예제 #1
0
        public string Visit(Array_ node, int modo)
        {
            var array = "";

            array = array + Visit((dynamic)node[0], 7);
            Console.WriteLine("hola hola " + array);
            var array1           = array.Split();
            var stringBuilder    = new StringBuilder();
            var variableTempName = GenerateLabel();

            // Add variable to stack
            stringBuilder.Append(String.Format("\t\t.locals init (int64 '{0}')\n", variableTempName));
            // Create array handle
            stringBuilder.Append("\t\tldc.i8 0\n");
            stringBuilder.Append("\t\tcall int64 class ['int64lib']'Int64'.'Utils'::'New'(int64)\n");
            stringBuilder.Append(String.Format("\t\tstloc '{0}'\n", variableTempName));
            // Add values
            foreach (var m in array1)
            {
                stringBuilder.Append(String.Format("\t\tldloc '{0}'\n", variableTempName));
                stringBuilder.Append(String.Format("\t\tldc.i8 {0}\n", m));
                stringBuilder.Append("\t\tcall int64 class ['int64lib']'Int64'.'Utils'::'Add'(int64, int64)\n");
                stringBuilder.Append("\t\tpop\n");
            }
            // Load to top of stack
            stringBuilder.Append(String.Format("\t\tldloc '{0}'\n", variableTempName));
            return(stringBuilder.ToString());
        }
예제 #2
0
 public object[]? ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
 {
     if (!(value is bool b))
     {
         return(null);
     }
     return(Array_.New <object>(targetTypes.Length, i => b));
 }
예제 #3
0
 public static Array <Int> Div(this Array <Int> a, Array <Int> b, Array <Int> result = null)
 {
     return(Array_.ElementwiseOp(a, b, result,
                                 (n, x, offsetx, incx, y, offsety, incy, z, offsetz, incz) =>
     {
         for (int i = 0; i < n; i++)
         {
             z[offsetz] = x[offsetx] / y[offsety];
             offsetx += incx;
             offsety += incy;
             offsetz += incz;
         }
     }));
 }
예제 #4
0
 public static Array <Int> Acc(this Array <Int> a, Array <Int> b, Int alpha = 1)
 {
     Array_.ElementwiseOp(a, b,
                          (n, x, offsetx, incx, y, offsety, incy) =>
     {
         for (int i = 0; i < n; i++)
         {
             x[offsetx] += alpha * y[offsety];
             offsetx    += incx;
             offsety    += incy;
         }
     });
     return(a);
 }
예제 #5
0
 public static Array <Int> Apply(this Array <Int> a, Array <Int> b, Func <Int, Int, Int> fn, Array <Int> result = null)
 {
     return(Array_.ElementwiseOp(a, b, result,
                                 (n, x, offsetx, incx, y, offsety, incy, z, offsetz, incz) =>
     {
         for (int i = 0; i < n; i++)
         {
             z[offsetz] = fn(x[offsetx], y[offsety]);
             offsetx += incx;
             offsety += incy;
             offsetz += incz;
         }
     }));
 }
예제 #6
0
        public Node array_list()
        {
            //Console.WriteLine("array_list");
            var array = new Array_();
            var r     = Expect(TokenCategory.OPENB);

            array.AnchorToken = r;
            while (CurrentToken != TokenCategory.CLOSEB)
            {
                array.Add(lit_list());
            }
            //Console.WriteLine("CLOSEB1");
            Expect(TokenCategory.CLOSEB);
            return(array);
        }
예제 #7
0
        public static Int Min(this Array <Int> a)
        {
            Int result = Int.MaxValue;

            Array_.ElementwiseOp(0, a, 0,
                                 (n, x, offsetx, incx) =>
            {
                Int s = Int.MaxValue;
                for (int i = 0; i < n; i++)
                {
                    s        = Math.Min(s, x[offsetx]);
                    offsetx += incx;
                }
                result = Math.Min(result, s);
            });
            return(result);
        }
예제 #8
0
 public static Array <Int> Apply(this Array <Int> a, Func <Int, Int> fn, Array <Int> result = null)
 {
     if (result == null)
     {
         result = new Array <Int>(a.Shape);
     }
     Array_.ElementwiseOp(a, result, (n, x, offsetx, incx, y, offsety, incy) =>
     {
         for (int i = 0; i < n; i++)
         {
             y[offsety] = fn(x[offsetx]);
             offsetx   += incx;
             offsety   += incy;
         }
     });
     return(result);
 }
