public MBeanAttributeInfo CreateMBeanAttributeInfo(PropertyInfo info)
 {
     Descriptor descriptor = new Descriptor();
      OpenType openType = OpenType.CreateOpenType(info.PropertyType);
      descriptor.SetField(OpenTypeDescriptor.Field, openType);
      object[] tmp = info.GetCustomAttributes(typeof(OpenMBeanAttributeAttribute), false);
      if (tmp.Length > 0)
      {
     OpenMBeanAttributeAttribute attr = (OpenMBeanAttributeAttribute)tmp[0];
     if (attr.LegalValues != null && (attr.MinValue != null || attr.MaxValue != null))
     {
        throw new OpenDataException("Cannot specify both min/max values and legal values.");
     }
     IComparable defaultValue = (IComparable)attr.DefaultValue;
     OpenInfoUtils.ValidateDefaultValue(openType, defaultValue);
     descriptor.SetField(DefaultValueDescriptor.Field, defaultValue);
     if (attr.LegalValues != null)
     {
        OpenInfoUtils.ValidateLegalValues(openType, attr.LegalValues);
        descriptor.SetField(LegalValuesDescriptor.Field, attr.LegalValues);
     }
     else
     {
        OpenInfoUtils.ValidateMinMaxValue(openType, defaultValue, attr.MinValue, attr.MaxValue);
        descriptor.SetField(MinValueDescriptor.Field, attr.MinValue);
        descriptor.SetField(MaxValueDescriptor.Field, attr.MaxValue);
     }
      }
      return new MBeanAttributeInfo(info.Name, InfoUtils.GetDescrition(info, info, "MBean attribute"), openType.Representation.AssemblyQualifiedName,
     info.CanRead, info.CanWrite, descriptor);
 }
Esempio n. 2
0
 /// <summary>
 /// Creates new MBeanOperationInfo object.
 /// </summary>
 /// <param name="name">The name of the method.</param>
 /// <param name="description">A human readable description of the operation.</param>
 /// <param name="returnType">The type of the method's return value.</param>
 /// <param name="signature">MBeanParameterInfo objects describing the parameters(arguments) of the method. It should be an empty list if operation has no parameters.</param>
 /// <param name="impact">The impact of the method.</param>
 /// <param name="descriptor">Initial descriptor values.</param>
 public MBeanOperationInfo(string name, string description, string returnType, IEnumerable<MBeanParameterInfo> signature, OperationImpact impact, Descriptor descriptor)
     : base(name, description, descriptor)
 {
     _returnType = returnType;
        _signature = new List<MBeanParameterInfo>(signature).AsReadOnly();
     _impact = impact;
 }
Esempio n. 3
0
        public Device(Descriptor descriptor, int baudRate)
        {
            Descriptor = descriptor;

            port = new SerialPort(
                portName: descriptor.Port,
                baudRate: baudRate,
                parity: Parity.None,
                dataBits: 8,
                stopBits: StopBits.One);

            port.ErrorReceived += (s, e) =>
            {
                throw new ApplicationException(string.Format(
                    "Serial error: {0}", e.EventType));
            };

            port.DtrEnable = false;
            port.Open();
            Thread.Sleep(50);
            port.DtrEnable = true;

            reader = new BinaryReader(port.BaseStream);
            writer = new BinaryWriter(port.BaseStream);

            port.ReadTimeout = 5000;

            byte r;
            do r = reader.ReadByte();
            while (r != ready);

            port.ReadTimeout = 500;
        }
Esempio n. 4
0
 public void SetDescriptorDistance(Descriptor desc, double distance)
 {
     switch (desc)
     {
         case Descriptor.NONE:
             break;
         case Descriptor.CLD:
             CLDDiff = distance;
             break;
         case Descriptor.DCD:
             DCDDiff = distance;
             break;
         case Descriptor.EHD:
             EHDDiff = distance;
             break;
         case Descriptor.SCD:
             SCDDiff = distance;
             break;
         case Descriptor.CEDD:
             CEDDDiff = distance;
             break;
         case Descriptor.FCTH:
             FCTHDiff = distance;
             break;
         default:
             break;
     }
 }
Esempio n. 5
0
        public TypeToolObject(BinaryPSDReader reader)
            : base(reader)
        {
            BinaryPSDReader r = this.GetDataReader();

            ushort Version = r.ReadUInt16(); //1= Photoshop 5.0

            this.Transform = new Matrix2D(r);

            ushort TextDescriptorVersion = r.ReadUInt16(); //=50. For Photoshop 6.0.
            if (true)
                this.TxtDescriptor = new DynVal(r, true);
            else
            {
                uint XTextDescriptorVersion = r.ReadUInt32(); //=16. For Photoshop 6.0.
                this.TextDescriptor = new Descriptor(r);
            }
            this.Data = r.ReadBytes((int)r.BytesToEnd);

            ////ushort WarpDescriptorVersion = r.ReadUInt16(); //=50. For Photoshop 6.0.
            ////uint XWarpDescriptorVersion = r.ReadUInt32(); //=16. For Photoshop 6.0.
            ////Descriptor warpDescriptor = new Descriptor(r);
            //this.WarpDescriptor = new DynVal(r, true);

            //this.WarpRect = ERectangleF.FromLTRB((float)r.ReadPSDDouble(), (float)r.ReadPSDDouble(), (float)r.ReadPSDDouble(), (float)r.ReadPSDDouble());
            ////this.WarpRect.Left = r.ReadPSDDouble();
            ////double warpRectTop = r.ReadPSDDouble();
            ////double warpRectRight = r.ReadPSDDouble();
            ////double warpRectBottom = r.ReadPSDDouble();

            //this.Data = null;
        }
Esempio n. 6
0
        /// <summary>Defaults.</summary>
        /// <param name="d">The Descriptor to process.</param>
        /// <param name="x">The Vector to process.</param>
        /// <param name="y">The Vector to process.</param>
        /// <param name="activation">The activation.</param>
        /// <returns>A Network.</returns>
        public static Network Default(Descriptor d, Matrix x, Vector y, IFunction activation)
        {
            var nn = new Network();

            // set output to number of choices of available
            // 1 if only two choices
            var distinct = y.Distinct().Count();
            var output = distinct > 2 ? distinct : 1;

            // identity funciton for bias nodes
            IFunction ident = new Ident();

            // set number of hidden units to (Input + Hidden) * 2/3 as basic best guess.
            var hidden = (int)Math.Ceiling((decimal)(x.Cols + output) * 2m / 3m);

            // creating input nodes
            nn.In = new Node[x.Cols + 1];
            nn.In[0] = new Node { Label = "B0", Activation = ident };
            for (var i = 1; i < x.Cols + 1; i++)
            {
                nn.In[i] = new Node { Label = d.ColumnAt(i - 1), Activation = ident };
            }

            // creating hidden nodes
            var h = new Node[hidden + 1];
            h[0] = new Node { Label = "B1", Activation = ident };
            for (var i = 1; i < hidden + 1; i++)
            {
                h[i] = new Node { Label = string.Format("H{0}", i), Activation = activation };
            }

            // creating output nodes
            nn.Out = new Node[output];
            for (var i = 0; i < output; i++)
            {
                nn.Out[i] = new Node { Label = GetLabel(i, d), Activation = activation };
            }

            // link input to hidden. Note: there are
            // no inputs to the hidden bias node
            for (var i = 1; i < h.Length; i++)
            {
                for (var j = 0; j < nn.In.Length; j++)
                {
                    Edge.Create(nn.In[j], h[i]);
                }
            }

            // link from hidden to output (full)
            for (var i = 0; i < nn.Out.Length; i++)
            {
                for (var j = 0; j < h.Length; j++)
                {
                    Edge.Create(h[j], nn.Out[i]);
                }
            }

            return nn;
        }
Esempio n. 7
0
 /// <summary>Gets a label.</summary>
 /// <param name="n">The Node to process.</param>
 /// <param name="d">The Descriptor to process.</param>
 /// <returns>The label.</returns>
 private static string GetLabel(int n, Descriptor d)
 {
     if (d.Label.Type.IsEnum)
         return Enum.GetName(d.Label.Type, n);
     else if (d.Label is StringProperty && ((StringProperty)d.Label).AsEnum)
         return ((StringProperty)d.Label).Dictionary[n];
     else return d.Label.Name;
 }
 private void SetFieldValuesFromDescriptor(Descriptor descriptor)
 {
     Field = new List<FeatureDescriptorTypeField>();
      foreach (string fieldName in descriptor.GetFieldNames())
      {
     Field.Add(new FeatureDescriptorTypeField(fieldName, descriptor.GetFieldValue(fieldName)));
      }
 }
Esempio n. 9
0
 public void NotifyCompleted(Descriptor descriptor)
 {
     running.Remove(descriptor);
     if (running.Count == 0)
     {
         if (AllCompleted != null) AllCompleted(this, new EventArgs());
     }
 }
Esempio n. 10
0
 /// <summary>Constructor.</summary>
 /// <param name="descriptor">the descriptor.</param>
 public DecisionTreeGenerator(Descriptor descriptor)
 {
     Depth = 5;
     Width = 2;
     Descriptor = descriptor;
     ImpurityType = typeof(Entropy);
     Hint = double.Epsilon;
 }
Esempio n. 11
0
 public static bool IsParentNode(Descriptor descriptor)
 {
     bool result = false;
     if (descriptor.DescriptorType.DescriptorTypeName == "To")
     {
         result = true;
     }
     return result;
 }
Esempio n. 12
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);
        }
