예제 #1
0
파일: StackOps.cs 프로젝트: griderd/gsvm
        void PushRegister(Register_t reg)
        {
            int size = registers.SizeOf(reg);

            switch (size)
            {
            case 8:
                uint64_t value64 = registers.Read <uint64_t>(reg);
                System.Diagnostics.Debug.Assert(value64 != null);
                stack.Push(value64);
                break;

            case 4:
                uint32_t value32 = registers.Read <uint32_t>(reg);
                System.Diagnostics.Debug.Assert(value32 != null);
                stack.Push(value32);
                break;

            case 2:
                uint16_t value16 = registers.Read <uint16_t>(reg);
                System.Diagnostics.Debug.Assert(value16 != null);
                stack.Push(value16);
                break;

            case 1:
                uint8_t value8 = registers.Read <uint8_t>(reg);
                System.Diagnostics.Debug.Assert(value8 != null);
                stack.Push(value8);
                break;
            }
        }
예제 #2
0
파일: StackOps.cs 프로젝트: griderd/gsvm
        void PushRegister(Register_t reg)
        {
            int size = registers.SizeOf(reg);

            switch (size)
            {
            case 8:
                uint64_t value64 = registers.Read <uint64_t>(reg);
                stack.Push(value64);
                break;

            case 4:
                uint32_t value32 = registers.Read <uint32_t>(reg);
                stack.Push(value32);
                break;

            case 2:
                uint16_t value16 = registers.Read <uint16_t>(reg);
                stack.Push(value16);
                break;

            case 1:
                uint8_t value8 = registers.Read <uint8_t>(reg);
                stack.Push(value8);
                break;
            }
        }
예제 #3
0
        //------------------ Battery Remaining Picture ----------------------------------

        public void setBatteryPic()
        {
            if (osd_battery_remaining <= 270)
            {
                osd_battery_pic = 0xb4;
            }
            else if (osd_battery_remaining <= 300)
            {
                osd_battery_pic = 0xb5;
            }
            else if (osd_battery_remaining <= 400)
            {
                osd_battery_pic = 0xb6;
            }
            else if (osd_battery_remaining <= 500)
            {
                osd_battery_pic = 0xb7;
            }
            else if (osd_battery_remaining <= 800)
            {
                osd_battery_pic = 0xb8;
            }
            else
            {
                osd_battery_pic = 0xb9;
            }
        }
예제 #4
0
        public void flush(uint8_t data, uint64_t size)
        {
            Debug.Assert(isOpened());

            std::error_code ec = new std::error_code();

            flush(data, new uint64_t(size), ref ec);
            if (ec != null)
            {
                throw std::system_error(ec, "MemoryMappedFile::flush");
            }
        }
예제 #5
0
        public void flush(uint8_t data, uint64_t size, ref std::error_code ec)
        {
            Debug.Assert(isOpened());

            uintptr_t pageSize = (uintptr_t)sysconf(_SC_PAGESIZE);
//C++ TO C# CONVERTER TODO TASK: There is no equivalent to 'reinterpret_cast' in C#:
            uintptr_t dataAddr   = reinterpret_cast <uintptr_t>(data);
            uintptr_t pageOffset = (dataAddr / pageSize) * pageSize;

//C++ TO C# CONVERTER TODO TASK: There is no equivalent to 'reinterpret_cast' in C#:
            int result = global::msync(reinterpret_cast <object>(pageOffset), (size_t)(dataAddr % pageSize + size), MS_SYNC);

            if (result == 0)
            {
                result = global::fsync(m_file);
                if (result == 0)
                {
                    ec = std::error_code();
                    return;
                }
            }

            ec = std::error_code(errno, std::system_category());
        }
예제 #6
0
        /* **************************************************************** */
        // Panel  : panClimb        // JDL Fixed 2
        // Needs  : X, Y locations
        // Output : Alt symbol and altitude value in meters from MAVLink
        // Size   : 1 x 7Hea  (rows x chars)
        // Staus  : done

        public int panClimb(int first_col, int first_line)
        {
            osd.setPanel(first_col, first_line);
            osd.openPanel();

            if (firmware_type == 2)
            {
                double  osd_climb_m_min = abs(osd_climb * 60.0);
                uint8_t symbol_climb    = 0x7D;
                if (osd_climb > 0.0)
                {
                    symbol_climb = 0x7B;
                }
                osd.printf("%c%4.0f%c", symbol_climb, osd_climb_m_min, 0x7F);
            }
            else
            {
                osd.printf("%c%3.0f%c", 0x16, osd_climb, 0x88);
//                osd.printf("%c%3.0f%c", 0x16, (double)(osd_climb), 0x88);
            }

            osd.closePanel();
            return(0);
        }
