Example #1
0
        public static string ToStringInShortFormat(this NDArray array, bool includeHeader)
        {
            var dtype = DType.GetType(array.GetDType());

            if (dtype == DType.Float64)
            {
                return(ToStringInShortFormat <double>(array, includeHeader));
            }
            if (dtype == DType.Float32)
            {
                return(ToStringInShortFormat <float>(array, includeHeader));
            }
            if (dtype == DType.Int64)
            {
                return(ToStringInShortFormat <long>(array, includeHeader));
            }
            if (dtype == DType.Int32)
            {
                return(ToStringInShortFormat <int>(array, includeHeader));
            }
            if (dtype == DType.Int8)
            {
                return(ToStringInShortFormat <sbyte>(array, includeHeader));
            }
            if (dtype == DType.UInt8)
            {
                return(ToStringInShortFormat <byte>(array, includeHeader));
            }

            throw new ArgumentException($"Type {dtype} cannot be displayed");
        }
Example #2
0
        public static PSObject To3DArray(PSObject self)
        {
            var array = self.BaseObject as NDArray;

            var dtype = DType.GetType(array.GetDType());

            if (dtype == DType.Float64)
            {
                return(new PSObject(array.To3DArray <double>()));
            }
            if (dtype == DType.Float32)
            {
                return(new PSObject(array.To3DArray <float>()));
            }
            if (dtype == DType.Int64)
            {
                return(new PSObject(array.To3DArray <long>()));
            }
            if (dtype == DType.Int32)
            {
                return(new PSObject(array.To3DArray <int>()));
            }
            if (dtype == DType.Int8)
            {
                return(new PSObject(array.To3DArray <sbyte>()));
            }
            if (dtype == DType.UInt8)
            {
                return(new PSObject(array.To3DArray <byte>()));
            }

            throw new ArgumentException($"Type {dtype} cannot be displayed");
        }
Example #3
0
        public CudaKernel GetKernel(string name, string signature)
        {
            var         pattern    = new Regex(@"""^\s*(const)?\s*([\w_]+)\s*(\*)?\s*([\w_]+)?\s*$""");
            var         args       = Regex.Replace(signature, @"\s+", " ").Split(',');
            List <bool> is_const   = new List <bool>();
            List <bool> is_ndarray = new List <bool>();
            List <int>  dtypes     = new List <int>();

            foreach (var arg in args)
            {
                var match = pattern.Match(arg);
                if (!match.Success || match.Groups[1].Value == "const")
                {
                    throw new Exception($"Invalid function prototype \"{ arg }\". Must be in the " +
                                        "form of \"(const) type (*) (name)\"");
                }

                is_const.Add(match.Groups[0].Success);
                string dtype = match.Groups[1].Value;
                is_ndarray.Add(match.Groups[2].Success);
                if (!cudaDtypeMap.ContainsKey(dtype))
                {
                    throw new Exception($"Unsupported kernel argument type {arg}");
                }

                dtypes.Add(cudaDtypeMap[dtype].Index);
            }

            NativeMethods.MXRtcCudaKernelCreate(Handle, name, dtypes.Count, is_ndarray.ToArray(), is_const.ToArray(), dtypes.ToArray(), out var kernel_handle);

            return(new CudaKernel(kernel_handle, name, is_ndarray.ToArray(), dtypes.Select(x => (DType.GetType(x))).ToArray()));
        }
Example #4
0
 private DType AuxType(int i)
 {
     NativeMethods.MXNDArrayGetAuxType(GetHandle(), i, out var out_type);
     return(DType.GetType(out_type));
 }