Esempio n. 13
0
 /// <summary>
 /// Constructs an <see cref="NetMX.MBeanInfo"/>.
 /// </summary>
 /// <param name="className">Name of the MBean described by this MBeanInfo.</param>
 /// <param name="description">Human readable description of the MBean. </param>
 /// <param name="attributes">List of MBean attributes. It should be an empty list if MBean contains no attributes.</param>
 /// <param name="constructors">List of MBean constructors. It should be an empty list if MBean contains no constructors.</param>
 /// <param name="operations">List of MBean operations. It should be an empty list if MBean contains no operations.</param>
 /// <param name="notifications">List of MBean notifications. It should be an empty list if MBean contains no notifications.</param>
 /// <param name="descriptor">Initial descriptor values.</param>
 public MBeanInfo(string className, string description, IEnumerable<MBeanAttributeInfo> attributes, IEnumerable<MBeanConstructorInfo> constructors, IEnumerable<MBeanOperationInfo> operations, IEnumerable<MBeanNotificationInfo> notifications, Descriptor descriptor)
 {
     _className = className;
     _description = description;
        _attributes = new List<MBeanAttributeInfo>(attributes).AsReadOnly();
      _constructors = new List<MBeanConstructorInfo>(constructors).AsReadOnly();
     _operations = new List<MBeanOperationInfo>(operations).AsReadOnly();
     _notifications = new List<MBeanNotificationInfo>(notifications).AsReadOnly();
        _descriptor = descriptor;
 }
Esempio n. 14
0
        public void ReadFrom_FromAStreamWithNonHexadecimalCharacters_ThrowsException()
        {
            var descriptorBytes = Encoding.ASCII.GetBytes("zz\0e82fe33199f25c242213ada825358e91c4261753\0b\03\0foo\0");
            var expected = new Descriptor("e82fe33199f25c242213ada825358e91c4261753", DescriptorType.File, "foo");

            using (var stream = new MemoryStream(descriptorBytes))
            {
                Assert.That(() => Descriptor.ReadFrom(stream), Throws.InstanceOf<InvalidOperationException>());
            }
        }
Esempio n. 15
0
        public Cluster Generate(Descriptor descriptor, IEnumerable<object> examples, int k, IDistance metric = null)
        {
            var data = examples.ToArray();
            Descriptor = descriptor;
            Matrix X = Descriptor.Convert(examples).ToMatrix();

            var assignments = Generate(X, k, metric);

            return GenerateClustering(X, assignments, data);
        }
Esempio n. 16
0
        /// <summary>
        /// Returns a Vector of positive and negative labels in 1 - 0 form.
        /// </summary>
        /// <param name="examples">Object examples.</param>
        /// <param name="descriptor">Descriptor.</param>
        /// <param name="truthLabel">The truth label's value (see <see cref="LabelAttribute"/>).</param>
        /// <returns></returns>
        public static Vector ChangeClassLabels(object[] examples, Descriptor descriptor, object truthLabel)
        {
            Vector y = new Vector(examples.Length);

            for (int i = 0; i < y.Length; i++)
            {
                y[i] = (descriptor.GetValue(examples.ElementAt(i), descriptor.Label).Equals(truthLabel) ? 1.0 : 0.0);
            }

            return y;
        }
Esempio n. 17
0
        public Device(ref Descriptor desc, FeatureLevel featureLevel = FeatureLevel.Level_12_0)
            : base(ref desc)
        {
            if (desc.DebugDevice)
            {
                var debugInterface = SharpDX.Direct3D12.DebugInterface.Get();
                if (debugInterface != null)
                {
                    debugInterface.EnableDebugLayer();
                }
                else
                {
                    Log.Error("Failed to obtain DX12 debug layer.");
                }
            }

            // Use first adapter that is supported.
            using (SharpDX.DXGI.Factory dxgiFactory = new Factory4())
            {
                for (int adapterIndex = 0;; ++adapterIndex)
                {
                    var adapter = dxgiFactory.GetAdapter(adapterIndex);
                    if (adapter == null)
                    {
                        // TODO: Throw exception
                        return;
                    }

                    try
                    {
                        DeviceD3D12 = new SharpDX.Direct3D12.Device(adapter, (SharpDX.Direct3D.FeatureLevel) featureLevel);
                        Adapter = adapter;
                        break;
                    }

                    catch (Exception)
                    {
                        DeviceD3D12 = null;
                        adapter.Dispose();
                    }
                }
            }

            // Get Resource handle increment sizes.
            descriptorHandleIncrementSize[(int)DescriptorHeap.Descriptor.ResourceDescriptorType.Sampler] = DeviceD3D12.GetDescriptorHandleIncrementSize(DescriptorHeapType.Sampler);
            descriptorHandleIncrementSize[(int)DescriptorHeap.Descriptor.ResourceDescriptorType.DepthStencil] = DeviceD3D12.GetDescriptorHandleIncrementSize(DescriptorHeapType.DepthStencilView);
            descriptorHandleIncrementSize[(int)DescriptorHeap.Descriptor.ResourceDescriptorType.RenderTarget] = DeviceD3D12.GetDescriptorHandleIncrementSize(DescriptorHeapType.RenderTargetView);
            descriptorHandleIncrementSize[(int)DescriptorHeap.Descriptor.ResourceDescriptorType.ShaderResource] = DeviceD3D12.GetDescriptorHandleIncrementSize(DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView);

            Memory.Enums.InitLookupTables();

            Log.Info("Successfully created a DX12 device with adapter \"{0}\"", Adapter.Description.Description);
        }
Esempio n. 18
0
 protected Descriptor GetDescriptorFromFieldValues()
 {
     Descriptor descriptor = new Descriptor();
      if (Field != null)
      {
     foreach (FeatureDescriptorTypeField field in Field)
     {
        descriptor.SetField(field.Name, field.Value.Deserialize());
     }
      }
      return descriptor;
 }
Esempio n. 19
0
        public void AddItem(string item, string name, IProgressBar progress)
        {
            if (Running) throw new Exception("Resource Downloader was already started.");

            string resourceUrl = UrlResourceName(category, item, name);

            Downloader downloader = new Downloader();
            downloader.Open("GET", new Uri(resourceUrl, UriKind.RelativeOrAbsolute));

            Descriptor descriptor = new Descriptor(this, downloader, progress);
            descriptors.Add(resourceUrl, descriptor);
        }
Esempio n. 20
0
        public void ReadFrom_FromAStreamWithAValidFolderDescriptor_ReturnsTheDescriptor()
        {
            var descriptorBytes = Encoding.ASCII.GetBytes("28\0e82fe33199f25c242213ada825358e91c4261753\0t\03\0foo\0");
            var expected = new Descriptor("e82fe33199f25c242213ada825358e91c4261753", DescriptorType.Folder, "foo");

            using (var stream = new MemoryStream(descriptorBytes))
            {
                var descriptor = Descriptor.ReadFrom(stream);

                Assert.That(descriptor, Is.EqualTo(expected));
            }
        }
Esempio n. 21
0
        /// <summary>Constructor.</summary>
        /// <exception cref="InvalidOperationException">Thrown when the requested operation is invalid.</exception>
        /// <param name="depth">(Optional) The depth.</param>
        /// <param name="width">(Optional) the width.</param>
        /// <param name="descriptor">(Optional) the descriptor.</param>
        /// <param name="impurityType">(Optional) type of the impurity.</param>
        /// <param name="hint">(Optional) the hint.</param>
        public DecisionTreeGenerator(
            int depth = 5,
            int width = 2,
            Descriptor descriptor = null,
            Type impurityType = null,
            double hint = double.Epsilon)
        {
            if (width < 2)
                throw new InvalidOperationException("Cannot set dt tree width to less than 2!");

            Descriptor = descriptor;
            Depth = depth;
            Width = width;
            ImpurityType = impurityType ?? typeof(Entropy);
            Hint = hint;
        }
Esempio n. 22
0
        public static Guid GetMapId(Node node, Descriptor descriptor)
        {
            Node altNode = ConditionHelper.GetAlternateNode(descriptor);
            bool isNodeParent = ConditionHelper.IsParentNode(descriptor);

            Guid mapId = Guid.Empty;
            if (!isNodeParent)
            {
                mapId = altNode.NodeUid;
            }
            else
            {
                mapId = node.NodeUid;
            }
            return mapId;
        }
Esempio n. 23
0
        private Descriptor Generate()
        {
            Descriptor d = new Descriptor();

            d.Features = new Property[]
            {
                new Property { Name = "Age" },
                new Property { Name = "Height" },
                new DateTimeProperty(DateTimeFeature.DayOfWeek | DateTimeFeature.Month) { Name = "BirthDate"  },
                new Property { Name = "Weight" },
                new Property { Name = "Good" },
                
            };

            return d;
        }
Esempio n. 24
0
		private IEnumerable<Descriptor> ReadDescriptors(IBitStream bitstream)
		{
			while (!bitstream.ChunkFinished) {
				var desc = bitstream.ReadProtobufVarInt();
				var wireType = desc & 7;
				var fieldnum = desc >> 3;
				if ((wireType != 2) || (fieldnum != 1))
					throw new InvalidDataException();

				var length = bitstream.ReadProtobufVarInt();
				bitstream.BeginChunk(length * 8);
				var descriptor = new Descriptor();
				descriptor.Parse(bitstream);
				yield return descriptor;
				bitstream.EndChunk();
			}
		}
        public bool Evaluate(Node node, Relationship relationship, Descriptor descriptor)
        {
            Guid searchId = Guid.Empty;
            bool? evaluation = new bool?();

            switch (Context)
            {
                case ConditionContext.Node:
                    searchId = node.NodeUid;
                    break;
                case ConditionContext.Relationship:
                    searchId = relationship.RelationshipUid;
                    break;
                case ConditionContext.Descriptor:
                    searchId = descriptor.DescriptorUid;
                    break;
                case ConditionContext.NodeType:
                    searchId = node.NodeTypeUid.Value;
                    break;
                case ConditionContext.RelationshipType:
                    searchId = relationship.RelationshipTypeUid.Value;
                    break;
                case ConditionContext.DescriptorType:
                    searchId = descriptor.DescriptorTypeUid.Value;
                    break;
                default:
                    break;
            }

            switch (Operator)
            {
                case ComparisonOperators.Equal:
                    evaluation = SearchValue == searchId;
                    break;
                case ComparisonOperators.NotEqual:
                    evaluation = SearchValue != searchId;
                    break;
                default:
                    evaluation = false;
                    break;
            }

            return evaluation.Value;
        }
