Exemplo n.º 1
0
        public NDArray()
        {
            Logging.CHECK_EQ(NativeMethods.MXNDArrayCreateNone(out var @out), NativeMethods.OK);

            this.NativePtr = @out;
            this._Blob     = new NDBlob(@out);
        }
Exemplo n.º 2
0
        public NDArray(NDArrayHandle handle)
        {
            if (handle == NDArrayHandle.Zero)
            {
                throw new ArgumentException("Can not pass IntPtr.Zero", nameof(handle));
            }

            this.NativePtr = handle;
            this._Blob     = new NDBlob(handle);
        }
Exemplo n.º 3
0
        public NDArray(IList <mx_float> data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            Logging.CHECK_EQ(NativeMethods.MXNDArrayCreateNone(out var @out), NativeMethods.OK);

            NativeMethods.MXNDArraySyncCopyFromCPU(@out, data.ToArray(), (size_t)data.Count);

            this.NativePtr = @out;
            this._Blob     = new NDBlob(@out);
        }
Exemplo n.º 4
0
        public NDArray(Shape shape, bool delayAlloc = true)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            Logging.CHECK_EQ(NativeMethods.MXNDArrayCreate(shape.Data,
                                                           shape.Dimension,
                                                           (int)DeviceManager.Current.GetDeviceType(),
                                                           DeviceManager.Current.GetDeviceId(),
                                                           delayAlloc.ToInt32(),
                                                           out var @out), NativeMethods.OK);
            this.NativePtr = @out;
            this._Blob     = new NDBlob(@out);
        }
Exemplo n.º 5
0
        public NDArray(IList <mx_uint> shape, bool delayAlloc = true)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            var floats = shape as mx_uint[];
            var arg    = floats ?? shape.ToArray();

            Logging.CHECK_EQ(NativeMethods.MXNDArrayCreate(arg,
                                                           (uint)arg.Length,
                                                           (int)DeviceManager.Current.GetDeviceType(),
                                                           DeviceManager.Current.GetDeviceId(),
                                                           delayAlloc.ToInt32(),
                                                           out var @out), NativeMethods.OK);
            this.NativePtr = @out;
            this._Blob     = new NDBlob(@out);
        }
Exemplo n.º 6
0
        public NDArray(mx_float[] data, Shape shape)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            Logging.CHECK_EQ(NativeMethods.MXNDArrayCreate(shape.Data,
                                                           (uint)shape.Dimension,
                                                           (int)DeviceManager.Current.GetDeviceType(),
                                                           DeviceManager.Current.GetDeviceId(),
                                                           false.ToInt32(),
                                                           out var @out), NativeMethods.OK);

            NativeMethods.MXNDArraySyncCopyFromCPU(@out, data, shape.Size);

            this.NativePtr = @out;
            this._Blob     = new NDBlob(@out);
        }