예제 #7
0
    public static vector <case_t> read_test_cases()
    {
        vector <case_t> cases = new vector <case_t>();

        uint8_t train_image  = read_file("train-images.idx3-ubyte");
        uint8_t train_labels = read_file("train-labels.idx1-ubyte");

        uint32_t case_count = byteswap_uint32((uint32_t)(train_image + 4));

        for (int i = 0; i < case_count; i++)
        {
            case_t c = new case_t(new tensor_t <float>(28, 28, 1), new tensor_t <float>(10, 1, 1));

            uint8_t[] img   = train_image + 16 + i * (28 * 28);
            uint8_t   label = train_labels + 8 + i;

            for (int x = 0; x < 28; x++)
            {
                for (int y = 0; y < 28; y++)
                {
                    c.data.functorMethod(x, y, 0) = img[x + y * 28] / 255.0f;
                }
            }

            for (int b = 0; b < 10; b++)
            {
                [email protected](b, 0, 0) = label == b != 0 ? 1.0f : 0.0f;
            }

            cases.push_back(c);
        }
        train_image  = null;
        train_labels = null;

        return(cases);
    }
예제 #8
0
        //------------------ Battery Remaining Picture ----------------------------------

        public void setBatteryPic()
        {
            if (osd_battery_remaining <= 270)
            {
                osd_battery_pic = 0xb4;
            }
            else if (osd_battery_remaining <= 300)
            {
                osd_battery_pic = 0xb5;
            }
            else if (osd_battery_remaining <= 400)
            {
                osd_battery_pic = 0xb6;
            }
            else if (osd_battery_remaining <= 500)
            {
                osd_battery_pic = 0xb7;
            }
            else if (osd_battery_remaining <= 800)
            {
                osd_battery_pic = 0xb8;
            }
            else osd_battery_pic = 0xb9;
        }
예제 #9
0
 public static extern void gs_clear(uint32_t clear_flags, out Vector4 color, float depth, uint8_t stencil);
예제 #10
0
 public RGBColor(uint8_t red, uint8_t green, uint8_t blue)
 {
     this.red   = red;
     this.green = green;
     this.blue  = blue;
 }
예제 #11
0
 public void deserialize(BinaryReader reader)
 {
     time  = reader.ReadSingle();
     magic = reader.ReadByte();
     upper.deserialize(reader);
 }
예제 #12
0
    public void setPixel(uint16_t index, uint8_t r, uint8_t g, uint8_t b)
    {
        Console.WriteLine("{0}, {1}, {2}", r, g, b);

        _pixels[index] = new RGBColor(r, g, b);
    }
예제 #13
0
        static int encodePulseModulation(PulseModulationEncoding encoding,
                                            uint32_t data, uint8_t[] rawData, uint8_t maxLen)
        {

            // Index 0 is a space. Set it to 0 length.
            rawData[0] = 0;
            int length = 1;

            if ((encoding.headerMark != 0) && (length + 2 < maxLen))
            {
                rawData[length++] = (byte)(encoding.headerMark / USECPERTICK);
                rawData[length++] = (byte)(encoding.headerSpace / USECPERTICK);
            }

            for (int i = encoding.numBits - 1; i >= 0 && length + 2 < maxLen; i--)
            {
                if ((data & (1 << i)) != 0)
                {
                    rawData[length++] = (byte)(encoding.oneMark / USECPERTICK);
                    rawData[length++] = (byte)(encoding.oneSpace / USECPERTICK);
                }
                else {
                    rawData[length++] = (byte)(encoding.zeroMark / USECPERTICK);
                    rawData[length++] = (byte)(encoding.zeroSpace / USECPERTICK);
                }
            }

            if ((encoding.stopMark != 0) && length < maxLen)
            {
                rawData[length++] = (byte)(encoding.stopMark / USECPERTICK);
            }

            return length;
        }
예제 #14
0
 public void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w)
 {
 }
예제 #15
0
 public void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b)
 {
     pixels[n] = (uint)(r << 16 | g << 8 | b);
 }