Esempio n. 26
0
 /// <summary>
 /// Constructs an MBeanAttributeInfo object.
 /// </summary>
 /// <param name="name">The name of the attribute.</param>
 /// <param name="description">The type or class name of the attribute.</param>
 /// <param name="type">A human readable description of the attribute.</param>
 /// <param name="isReadable">True if the attribute has a getter method, false otherwise.</param>
 /// <param name="isWritable">True if the attribute has a setter method, false otherwise.</param>
 /// <param name="descriptor">Initial descriptor values.</param>
 public MBeanAttributeInfo(string name, string description, string type, bool isReadable, bool isWritable, Descriptor descriptor)
     : base(name, description, descriptor)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (description == null)
     {
         throw new ArgumentNullException("description");
     }
     if (type == null)
     {
         throw new ArgumentNullException("type");
     }
     _type = type;
     _isReadable = isReadable;
     _isWritable = isWritable;
 }
Esempio n. 27
0
 public static Descriptor GetAlternateDescriptor(Descriptor descriptor)
 {
     Descriptor result = null;
     if (descriptor.Relationship != null && descriptor.Relationship.Descriptors != null)
     {
         foreach (Descriptor desc in descriptor.Relationship.Descriptors)
         {
             if (desc.DescriptorUid == descriptor.DescriptorUid)
             {
                 continue;
             }
             else
             {
                 result = desc;
             }
         }
     }
     return result;
 }
Esempio n. 28
0
        public void Descriptor_Dictionary_Serialization_Test()
        {
            Descriptor d = new Descriptor();

            var dictionary = StringHelpers.BuildWordDictionary(WordStrings)
                                          .Select(k => k.Key)
                                          .ToArray();

            d.Features = new Property[]
            {
                new Property { Name = "Age", Type = typeof(int) },
                new Property { Name = "Height", Type = typeof(decimal) },
                new StringProperty { Name = "Words", Dictionary = dictionary },
                new Property { Name = "Weight", Type = typeof(double) },
                new Property { Name = "Good", Type = typeof(bool) },

            };

            Serialize(d);
        }
Esempio n. 29
0
        /// <summary>Defaults.</summary>
        /// <param name="d">The Descriptor to process.</param>
        /// <param name="x">The Vector to process.</param>
        /// <param name="y">The Vector to process.</param>
        /// <param name="activationFunction">The activation.</param>
        /// <param name="outputFunction">The ouput function for hidden nodes (Optional).</param>
        /// <param name="epsilon">epsilon</param>
        /// <returns>A Network.</returns>
        public static Network Create(this Network network, Descriptor d, Matrix x, Vector y, IFunction activationFunction, IFunction outputFunction = null, double epsilon = double.NaN)
        {
            // set output to number of choices of available
            // 1 if only two choices
            int distinct = y.Distinct().Count();
            int output = distinct > 2 ? distinct : 1;
            // identity funciton for bias nodes
            IFunction ident = new Ident();

            // set number of hidden units to (Input + Hidden) * 2/3 as basic best guess.
            int hidden = (int)System.Math.Ceiling((double)(x.Cols + output) * 2.0 / 3.0);

            return network.Create(x.Cols, output, activationFunction, outputFunction,
                fnNodeInitializer: new Func<int, int, Neuron>((l, i) =>
                {
                    if (l == 0) return new Neuron(false) { Label = d.ColumnAt(i - 1), ActivationFunction = activationFunction, NodeId = i, LayerId = l };
                    else if (l == 2) return new Neuron(false) { Label = Network.GetLabel(i, d), ActivationFunction = activationFunction, NodeId = i, LayerId = l };
                    else return new Neuron(false) { ActivationFunction = activationFunction, NodeId = i, LayerId = l };
                }), hiddenLayers: hidden);
        }
 public MBeanOperationInfo CreateMBeanOperationInfo(MethodInfo info)
 {
     Descriptor descriptor = new Descriptor();
      object[] attrTmp = info.GetCustomAttributes(typeof(OpenMBeanOperationAttribute), false);
      if (attrTmp.Length == 0)
      {
     throw new OpenDataException("Open MBean operation have to have its impact specified.");
      }
      OpenMBeanOperationAttribute attr = (OpenMBeanOperationAttribute)attrTmp[0];
      if (attr.Impact == OperationImpact.Unknown)
      {
     throw new OpenDataException("Open MBean operation have to have its impact specified.");
      }
      OpenType openType = info.ReturnType != null ? OpenType.CreateOpenType(info.ReturnType) : SimpleType.Void;
      descriptor.SetField(OpenTypeDescriptor.Field, openType);
      return new MBeanOperationInfo(info.Name, InfoUtils.GetDescrition(info, info, "MBean operation"),
                                openType.Representation.AssemblyQualifiedName,
                                info.GetParameters().Select(x => CreateMBeanParameterInfo(x)), attr.Impact,
                                descriptor);
 }
Esempio n. 31
0
        /// <summary>Builds a tree.</summary>
        /// <param name="x">The Matrix to process.</param>
        /// <param name="y">The Vector to process.</param>
        /// <param name="depth">The depth.</param>
        /// <param name="used">The used.</param>
        /// <returns>A Node.</returns>
        private Node BuildTree(Matrix x, Vector y, int depth, List <int> used, Tree tree)
        {
            if (depth < 0)
            {
                return(BuildLeafNode(y.Mode()));
            }

            var tuple   = GetBestSplit(x, y, used);
            var col     = tuple.Item1;
            var gain    = tuple.Item2;
            var measure = tuple.Item3;

            // uh oh, need to return something?
            // a weird node of some sort...
            // but just in case...
            if (col == -1)
            {
                return(BuildLeafNode(y.Mode()));
            }

            used.Add(col);

            Node node = new Node
            {
                Column = col,
                Gain   = gain,
                IsLeaf = false,
                Name   = Descriptor.ColumnAt(col)
            };

            // populate edges
            List <Edge> edges = new List <Edge>(measure.Segments.Length);

            for (int i = 0; i < measure.Segments.Length; i++)
            {
                // working set
                var segment = measure.Segments[i];
                var edge    = new Edge()
                {
                    ParentId = node.Id,
                    Discrete = measure.Discrete,
                    Min      = segment.Min,
                    Max      = segment.Max
                };

                IEnumerable <int> slice;

                if (edge.Discrete)
                {
                    // get discrete label
                    edge.Label = Descriptor.At(col).Convert(segment.Min).ToString();
                    // do value check for matrix slicing
                    slice = x.Indices(v => v[col] == segment.Min);
                }
                else
                {
                    // get range label
                    edge.Label = string.Format("{0} <= x < {1}", segment.Min, segment.Max);
                    // do range check for matrix slicing
                    slice = x.Indices(v => v[col] >= segment.Min && v[col] < segment.Max);
                }

                // something to look at?
                // if this number is 0 then this edge
                // leads to a dead end - the edge will
                // not be built
                if (slice.Any())
                {
                    Vector ySlice = y.Slice(slice);
                    // only one answer, set leaf
                    if (ySlice.Distinct().Count() == 1)
                    {
                        var child = BuildLeafNode(ySlice[0]);
                        tree.AddVertex(child);
                        edge.ChildId = child.Id;
                    }
                    // otherwise continue to build tree
                    else
                    {
                        var child = BuildTree(x.Slice(slice), ySlice, depth - 1, used, tree);
                        tree.AddVertex(child);
                        edge.ChildId = child.Id;
                    }

                    edges.Add(edge);
                }
            }

            // problem, need to convert
            // parent to terminal node
            // with mode
            if (edges.Count <= 1)
            {
                var val = y.Mode();
                node.IsLeaf = true;
                node.Value  = val;
            }

            tree.AddVertex(node);

            if (edges.Count > 1)
            {
                foreach (var e in edges)
                {
                    tree.AddEdge(e);
                }
            }

            return(node);
        }
Esempio n. 32
0
 public IDocumentDescriptor GetDocument(string filename)
 {
     return(Descriptor.Document(this.intellisenseSession.GetDocumentAsByteArray(filename)));
 }
 private static BuildingRequestEventArgs SetupTest(string method, Uri uri, HeaderCollection headers, Descriptor descriptor)
 {
     return(new BuildingRequestEventArgs(method, uri, headers, descriptor, HttpStack.Auto));
 }
Esempio n. 34
0
 public SimpleFSIndexInput(System.IO.FileInfo path, int bufferSize, int chunkSize)
     : base(bufferSize)
 {
     file           = new Descriptor(path, System.IO.FileAccess.Read);
     this.chunkSize = chunkSize;
 }
Esempio n. 35
0
 protected DescribedMap(Descriptor descriptor)
     : base(descriptor)
 {
 }
Esempio n. 36
0
        public override string GetMessage(IFormatProvider formatProvider)
        {
            var format = Descriptor.GetMessageFormat();

            return(string.Format(formatProvider, format, Args));
        }
Esempio n. 37
0
 protected Fence(ref Descriptor desc, Device device, string label) : base(ref desc, device, label)
 {
     Create();
 }
