예제 #1
0
        public static void Initialize()
        {
            Py.Initialize();
            NumPy.Initialize();

            Main = PyImport.AddModule("__main__");
        }
예제 #2
0
        public unsafe T this[params long[] indices]
        {
            get
            {
                if (typeof(T).IsArray)
                {
                    //todo 配列の取得は未対応
                    throw new NotImplementedException();
                }
                else
                {
                    IntPtr addr = NumPy.PyArrayGetPtr(this, indices);
                    return(Unsafe.Read <T>((void *)addr));
                }
            }

            set
            {
                if (value is Array array)
                {
                    Type t = value.GetType().GetElementType();

                    GCHandle handle;

                    if (t == array.GetType().GetElementType())
                    {
                        handle = GCHandle.Alloc(array, GCHandleType.Pinned);
                    }
                    else
                    {
                        long[] dims = new long[array.Rank];

                        for (int i = 0; i < dims.Length; i++)
                        {
                            dims[i] = array.GetLength(i);
                        }

                        Array tmp = Array.CreateInstance(typeof(T), dims);
                        Array.Copy(array, tmp, array.Length);

                        handle = GCHandle.Alloc(tmp, GCHandleType.Pinned);
                    }

                    int size = Marshal.SizeOf(t) * array.Length;

                    IntPtr addr = NumPy.PyArrayGetPtr(this, indices);

                    Buffer.MemoryCopy((void *)handle.AddrOfPinnedObject(), (void *)addr, size, size);

                    handle.Free();
                }
                else
                {
                    IntPtr addr = NumPy.PyArrayGetPtr(this, indices);
                    Unsafe.Write((void *)addr, value);
                }
            }
        }
예제 #3
0
        public static IntPtr Timedelta64; // = 22;

        static Dtype()
        {
            Bool        = NumPy.PyArrayDescrFromType(0);
            Int8        = NumPy.PyArrayDescrFromType(1);
            Uint8       = NumPy.PyArrayDescrFromType(2);
            Int16       = NumPy.PyArrayDescrFromType(3);
            Uint16      = NumPy.PyArrayDescrFromType(4);
            Int32       = NumPy.PyArrayDescrFromType(5);
            Uint32      = NumPy.PyArrayDescrFromType(6);
            Int64       = NumPy.PyArrayDescrFromType(9);
            Uint64      = NumPy.PyArrayDescrFromType(10);
            Float32     = NumPy.PyArrayDescrFromType(11);
            Float64     = NumPy.PyArrayDescrFromType(12);
            Complex64   = NumPy.PyArrayDescrFromType(14);
            Complex128  = NumPy.PyArrayDescrFromType(15);
            Object      = NumPy.PyArrayDescrFromType(17);
            S0          = NumPy.PyArrayDescrFromType(18);
            U0          = NumPy.PyArrayDescrFromType(19);
            V0          = NumPy.PyArrayDescrFromType(20);
            Datetime64  = NumPy.PyArrayDescrFromType(21);
            Timedelta64 = NumPy.PyArrayDescrFromType(22);
        }