예제 #16
0
    static int Main()
    {
        vector <case_t> cases = read_test_cases();

        vector <layer_t> layers = new vector <layer_t>();

        conv_layer_t layer1 = new conv_layer_t(1, 5, 8, cases[0].data.size); // 28 * 28 * 1 -> 24 * 24 * 8
                                                                             //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
                                                                             //ORIGINAL LINE: relu_layer_t * layer2 = new relu_layer_t(layer1->out.size);
        relu_layer_t layer2 = new relu_layer_t(new point_t([email protected]));
        //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
        //ORIGINAL LINE: pool_layer_t * layer3 = new pool_layer_t(2, 2, layer2->out.size);
        pool_layer_t layer3 = new pool_layer_t(2, 2, new point_t([email protected])); // 24 * 24 * 8 -> 12 * 12 * 8

        //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
        //ORIGINAL LINE: conv_layer_t * layer4 = new conv_layer_t(1, 3, 10, layer3->out.size);
        conv_layer_t layer4 = new conv_layer_t(1, 3, 10, new point_t([email protected])); // 12 * 12 * 6 -> 10 * 10 * 10
                                                                                         //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
                                                                                         //ORIGINAL LINE: relu_layer_t * layer5 = new relu_layer_t(layer4->out.size);
        relu_layer_t layer5 = new relu_layer_t(new point_t([email protected]));
        //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
        //ORIGINAL LINE: pool_layer_t * layer6 = new pool_layer_t(2, 2, layer5->out.size);
        pool_layer_t layer6 = new pool_layer_t(2, 2, new point_t([email protected])); // 10 * 10 * 10 -> 5 * 5 * 10

        //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
        //ORIGINAL LINE: fc_layer_t * layer7 = new fc_layer_t(layer6->out.size, 10);
        fc_layer_t layer7 = new fc_layer_t(new point_t([email protected]), 10); // 4 * 4 * 16 -> 10

        layers.push_back((layer_t)layer1);
        layers.push_back((layer_t)layer2);
        layers.push_back((layer_t)layer3);
        layers.push_back((layer_t)layer4);
        layers.push_back((layer_t)layer5);
        layers.push_back((layer_t)layer6);
        layers.push_back((layer_t)layer7);



        float amse = 0F;
        int   ic   = 0;

        for (int ep = 0; ep < 100000;)
        {
            foreach (case_t t in cases)
            {
                float xerr = train(layers, t.data.functorMethod, [email protected]);
                amse += xerr;

                ep++;
                ic++;

                if (ep % 1000 == 0)
                {
                    Console.Write("case ");
                    Console.Write(ep);
                    Console.Write(" err=");
                    Console.Write(amse / ic);
                    Console.Write("\n");
                }

                // if ( GetAsyncKeyState( VK_F1 ) & 0x8000 )
                // {
                //     printf( "err=%.4f%\n", amse / ic  );
                //     goto end;
                // }
            }
        }
        // end:



        while (true)
        {
            uint8_t[] data = read_file("test.ppm");

            if (data != null)
            {
                //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
                //ORIGINAL LINE: uint8_t * usable = data;
                uint8_t[] usable = new uint8_t(data);

                while ((uint32_t)usable != 0x0A353532)
                {
                    usable++;
                }

                //C++ TO C# CONVERTER TODO TASK: There is no equivalent to most C++ 'pragma' directives in C#:
                //#pragma pack(push, 1)
                //C++ TO C# CONVERTER TODO TASK: C# does not allow declaring types within methods:
                //			struct RGB
                //			{
                //				uint8_t r, g, b;
                //			};
                //C++ TO C# CONVERTER TODO TASK: There is no equivalent to most C++ 'pragma' directives in C#:
                //#pragma pack(pop)

                RGB[] rgb = (RGB)usable;

                tensor_t <float> image = new tensor_t <float>(28, 28, 1);
                for (int i = 0; i < 28; i++)
                {
                    for (int j = 0; j < 28; j++)
                    {
                        RGB rgb_ij = rgb[i * 28 + j];
                        image.functorMethod(j, i, 0) = ((((float)rgb_ij.r + rgb_ij.g + rgb_ij.b) / (3.0f * 255.0f)));
                    }
                }

                forward(layers, image.functorMethod);
                tensor_t <float> @out = layers.back().@out;
                for (int i = 0; i < 10; i++)
                {
                    Console.Write("[{0:D}] {1:f}\n", i, @out.functorMethod(i, 0, 0) * 100.0f);
                }

                data = null;
            }

            timespec wait = new timespec();
            wait.tv_sec  = 1;
            wait.tv_nsec = 0;
            nanosleep(wait, null);
        }
        return(0);
    }