Esempio n. 38
0
        public HidDeviceWrap Initialize()
        {
            Error  = null;
            Opened = false;
            _ready = false;

            DevicePath = Device.DevicePath;
            Change();

            Task.Run(() =>
            {
                Opening = true;
                try
                {
                    //Stream = Device.Open();

                    Descriptor = Device.GetReportDescriptor();

                    MaxInputReportLength = Device.GetMaxInputReportLength();
                    InputReportCount     = 0;
                    InputReportOffsets.Clear();
                    foreach (var report in Descriptor.InputReports)
                    {
                        InputReportOffsets.Add(report.ReportID, InputReportCount * MaxInputReportLength);
                        InputReportCount++;
                    }
                    InputLength  = MaxInputReportLength * InputReportCount;
                    OutputLength = Device.GetMaxOutputReportLength();

                    _inputBytes    = new byte[InputLength];
                    _rawInputBytes = new byte[MaxInputReportLength];
                    _outputBytes   = new byte[OutputLength];

                    Receiver = Descriptor.CreateHidDeviceInputReceiver();

                    var options = new OpenConfiguration();
                    options.SetOption(OpenOption.Exclusive, false);
                    options.SetOption(OpenOption.Transient, false);
                    options.SetOption(OpenOption.Interruptible, false);
                    options.SetOption(OpenOption.Priority, OpenPriority.High);

                    Stream = Device.Open(options);

                    Receiver.Start(Stream);
                    Receiver.Received += (sender, args) =>
                    {
                        Opened = true;
                        _ready = true;
                        Change();
                    };

                    Opened = true;
                }
                catch (Exception e)
                {
                    Opened = false;
                    Error  = e;
                }
                Opening = false;
                Change();
                _ready = Opened;
            });
            return(this);
        }
Esempio n. 39
0
 public string ToString(CultureInfo culture)
 {
     return(Descriptor.Translate(ToString(), CultureInfo.InvariantCulture, culture));
 }
 public void descirptor_is_read()
 {
     Descriptor.ShouldNotBeNull();
 }
Esempio n. 41
0
        /// <summary>Defaults.</summary>
        /// <param name="d">The Descriptor to process.</param>
        /// <param name="x">The Vector to process.</param>
        /// <param name="y">The Vector to process.</param>
        /// <param name="activation">The activation.</param>
        /// <returns>A Network.</returns>
        public static Network Default(Descriptor d, Matrix x, Vector y, IFunction activation)
        {
            Network nn = new Network();
            // set output to number of choices of available
            // 1 if only two choices
            int distinct = y.Distinct().Count();
            int output   = distinct > 2 ? distinct : 1;
            // identity funciton for bias nodes
            IFunction ident = new Ident();

            // set number of hidden units to (Input + Hidden) * 2/3 as basic best guess.
            int hidden = (int)System.Math.Ceiling((decimal)(x.Cols + output) * 2m / 3m);

            // creating input nodes
            nn.In    = new Node[x.Cols + 1];
            nn.In[0] = new Node {
                Label = "B0", Activation = ident
            };
            for (int i = 1; i < x.Cols + 1; i++)
            {
                nn.In[i] = new Node {
                    Label = d.ColumnAt(i - 1), Activation = ident
                }
            }
            ;

            // creating hidden nodes
            Node[] h = new Node[hidden + 1];
            h[0] = new Node {
                Label = "B1", Activation = ident
            };
            for (int i = 1; i < hidden + 1; i++)
            {
                h[i] = new Node {
                    Label = String.Format("H{0}", i), Activation = activation
                }
            }
            ;

            // creating output nodes
            nn.Out = new Node[output];
            for (int i = 0; i < output; i++)
            {
                nn.Out[i] = new Node {
                    Label = GetLabel(i, d), Activation = activation
                }
            }
            ;

            // link input to hidden. Note: there are
            // no inputs to the hidden bias node
            for (int i = 1; i < h.Length; i++)
            {
                for (int j = 0; j < nn.In.Length; j++)
                {
                    Edge.Create(nn.In[j], h[i]);
                }
            }

            // link from hidden to output (full)
            for (int i = 0; i < nn.Out.Length; i++)
            {
                for (int j = 0; j < h.Length; j++)
                {
                    Edge.Create(h[j], nn.Out[i]);
                }
            }

            return(nn);
        }
Esempio n. 42
0
        /// <summary>
        ///     Gets the descriptor for this data source.
        /// </summary>
        /// <param name="alias">
        ///     The alias.
        /// </param>
        /// <param name="context">
        ///     The execution context.
        /// </param>
        /// <param name="reader">
        ///     The reader.
        /// </param>
        /// <returns>
        ///     The <see cref="System.Threading.Tasks.Task" />.
        /// </returns>
        public Task <IDataSourceDescriptor> GetDataSourceDescriptorAsync(string alias, [NotNull] IFileFormatExecutionContext context, StreamReader reader)
        {
            var separator = context.GetDefault("SEPARATOR", false) as string ?? ",";

            return(Task.FromResult(Descriptor.ForDataSource(alias, CsvFileFormat.GetHeaders(CsvFileFormat.GetSplitter(separator), reader, separator).Where(header => header.Length > 0).Select(column => Descriptor.ForColumn(column, typeof(string))))));
        }
 protected override List <string> getCurrentScriptNames()
 {
     return(Descriptor.getScriptNamesClone());
 }