예제 #9
0
 public static Array <Int> Copy(this Array <Int> a, Array <Int> result = null)
 {
     if (result == null)
     {
         result = new Array <Int>(a.Shape);
     }
     Array_.ElementwiseOp(result, a, (n, x, offsetx, incx, y, offsety, incy) =>
     {
         //Blas.copy(n, y, offsety, incy, x, offsetx, incx);
         for (int i = 0; i < n; i++)
         {
             x[offsetx] = y[offsety];
             offsetx   += incx;
             offsety   += incy;
         }
     });
     return(result);
 }
예제 #10
0
        // result = a + alpha * b
        public static Array <Int> Add(this Array <Int> a, Array <Int> b, Int alpha = 1, Array <Int> result = null)
        {
            if (result == a)
            {
                return(a.Acc(b, alpha));
            }

            return(Array_.ElementwiseOp(a, b, result,
                                        (n, x, offsetx, incx, y, offsety, incy, z, offsetz, incz) =>
            {
                for (int i = 0; i < n; i++)
                {
                    z[offsetz] = x[offsetx] + alpha * y[offsety];
                    offsetx += incx;
                    offsety += incy;
                    offsetz += incz;
                }
            }));
        }
예제 #11
0
        /// <summary>Verify that a file has a valid signature</summary>
        public static bool Validate(string filepath, string public_key, bool thrw = true)
        {
            // Create the 'Crypto' service
            var alg = new RSACryptoServiceProvider();

            alg.FromXmlString(public_key);
            var key_size_bytes = alg.KeySize / 8;

            // Read the file into memory (no fancy streaming...)
            var filebuf = File.ReadAllBytes(filepath);
            var length  = filebuf.Length;

            // The total length of the signature in bytes
            var sig_length = key_size_bytes + SignatureId.Length;

            // Check whether the file has a signature
            if (length >= sig_length && Array_.Compare(
                    filebuf, length - sig_length, SignatureId.Length,
                    SignatureId, 0, SignatureId.Length) == 0)
            {
                length -= sig_length;
            }
            else
            {
                if (thrw)
                {
                    throw new VerificationException("File is not signed");
                }
                return(false);
            }

            // Validate the signature
            var  buf   = filebuf.Take(length).ToArray();
            var  sig   = filebuf.Skip(length + SignatureId.Length).Take(key_size_bytes).ToArray();
            bool valid = alg.VerifyData(buf, new SHA256CryptoServiceProvider(), sig);

            if (thrw && !valid)
            {
                throw new VerificationException("File signature incorrect");
            }
            return(valid);
        }
예제 #12
0
        /// <summary>Creates a bitmap containing a checker board where each 'checker' is 'sx' x 'sy'</summary>
        public static Image BitmapChecker(int sx, int sy, uint X = 0xFFFFFFFFU, uint O = 0x00000000U)
        {
            var w    = 2 * sx;
            var h    = 2 * sy;
            var bmp  = new Bitmap(w, h, PixelFormat.Format32bppArgb);
            var row0 = Array_.New(sx, unchecked ((int)O));
            var row1 = Array_.New(sx, unchecked ((int)X));

            using (var bits = bmp.LockBits(ImageLockMode.WriteOnly))
            {
                for (int j = 0; j != sy; ++j)
                {
                    Marshal.Copy(row0, 0, bits.Value.Scan0 + ((j + 0) * w) * sizeof(int), row0.Length);
                    Marshal.Copy(row1, 0, bits.Value.Scan0 + ((j + 0) * w + sx) * sizeof(int), row1.Length);
                    Marshal.Copy(row1, 0, bits.Value.Scan0 + ((j + sy) * w) * sizeof(int), row1.Length);
                    Marshal.Copy(row0, 0, bits.Value.Scan0 + ((j + sy) * w + sx) * sizeof(int), row0.Length);
                }
            }
            return(bmp);
        }
예제 #13
0
        public static int Argmax(this Array <Int> a, int[] result = null)
        {
            Int min = Int.MinValue;
            int pos = -1;

            Array_.ElementwiseOp(0, a, 0,
                                 (n, x, offsetx, incx) =>
            {
                for (int i = 0; i < n; i++)
                {
                    if (x[offsetx] > min)
                    {
                        min = x[offsetx];
                        pos = offsetx;
                    }
                    offsetx += incx;
                }
            });
            return(pos);
        }