Esempio n. 44
0
        public void ProcessVerticesWithWeights(Mesh mesh, VertexData vertData, Dictionary <string, int> boneNames, EVP1 envelopes, DRW1 partialWeight, bool doStrip = true)
        {
            Weight[] weights = new Weight[mesh.Vertices.Count];

            for (int i = 0; i < mesh.Vertices.Count; i++)
            {
                int    vertexid   = i;
                Weight vertWeight = new Weight();

                foreach (Assimp.Bone bone in mesh.Bones)
                {
                    foreach (VertexWeight weight in bone.VertexWeights)
                    {
                        if (weight.VertexID == vertexid)
                        {
                            vertWeight.AddWeight(weight.Weight, boneNames[bone.Name]);
                        }
                    }
                }
                vertWeight.reorderBones();
                weights[vertexid] = vertWeight;
            }

            //Primitive prim = new Primitive(Enums.GXPrimitiveType.Triangles);
            List <Enums.GXVertexAttribute> activeAttribs = Descriptor.GetActiveAttributes();

            AttributeData.SetAttributesFromList(activeAttribs);


            uint[] triindices = MakeTriIndexList(mesh);

            List <PrimitiveBrawl> primlist;

            if (doStrip)
            {
                //Console.WriteLine("Calculating triangle strips for Weighted");
                TriStripper stripper = new TriStripper(triindices, weights);
                primlist = stripper.Strip();
            }
            else
            {
                //Console.WriteLine("Calculating triangle list for Weighted");
                primlist = new List <PrimitiveBrawl>();
                PrimitiveBrawl prim = new PrimitiveBrawl(PrimType.TriangleList); // Trilist
                foreach (uint index in triindices)
                {
                    prim.Indices.Add(index);
                }
                primlist.Add(prim);
            }

            //Console.WriteLine(String.Format("Done, {0} primitives", primlist.Count));



            Packet        pack          = new Packet();
            List <Weight> packetWeights = new List <Weight>();
            int           numMatrices   = 0;

            foreach (PrimitiveBrawl primbrawl in primlist)
            {
                int numNewMatricesForFirstThreeVerts = 0;
                if (!packetWeights.Contains(weights[primbrawl.Indices[0]]))
                {
                    numNewMatricesForFirstThreeVerts++;
                }
                if (!packetWeights.Contains(weights[primbrawl.Indices[1]]))
                {
                    numNewMatricesForFirstThreeVerts++;
                }
                if (!packetWeights.Contains(weights[primbrawl.Indices[2]]))
                {
                    numNewMatricesForFirstThreeVerts++;
                }
                if (numMatrices + numNewMatricesForFirstThreeVerts > MaxMatricesPerPacket)
                {
                    // We won't be able to fit even the first 3 vertices of this primitive without going over the matrix limit.
                    // So we need to start a new packet.
                    packetWeights.Clear();
                    numMatrices = 0;
                    Packets.Add(pack);
                    pack = new Packet();
                }


                Primitive prim = new Primitive((Enums.GXPrimitiveType)primbrawl.Type);

                int currvert = -1;
                int maxvert  = primbrawl.Indices.Count - 1;
                Enums.GXPrimitiveType primtype = (Enums.GXPrimitiveType)primbrawl.Type;

                if (primtype == Enums.GXPrimitiveType.TriangleStrip)
                {
                    //Console.WriteLine("Doing Tristrip");
                    foreach (int vertIndex in primbrawl.Indices)
                    {
                        currvert++;
                        Weight vertWeight = weights[vertIndex];

                        int oldmat = numMatrices;
                        if (!packetWeights.Contains(vertWeight))
                        {
                            packetWeights.Add(vertWeight);
                            numMatrices++;
                        }

                        //Console.WriteLine(String.Format("Added {0} matrices, is now {1}", numMatrices - oldmat, numMatrices));

                        // There are too many matrices, we need to create a new packet
                        if (numMatrices > MaxMatricesPerPacket)
                        {
                            // If we break up and the resulting TriStrip becomes invalid,
                            // then we need to handle those cases.

                            //Console.WriteLine(String.Format("Breaking up because over the limit: {0}", numMatrices));

                            if (prim.PrimitiveType == Enums.GXPrimitiveType.TriangleStrip)
                            {
                                Debug.Assert(prim.Vertices.Count >= 3);
                            }
                            else if (prim.PrimitiveType == Enums.GXPrimitiveType.Triangles)
                            {
                                Debug.Assert(prim.Vertices.Count % 3 == 0);
                            }
                            pack.Primitives.Add(prim);


                            Primitive newprim = new Primitive(Enums.GXPrimitiveType.TriangleStrip);
                            Vertex    prev3   = new Vertex(prim.Vertices[prim.Vertices.Count - 3]);
                            Vertex    prev2   = new Vertex(prim.Vertices[prim.Vertices.Count - 2]);
                            Vertex    prev    = new Vertex(prim.Vertices[prim.Vertices.Count - 1]);
                            bool      isOdd   = currvert % 2 != 0;
                            if (isOdd)
                            {
                                // Need to preserve whether each vertex is even or odd inside the triangle strip.
                                // Do this by adding an extra vertex from the previous packet to the start of this one.
                                newprim.Vertices.Add(prev3);
                            }
                            newprim.Vertices.Add(prev2);
                            newprim.Vertices.Add(prev);

                            prim = newprim;

                            packetWeights.Clear();
                            numMatrices = 0;
                            Packets.Add(pack);
                            Packet oldPack = pack;
                            pack = new Packet();

                            // Calculate matrices for current packet in case we added vertices
                            foreach (Vertex vertex in prim.Vertices)
                            {
                                if (!packetWeights.Contains(vertex.VertexWeight))
                                {
                                    packetWeights.Add(vertex.VertexWeight);
                                    numMatrices++;
                                }

                                // Re-add the matrix index for the duplicated verts to the new packet.
                                // And recalculate the matrix index index in each vert's attribute data.
                                uint oldMatrixIndexIndex = vertex.GetAttributeIndex(Enums.GXVertexAttribute.PositionMatrixIdx);
                                int  matrixIndex         = oldPack.MatrixIndices[(int)oldMatrixIndexIndex];

                                if (!pack.MatrixIndices.Contains(matrixIndex))
                                {
                                    pack.MatrixIndices.Add(matrixIndex);
                                }
                                vertex.SetAttributeIndex(Enums.GXVertexAttribute.PositionMatrixIdx, (uint)pack.MatrixIndices.IndexOf(matrixIndex));
                            }

                            if (!packetWeights.Contains(vertWeight))
                            {
                                packetWeights.Add(vertWeight);
                                numMatrices++;
                            }
                        }

                        Vertex vert      = new Vertex();
                        Weight curWeight = vertWeight;

                        vert.SetWeight(curWeight);

                        foreach (Enums.GXVertexAttribute attrib in activeAttribs)
                        {
                            switch (attrib)
                            {
                            case Enums.GXVertexAttribute.PositionMatrixIdx:
                                int newMatrixIndex = -1;

                                if (curWeight.WeightCount == 1)
                                {
                                    newMatrixIndex = partialWeight.MeshWeights.IndexOf(curWeight);
                                }
                                else
                                {
                                    if (!envelopes.Weights.Contains(curWeight))
                                    {
                                        envelopes.Weights.Add(curWeight);
                                    }

                                    int envIndex = envelopes.Weights.IndexOf(curWeight);
                                    int drwIndex = partialWeight.MeshWeights.IndexOf(curWeight);

                                    if (drwIndex == -1)
                                    {
                                        throw new System.Exception($"Model has unweighted vertices in mesh \"{mesh.Name}\". Please weight all vertices to at least one bone.");
                                    }

                                    newMatrixIndex = drwIndex;
                                    partialWeight.Indices[drwIndex] = envIndex;
                                }

                                if (!pack.MatrixIndices.Contains(newMatrixIndex))
                                {
                                    pack.MatrixIndices.Add(newMatrixIndex);
                                }

                                vert.SetAttributeIndex(Enums.GXVertexAttribute.PositionMatrixIdx, (uint)pack.MatrixIndices.IndexOf(newMatrixIndex));
                                break;

                            case Enums.GXVertexAttribute.Position:
                                List <Vector3> posData = (List <Vector3>)vertData.GetAttributeData(Enums.GXVertexAttribute.Position);
                                Vector3        vertPos = mesh.Vertices[vertIndex].ToOpenTKVector3();

                                if (curWeight.WeightCount == 1)
                                {
                                    Matrix4 ibm = envelopes.InverseBindMatrices[curWeight.BoneIndices[0]];

                                    Vector3 transVec = Vector3.TransformPosition(vertPos, ibm);
                                    if (!posData.Contains(transVec))
                                    {
                                        posData.Add(transVec);
                                    }
                                    AttributeData.Positions.Add(transVec);
                                    vert.SetAttributeIndex(Enums.GXVertexAttribute.Position, (uint)posData.IndexOf(transVec));
                                }
                                else
                                {
                                    if (!posData.Contains(vertPos))
                                    {
                                        posData.Add(vertPos);
                                    }
                                    AttributeData.Positions.Add(vertPos);

                                    vert.SetAttributeIndex(Enums.GXVertexAttribute.Position, (uint)posData.IndexOf(vertPos));
                                }
                                break;

                            case Enums.GXVertexAttribute.Normal:
                                List <Vector3> normData = (List <Vector3>)vertData.GetAttributeData(Enums.GXVertexAttribute.Normal);
                                Vector3        vertNrm  = mesh.Normals[vertIndex].ToOpenTKVector3();

                                if (curWeight.WeightCount == 1)
                                {
                                    Matrix4 ibm = envelopes.InverseBindMatrices[curWeight.BoneIndices[0]];
                                    vertNrm = Vector3.TransformNormal(vertNrm, ibm);
                                    if (!normData.Contains(vertNrm))
                                    {
                                        normData.Add(vertNrm);
                                    }
                                }
                                else
                                {
                                    if (!normData.Contains(vertNrm))
                                    {
                                        normData.Add(vertNrm);
                                    }
                                }

                                AttributeData.Normals.Add(vertNrm);
                                vert.SetAttributeIndex(Enums.GXVertexAttribute.Normal, (uint)normData.IndexOf(vertNrm));
                                break;

                            case Enums.GXVertexAttribute.Color0:
                            case Enums.GXVertexAttribute.Color1:
                                int          colNo   = (int)attrib - 11;
                                List <Color> colData = (List <Color>)vertData.GetAttributeData(Enums.GXVertexAttribute.Color0 + colNo);
                                Color        vertCol = mesh.VertexColorChannels[colNo][vertIndex].ToSuperBMDColorRGBA();

                                if (colNo == 0)
                                {
                                    AttributeData.Color_0.Add(vertCol);
                                }
                                else
                                {
                                    AttributeData.Color_1.Add(vertCol);
                                }

                                vert.SetAttributeIndex(Enums.GXVertexAttribute.Color0 + colNo, (uint)colData.IndexOf(vertCol));
                                break;

                            case Enums.GXVertexAttribute.Tex0:
                            case Enums.GXVertexAttribute.Tex1:
                            case Enums.GXVertexAttribute.Tex2:
                            case Enums.GXVertexAttribute.Tex3:
                            case Enums.GXVertexAttribute.Tex4:
                            case Enums.GXVertexAttribute.Tex5:
                            case Enums.GXVertexAttribute.Tex6:
                            case Enums.GXVertexAttribute.Tex7:
                                int            texNo        = (int)attrib - 13;
                                List <Vector2> texCoordData = (List <Vector2>)vertData.GetAttributeData(Enums.GXVertexAttribute.Tex0 + texNo);
                                Vector2        vertTexCoord = mesh.TextureCoordinateChannels[texNo][vertIndex].ToOpenTKVector2();
                                vertTexCoord = new Vector2(vertTexCoord.X, 1.0f - vertTexCoord.Y);

                                switch (texNo)
                                {
                                case 0:
                                    AttributeData.TexCoord_0.Add(vertTexCoord);
                                    break;

                                case 1:
                                    AttributeData.TexCoord_1.Add(vertTexCoord);
                                    break;

                                case 2:
                                    AttributeData.TexCoord_2.Add(vertTexCoord);
                                    break;

                                case 3:
                                    AttributeData.TexCoord_3.Add(vertTexCoord);
                                    break;

                                case 4:
                                    AttributeData.TexCoord_4.Add(vertTexCoord);
                                    break;

                                case 5:
                                    AttributeData.TexCoord_5.Add(vertTexCoord);
                                    break;

                                case 6:
                                    AttributeData.TexCoord_6.Add(vertTexCoord);
                                    break;

                                case 7:
                                    AttributeData.TexCoord_7.Add(vertTexCoord);
                                    break;
                                }

                                vert.SetAttributeIndex(Enums.GXVertexAttribute.Tex0 + texNo, (uint)texCoordData.IndexOf(vertTexCoord));
                                break;
                            }
                        }
                        prim.Vertices.Add(vert);
                    }
                }
                else if (primtype == Enums.GXPrimitiveType.Triangles)
                {
                    for (int j = 0; j < primbrawl.Indices.Count / 3; j++)
                    {
                        int    vert1Index  = (int)primbrawl.Indices[j * 3 + 0];
                        int    vert2Index  = (int)primbrawl.Indices[j * 3 + 1];
                        int    vert3Index  = (int)primbrawl.Indices[j * 3 + 2];
                        Weight vert1Weight = weights[vert1Index];
                        Weight vert2Weight = weights[vert2Index];
                        Weight vert3Weight = weights[vert3Index];
                        int    oldcount    = numMatrices;
                        if (!packetWeights.Contains(vert1Weight))
                        {
                            packetWeights.Add(vert1Weight);
                            numMatrices++;
                        }
                        if (!packetWeights.Contains(vert2Weight))
                        {
                            packetWeights.Add(vert2Weight);
                            numMatrices++;
                        }
                        if (!packetWeights.Contains(vert3Weight))
                        {
                            packetWeights.Add(vert3Weight);
                            numMatrices++;
                        }

                        // There are too many matrices, we need to create a new packet
                        if (numMatrices > MaxMatricesPerPacket)
                        {
                            //Console.WriteLine(String.Format("Making new packet because previous one would have {0}", numMatrices));
                            //Console.WriteLine(oldcount);
                            pack.Primitives.Add(prim);
                            Packets.Add(pack);

                            prim = new Primitive(Enums.GXPrimitiveType.Triangles);
                            pack = new Packet();

                            packetWeights.Clear();
                            numMatrices = 0;

                            if (!packetWeights.Contains(vert1Weight))
                            {
                                packetWeights.Add(vert1Weight);
                                numMatrices++;
                            }
                            if (!packetWeights.Contains(vert2Weight))
                            {
                                packetWeights.Add(vert2Weight);
                                numMatrices++;
                            }
                            if (!packetWeights.Contains(vert3Weight))
                            {
                                packetWeights.Add(vert3Weight);
                                numMatrices++;
                            }
                        }

                        int[]    vertexIndexArray = new int[] { vert1Index, vert2Index, vert3Index };
                        Weight[] vertWeightArray  = new Weight[] { vert1Weight, vert2Weight, vert3Weight };

                        for (int i = 0; i < 3; i++)
                        {
                            Vertex vert      = new Vertex();
                            int    vertIndex = vertexIndexArray[i];
                            Weight curWeight = vertWeightArray[i];

                            vert.SetWeight(curWeight);

                            foreach (Enums.GXVertexAttribute attrib in activeAttribs)
                            {
                                switch (attrib)
                                {
                                case Enums.GXVertexAttribute.PositionMatrixIdx:
                                    int newMatrixIndex = -1;

                                    if (curWeight.WeightCount == 1)
                                    {
                                        newMatrixIndex = partialWeight.MeshWeights.IndexOf(curWeight);
                                    }
                                    else
                                    {
                                        if (!envelopes.Weights.Contains(curWeight))
                                        {
                                            envelopes.Weights.Add(curWeight);
                                        }

                                        int envIndex = envelopes.Weights.IndexOf(curWeight);
                                        int drwIndex = partialWeight.MeshWeights.IndexOf(curWeight);

                                        if (drwIndex == -1)
                                        {
                                            throw new System.Exception($"Model has unweighted vertices in mesh \"{mesh.Name}\". Please weight all vertices to at least one bone.");
                                        }

                                        newMatrixIndex = drwIndex;
                                        partialWeight.Indices[drwIndex] = envIndex;
                                    }

                                    if (!pack.MatrixIndices.Contains(newMatrixIndex))
                                    {
                                        pack.MatrixIndices.Add(newMatrixIndex);
                                    }

                                    vert.SetAttributeIndex(Enums.GXVertexAttribute.PositionMatrixIdx, (uint)pack.MatrixIndices.IndexOf(newMatrixIndex));
                                    break;

                                case Enums.GXVertexAttribute.Position:
                                    List <Vector3> posData = (List <Vector3>)vertData.GetAttributeData(Enums.GXVertexAttribute.Position);
                                    Vector3        vertPos = mesh.Vertices[vertIndex].ToOpenTKVector3();

                                    if (curWeight.WeightCount == 1)
                                    {
                                        Matrix4 ibm = envelopes.InverseBindMatrices[curWeight.BoneIndices[0]];

                                        Vector3 transVec = Vector3.TransformPosition(vertPos, ibm);
                                        if (!posData.Contains(transVec))
                                        {
                                            posData.Add(transVec);
                                        }
                                        AttributeData.Positions.Add(transVec);
                                        vert.SetAttributeIndex(Enums.GXVertexAttribute.Position, (uint)posData.IndexOf(transVec));
                                    }
                                    else
                                    {
                                        if (!posData.Contains(vertPos))
                                        {
                                            posData.Add(vertPos);
                                        }
                                        AttributeData.Positions.Add(vertPos);

                                        vert.SetAttributeIndex(Enums.GXVertexAttribute.Position, (uint)posData.IndexOf(vertPos));
                                    }
                                    break;

                                case Enums.GXVertexAttribute.Normal:
                                    List <Vector3> normData = (List <Vector3>)vertData.GetAttributeData(Enums.GXVertexAttribute.Normal);
                                    Vector3        vertNrm  = mesh.Normals[vertIndex].ToOpenTKVector3();

                                    if (curWeight.WeightCount == 1)
                                    {
                                        Matrix4 ibm = envelopes.InverseBindMatrices[curWeight.BoneIndices[0]];
                                        vertNrm = Vector3.TransformNormal(vertNrm, ibm);
                                        if (!normData.Contains(vertNrm))
                                        {
                                            normData.Add(vertNrm);
                                        }
                                    }
                                    else
                                    {
                                        if (!normData.Contains(vertNrm))
                                        {
                                            normData.Add(vertNrm);
                                        }
                                    }

                                    AttributeData.Normals.Add(vertNrm);
                                    vert.SetAttributeIndex(Enums.GXVertexAttribute.Normal, (uint)normData.IndexOf(vertNrm));
                                    break;

                                case Enums.GXVertexAttribute.Color0:
                                case Enums.GXVertexAttribute.Color1:
                                    int          colNo   = (int)attrib - 11;
                                    List <Color> colData = (List <Color>)vertData.GetAttributeData(Enums.GXVertexAttribute.Color0 + colNo);
                                    Color        vertCol = mesh.VertexColorChannels[colNo][vertIndex].ToSuperBMDColorRGBA();

                                    if (colNo == 0)
                                    {
                                        AttributeData.Color_0.Add(vertCol);
                                    }
                                    else
                                    {
                                        AttributeData.Color_1.Add(vertCol);
                                    }

                                    vert.SetAttributeIndex(Enums.GXVertexAttribute.Color0 + colNo, (uint)colData.IndexOf(vertCol));
                                    break;

                                case Enums.GXVertexAttribute.Tex0:
                                case Enums.GXVertexAttribute.Tex1:
                                case Enums.GXVertexAttribute.Tex2:
                                case Enums.GXVertexAttribute.Tex3:
                                case Enums.GXVertexAttribute.Tex4:
                                case Enums.GXVertexAttribute.Tex5:
                                case Enums.GXVertexAttribute.Tex6:
                                case Enums.GXVertexAttribute.Tex7:
                                    int            texNo        = (int)attrib - 13;
                                    List <Vector2> texCoordData = (List <Vector2>)vertData.GetAttributeData(Enums.GXVertexAttribute.Tex0 + texNo);
                                    Vector2        vertTexCoord = mesh.TextureCoordinateChannels[texNo][vertIndex].ToOpenTKVector2();
                                    vertTexCoord = new Vector2(vertTexCoord.X, 1.0f - vertTexCoord.Y);

                                    switch (texNo)
                                    {
                                    case 0:
                                        AttributeData.TexCoord_0.Add(vertTexCoord);
                                        break;

                                    case 1:
                                        AttributeData.TexCoord_1.Add(vertTexCoord);
                                        break;

                                    case 2:
                                        AttributeData.TexCoord_2.Add(vertTexCoord);
                                        break;

                                    case 3:
                                        AttributeData.TexCoord_3.Add(vertTexCoord);
                                        break;

                                    case 4:
                                        AttributeData.TexCoord_4.Add(vertTexCoord);
                                        break;

                                    case 5:
                                        AttributeData.TexCoord_5.Add(vertTexCoord);
                                        break;

                                    case 6:
                                        AttributeData.TexCoord_6.Add(vertTexCoord);
                                        break;

                                    case 7:
                                        AttributeData.TexCoord_7.Add(vertTexCoord);
                                        break;
                                    }

                                    vert.SetAttributeIndex(Enums.GXVertexAttribute.Tex0 + texNo, (uint)texCoordData.IndexOf(vertTexCoord));
                                    break;
                                }
                            }

                            prim.Vertices.Add(vert);
                        }
                    }
                }

                /*
                 * if (prim.PrimitiveType == Enums.GXPrimitiveType.TriangleStrip) {
                 *  Debug.Assert(prim.Vertices.Count >= 3);
                 * }
                 * else if (prim.PrimitiveType == Enums.GXPrimitiveType.Triangles) {
                 *  Debug.Assert(prim.Vertices.Count % 3 == 0);
                 * }*/
                //Console.WriteLine(String.Format("We had this many matrices: {0}", numMatrices));
                pack.Primitives.Add(prim);
            }
            Packets.Add(pack);

            int mostmatrices = 0;

            if (true)
            {
                List <Weight> packWeights = new List <Weight>();
                foreach (Packet packet in Packets)
                {
                    int matrices = 0;

                    foreach (Primitive prim in packet.Primitives)
                    {
                        foreach (Vertex vert in prim.Vertices)
                        {
                            if (!packWeights.Contains(vert.VertexWeight))
                            {
                                packWeights.Add(vert.VertexWeight);
                                matrices++;
                            }
                        }


                        if (prim.PrimitiveType == Enums.GXPrimitiveType.TriangleStrip)
                        {
                            Debug.Assert(prim.Vertices.Count >= 3);
                        }
                        else if (prim.PrimitiveType == Enums.GXPrimitiveType.Triangles)
                        {
                            Debug.Assert(prim.Vertices.Count % 3 == 0);
                        }
                    }
                    if (matrices > mostmatrices)
                    {
                        mostmatrices = matrices;
                    }
                    //Debug.Assert(matrices <= MaxMatricesPerPacket);
                    //Console.WriteLine(matrices);
                    packWeights.Clear();
                }
            }
            //Console.WriteLine(String.Format("Most matrices: {0}", mostmatrices));
        }
Esempio n. 45
0
                                      select(Descriptor: descriptor, Args: args)
 )
                                                                         .ToDictionary(r => r.Descriptor, r => r.Args);
Esempio n. 46
0
        public void ProcessVerticesWithoutWeights(Mesh mesh, VertexData vertData)
        {
            Packet pack = new Packet();


            List <Enums.GXVertexAttribute> activeAttribs = Descriptor.GetActiveAttributes();

            AttributeData.SetAttributesFromList(activeAttribs);

            //Console.WriteLine("Calculating triangle strips");

            uint[]                triindices = MakeTriIndexList(mesh);
            TriStripper           stripper   = new TriStripper(triindices);
            List <PrimitiveBrawl> primlist   = stripper.Strip();

            //Console.WriteLine(String.Format("Done, {0} primitives", primlist.Count));

            foreach (PrimitiveBrawl primbrawl in primlist)
            {
                //Primitive prim = new Primitive(Enums.GXPrimitiveType.TriangleStrip);
                Primitive prim = new Primitive((Enums.GXPrimitiveType)primbrawl.Type);
                //Console.WriteLine(String.Format("Primitive type {0}", (Enums.GXPrimitiveType)primbrawl.Type));
                foreach (int vertIndex in primbrawl.Indices)
                {
                    Vertex vert = new Vertex();

                    Weight rootWeight = new Weight();
                    rootWeight.AddWeight(1.0f, 0);

                    vert.SetWeight(rootWeight);
                    //int vertIndex = face.Indices[i];

                    foreach (Enums.GXVertexAttribute attrib in activeAttribs)
                    {
                        switch (attrib)
                        {
                        case Enums.GXVertexAttribute.Position:
                            List <Vector3> posData = (List <Vector3>)vertData.GetAttributeData(Enums.GXVertexAttribute.Position);
                            Vector3        vertPos = mesh.Vertices[vertIndex].ToOpenTKVector3();

                            if (!posData.Contains(vertPos))
                            {
                                posData.Add(vertPos);
                            }
                            AttributeData.Positions.Add(vertPos);

                            vert.SetAttributeIndex(Enums.GXVertexAttribute.Position, (uint)posData.IndexOf(vertPos));
                            break;

                        case Enums.GXVertexAttribute.Normal:
                            List <Vector3> normData = (List <Vector3>)vertData.GetAttributeData(Enums.GXVertexAttribute.Normal);
                            Vector3        vertNrm  = mesh.Normals[vertIndex].ToOpenTKVector3();

                            if (!normData.Contains(vertNrm))
                            {
                                normData.Add(vertNrm);
                            }
                            AttributeData.Normals.Add(vertNrm);

                            vert.SetAttributeIndex(Enums.GXVertexAttribute.Normal, (uint)normData.IndexOf(vertNrm));
                            break;

                        case Enums.GXVertexAttribute.Color0:
                        case Enums.GXVertexAttribute.Color1:
                            int          colNo   = (int)attrib - 11;
                            List <Color> colData = (List <Color>)vertData.GetAttributeData(Enums.GXVertexAttribute.Color0 + colNo);
                            Color        vertCol = mesh.VertexColorChannels[colNo][vertIndex].ToSuperBMDColorRGBA();


                            if (colNo == 0)
                            {
                                AttributeData.Color_0.Add(vertCol);
                            }
                            else
                            {
                                AttributeData.Color_1.Add(vertCol);
                            }


                            vert.SetAttributeIndex(Enums.GXVertexAttribute.Color0 + colNo, (uint)colData.IndexOf(vertCol));
                            break;

                        case Enums.GXVertexAttribute.Tex0:
                        case Enums.GXVertexAttribute.Tex1:
                        case Enums.GXVertexAttribute.Tex2:
                        case Enums.GXVertexAttribute.Tex3:
                        case Enums.GXVertexAttribute.Tex4:
                        case Enums.GXVertexAttribute.Tex5:
                        case Enums.GXVertexAttribute.Tex6:
                        case Enums.GXVertexAttribute.Tex7:
                            int            texNo        = (int)attrib - 13;
                            List <Vector2> texCoordData = (List <Vector2>)vertData.GetAttributeData(Enums.GXVertexAttribute.Tex0 + texNo);
                            Vector2        vertTexCoord = mesh.TextureCoordinateChannels[texNo][vertIndex].ToOpenTKVector2();
                            vertTexCoord = new Vector2(vertTexCoord.X, 1.0f - vertTexCoord.Y);


                            switch (texNo)
                            {
                            case 0:
                                AttributeData.TexCoord_0.Add(vertTexCoord);
                                break;

                            case 1:
                                AttributeData.TexCoord_1.Add(vertTexCoord);
                                break;

                            case 2:
                                AttributeData.TexCoord_2.Add(vertTexCoord);
                                break;

                            case 3:
                                AttributeData.TexCoord_3.Add(vertTexCoord);
                                break;

                            case 4:
                                AttributeData.TexCoord_4.Add(vertTexCoord);
                                break;

                            case 5:
                                AttributeData.TexCoord_5.Add(vertTexCoord);
                                break;

                            case 6:
                                AttributeData.TexCoord_6.Add(vertTexCoord);
                                break;

                            case 7:
                                AttributeData.TexCoord_7.Add(vertTexCoord);
                                break;
                            }

                            vert.SetAttributeIndex(Enums.GXVertexAttribute.Tex0 + texNo, (uint)texCoordData.IndexOf(vertTexCoord));
                            break;
                        }
                    }

                    //triindices[vertIndex] = 1;
                    prim.Vertices.Add(vert);
                }

                pack.Primitives.Add(prim);
            }


            pack.MatrixIndices.Add(0);
            Packets.Add(pack);

            Bounds.GetBoundsValues(AttributeData.Positions);
        }
        public override async Task ReportsDiagnostic_WhenUsingReEntrantReturnsForAnyArgsViaMethodCall(string method, string reEntrantCall)
        {
            var plainMethodName = method.Replace("SubstituteExtensions.", string.Empty).Replace("(Of Integer)", string.Empty);

            var source = $@"Imports NSubstitute

Namespace MyNamespace
    Interface IFoo
        Function Bar() As Integer
    End Interface

    Interface IBar
        Function Foo() As Integer
    End Interface

    Public Class FooTests
        Public Sub Test()
            Dim substitute = NSubstitute.Substitute.[For](Of IFoo)()
            {method}(substitute.Bar(), [|ReturnThis()|], [|OtherReturn()|])
        End Sub

        Private Function ReturnThis() As Integer
            Return OtherReturn()
        End Function

        Private Function OtherReturn() As Integer
            Dim substitute = NSubstitute.Substitute.[For](Of IBar)()
            {reEntrantCall}
            Return 1
        End Function
    End Class
End Namespace
";

            var textParserResult = TextParser.GetSpans(source);

            var diagnosticMessages = new[]
            {
                $"{plainMethodName}() is set with a method that itself calls ReturnsForAnyArgs. This can cause problems with NSubstitute. Consider replacing with a lambda: {plainMethodName}(Function(x) ReturnThis()).",
                $"{plainMethodName}() is set with a method that itself calls ReturnsForAnyArgs. This can cause problems with NSubstitute. Consider replacing with a lambda: {plainMethodName}(Function(x) OtherReturn())."
            };

            var diagnostics = textParserResult.Spans.Select((span, idx) => CreateDiagnostic(Descriptor.OverrideMessage(diagnosticMessages[idx]), span.Span, span.LineSpan)).ToArray();

            await VerifyDiagnostic(textParserResult.Text, diagnostics);
        }
 protected override HttpParameterBinding CreateInnerBinding(IEnumerable <MediaTypeFormatter> perRequestFormatters)
 {
     return(Descriptor.BindWithFormatter(perRequestFormatters, bodyModelValidator: null));
 }
Esempio n. 49
0
 protected void RawDataAdd(byte[] aRawData)
 {
     Descriptor.RawDataAdd(aRawData);
 }
Esempio n. 50
0
        private bool BuildParameterDescriptor(
            Descriptor descriptor, FbParameter parameter, int index)
        {
            Charset  charset = this.connection.InnerConnection.Database.Charset;
            FbDbType type    = parameter.FbDbType;

            // Check the parameter character set
            if (parameter.Charset != FbCharset.Default)
            {
                int idx = Charset.SupportedCharsets.IndexOf((int)parameter.Charset);
                charset = Charset.SupportedCharsets[idx];
            }
            else
            {
                if (type == FbDbType.Guid)
                {
                    charset = Charset.SupportedCharsets["OCTETS"];
                }
            }

            // Set parameter Data Type
            descriptor[index].DataType =
                (short)TypeHelper.GetFbType((DbDataType)type, parameter.IsNullable);

            // Set parameter Sub Type
            switch (type)
            {
            case FbDbType.Binary:
                descriptor[index].SubType = 0;
                break;

            case FbDbType.Text:
                descriptor[index].SubType = 1;
                break;

            case FbDbType.Guid:
                descriptor[index].SubType = (short)charset.ID;
                break;

            case FbDbType.Char:
            case FbDbType.VarChar:
                descriptor[index].SubType = (short)charset.ID;
                if (parameter.Size > 0)
                {
                    short len = (short)(parameter.Size * charset.BytesPerCharacter);
                    descriptor[index].Length = len;
                }
                break;
            }

            // Set parameter length
            if (descriptor[index].Length == 0)
            {
                descriptor[index].Length = TypeHelper.GetSize((DbDataType)type);
            }

            // Verify parameter
            if (descriptor[index].SqlType == 0 || descriptor[index].Length == 0)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 51
0
 protected void RawDataClear()
 {
     Descriptor.RawDataClear();
 }
Esempio n. 52
0
        public override byte[] Rebuild()
        {
            FileOutput f = new FileOutput();

            f.endian = Endianness.Little;
            FileOutput fv = new FileOutput();

            fv.endian = Endianness.Little;

            f.WriteShort(format);
            f.WriteShort(unknown);
            f.WriteInt(flags);
            f.WriteInt(mode);
            bool hasNameTable = (flags & 2) > 0;

            f.WriteInt(mesh.Count);

            int vertSize = 0;

            // Vertex Bank
            for (int i = 0; i < 1; i++)
            {
                if (mode == 0 || i == 0)
                {
                    Descriptor des = descript[i];

                    if (format != 4)
                    {
                        foreach (Vertex v in vertices)
                        {
                            for (int k = 0; k < des.type.Length; k++)
                            {
                                fv.Align(2, 0x00);
                                switch (des.type[k])
                                {
                                case 0:     //Position
                                    writeType(fv, v.pos.X, des.format[k], des.scale[k]);
                                    writeType(fv, v.pos.Y, des.format[k], des.scale[k]);
                                    writeType(fv, v.pos.Z, des.format[k], des.scale[k]);
                                    break;

                                case 1:     //Normal
                                    writeType(fv, v.nrm.X, des.format[k], des.scale[k]);
                                    writeType(fv, v.nrm.Y, des.format[k], des.scale[k]);
                                    writeType(fv, v.nrm.Z, des.format[k], des.scale[k]);
                                    break;

                                case 2:     //Color
                                    writeType(fv, v.col.X, des.format[k], des.scale[k]);
                                    writeType(fv, v.col.Y, des.format[k], des.scale[k]);
                                    writeType(fv, v.col.Z, des.format[k], des.scale[k]);
                                    writeType(fv, v.col.W, des.format[k], des.scale[k]);
                                    break;

                                case 3:     //Tex0
                                    writeType(fv, v.tx[0].X, des.format[k], des.scale[k]);
                                    writeType(fv, v.tx[0].Y, des.format[k], des.scale[k]);
                                    break;

                                case 4:     //Tex1
                                    writeType(fv, v.tx[1].X, des.format[k], des.scale[k]);
                                    writeType(fv, v.tx[1].Y, des.format[k], des.scale[k]);
                                    break;

                                case 5:     //Bone Index
                                    fv.WriteByte(v.node[0]);
                                    fv.WriteByte(v.node[1]);
                                    break;

                                case 6:     //Bone Weight
                                    writeType(fv, v.weight[0], des.format[k], des.scale[k]);
                                    writeType(fv, v.weight[1], des.format[k], des.scale[k]);
                                    break;
                                    //default:
                                    //    Console.WriteLine("WTF is this");
                                }
                            }
                        }
                        vertSize = fv.Size();
                        fv.Align(32, 0xFF);
                    }
                }


                for (int j = 0; j < mesh.Count; j++)
                {
                    foreach (List <int> l in mesh[j].faces)
                    {
                        foreach (int index in l)
                        {
                            fv.WriteShort(index);
                        }
                        fv.Align(32, 0xFF);
                    }
                }
            }


            for (int i = 0; i < mesh.Count; i++)
            {
                if (i == 0 && mode == 1)
                {
                    descript[0].WriteDescription(f);
                    f.WriteInt(vertSize);
                }

                f.WriteInt(mesh[i].nodeList.Count);
                //Console.WriteLine(mesh[i].faces.Count + " " + mesh[i].nodeList.Count);
                for (int j = 0; j < mesh[i].nodeList.Count; j++)
                {
                    f.WriteInt(mesh[i].nodeList[j].Count);

                    for (int k = 0; k < mesh[i].nodeList[j].Count; k++)
                    {
                        f.WriteInt(mesh[i].nodeList[j][k]);
                    }

                    f.WriteInt(mesh[i].faces[j].Count);

                    // TODO: This stuff
                    if (hasNameTable)
                    {
                        //int nameId = d.readInt();
                    }

                    /*if (mode == 0)
                     * {
                     *  if (format == 4)
                     *  {
                     *      int[] buffer = new int[primitiveCount];
                     *      for (int k = 0; k < primitiveCount; k++)
                     *      {
                     *          buffer[k] = d.readShort();
                     *      }
                     *      d.align(4);
                     *      List<int> buf = new List<int>();
                     *      buf.AddRange(buffer);
                     *      m.faces.Add(buf);
                     *  }
                     *  else
                     *  {
                     *      Descriptor des = new Descriptor();
                     *      des.ReadDescription(d);
                     *      descript.Add(des);
                     *  }
                     *
                     * }*/
                }
            }

            // TODO: STRING TABLE

            /*if (hasNameTable)
             * {
             *  for (int i = 0; i < mesh.Count; i++)
             *  {
             *      int index = d.readByte();
             *      nameTable.Add(d.readString());
             *  }
             * }*/


            if (format != 4)
            {
                f.Align(32, 0xFF);
            }

            f.WriteOutput(fv);

            return(f.GetBytes());
        }
Esempio n. 53
0
 private void RegisterAsType(Descriptor nullClientDescriptor, Type p1)
 {
     throw new NotImplementedException();
 }
Esempio n. 54
0
        protected DescriptorHeap(ref Descriptor desc, Device device, string label) : base(ref desc, device, label)
        {
            associatedResources = new Resource[desc.NumResourceDescriptors];

            Create();
        }
Esempio n. 55
0
        /// <summary>
        /// Generate an <see cref="IReinforcementModel"/> based on a set of examples and transitions.
        /// </summary>
        /// <exception cref="InvalidOperationException">Thrown when the requested operation is invalid.</exception>
        /// <param name="descriptor">The description.</param>
        /// <param name="examples1">Example training set or state/action pairs.</param>
        /// <param name="transitionDescriptor">(Optional) Descriptor for extracting transition state/reward information from <paramref name="examples2"/> set.</param>
        /// <param name="examples2">(Optional) Corresponding training set where each item represents a transition state from <paramref name="examples1"/> and a reward label.</param>
        /// <returns>IReinforcementModel.</returns>
        public IReinforcementModel Generate(Descriptor descriptor, IEnumerable <object> examples1, Descriptor transitionDescriptor, IEnumerable <object> examples2)
        {
            if (examples1.Count() == 0)
            {
                throw new InvalidOperationException("Empty example set.");
            }

            bool hasTransitionStates = (examples2 != null && examples2.Any());

            this.Descriptor           = descriptor;
            this.TransitionDescriptor = transitionDescriptor;

            if (Descriptor.Features == null || Descriptor.Features.Length == 0)
            {
                throw new InvalidOperationException("Invalid State Descriptor: Empty feature set!");
            }
            if (Descriptor.Label == null)
            {
                throw new InvalidOperationException("Invalid State Descriptor: Empty label!");
            }

            if (hasTransitionStates)
            {
                if (TransitionDescriptor == null || TransitionDescriptor.Features == null || TransitionDescriptor.Features.Length == 0)
                {
                    throw new ArgumentNullException($"Transition Descriptor was null. A transition desciptor is required for '{nameof(examples2)}'.");
                }
                if (examples2.Count() != examples1.Count())
                {
                    throw new InvalidOperationException($"Length of '{nameof(examples1)}' must match length of '{nameof(examples2)}'.");
                }
            }

            var doubles = this.Descriptor.Convert(examples1);

            var(states, actions) = doubles.ToExamples();

            Matrix statesP = null;
            Vector rewards = Vector.Rand(actions.Length);

            if (hasTransitionStates)
            {
                var doubles2 = this.TransitionDescriptor.Convert(examples2);
                (statesP, rewards) = doubles2.ToExamples();
            }
            else
            {
                statesP = new Matrix(states.Rows, states.Cols);
                // assume temporal
                for (int i = 0; i < states.Rows - 1; i++)
                {
                    statesP[i, VectorType.Row] = states[i + 1, VectorType.Row];
                }
            }

            return(Generate(states, actions, statesP, rewards));
        }
 protected override string GetCategory(Descriptor desc)
 {
     return(string.Empty);
 }
Esempio n. 57
0
 public MapChange(long transactionId, Descriptor descriptor, TransactionType operation)
 {
     TransactionId = transactionId;
     Descriptor    = descriptor;
     Operation     = operation;
 }
Esempio n. 58
0
 /// <summary>
 /// Generates an <see cref="IReinforcementModel"/> from a descriptor and examples.
 /// </summary>
 /// <typeparam name="T">Object type</typeparam>
 /// <param name="descriptor">The description.</param>
 /// <param name="examples1">Example training set.</param>
 /// <param name="examples2">(Optional) Corresponding training set where each item represents a transition from <paramref name="examples1"/>.</param>
 /// <returns>IReinforcementModel</returns>
 public IReinforcementModel Generate <T>(Descriptor descriptor, IEnumerable <T> examples1, IEnumerable <T> examples2) where T : class
 {
     return(Generate(descriptor, examples1 as IEnumerable <object>, examples2 as IEnumerable <object>));
 }
Esempio n. 59
0
 public void OnLobby(Descriptor descriptor)
 {
     desc    = descriptor;
     tb.text = desc.Name();
 }
Esempio n. 60
0
        public override async Task ReportsDiagnostic_WhenUsingReEntrantReturnsForAnyArgsViaMethodCall(string method, string reEntrantCall)
        {
            var plainMethodName = method.Replace("<int>", string.Empty);
            var source          = $@"using NSubstitute;

namespace MyNamespace
{{
    public interface IFoo
    {{
        int Bar();
    }}

    public interface IBar
    {{
        int Foo();
    }}

    public class FooTests
    {{
        public void Test()
        {{
            var substitute = Substitute.For<IFoo>();
            substitute.Bar().{method}([|ReturnThis()|], [|OtherReturn()|]);
        }}


        private int ReturnThis()
        {{
            return OtherReturn();
        }}

        private int OtherReturn()
        {{
            var substitute = Substitute.For<IBar>();
            {reEntrantCall}
            return 1;
        }}
    }}
}}";

            var textParserResult = TextParser.GetSpans(source);

            var diagnosticMessages = new[]
            {
                $"{plainMethodName}() is set with a method that itself calls ReturnsForAnyArgs. This can cause problems with NSubstitute. Consider replacing with a lambda: {plainMethodName}(x => ReturnThis()).",
                $"{plainMethodName}() is set with a method that itself calls ReturnsForAnyArgs. This can cause problems with NSubstitute. Consider replacing with a lambda: {plainMethodName}(x => OtherReturn())."
            };

            var diagnostics = textParserResult.Spans.Select((span, idx) => CreateDiagnostic(Descriptor.OverrideMessage(diagnosticMessages[idx]), span.Span, span.LineSpan)).ToArray();

            await VerifyDiagnostic(textParserResult.Text, diagnostics);
        }