public NDArray() { Logging.CHECK_EQ(NativeMethods.MXNDArrayCreateNone(out var @out), NativeMethods.OK); this.NativePtr = @out; this._Blob = new NDBlob(@out); }
public NDArray(mx_float[] data, Shape shape, Context context) { if (data == null) { throw new ArgumentNullException(nameof(data)); } if (shape == null) { throw new ArgumentNullException(nameof(shape)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } Logging.CHECK_EQ(NativeMethods.MXNDArrayCreate(shape.Data, (uint)shape.Dimension, (int)context.GetDeviceType(), context.GetDeviceId(), false.ToInt32(), out var @out), NativeMethods.OK); NativeMethods.MXNDArraySyncCopyFromCPU(@out, data, shape.Size); this.NativePtr = @out; this._Blob = new NDBlob(@out); }
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); }
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); }
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)context.GetDeviceType(), context.GetDeviceId(), delayAlloc.ToInt32(), out var @out), NativeMethods.OK); this.NativePtr = @out; this._Blob = new NDBlob(@out); }
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)context.GetDeviceType(), context.GetDeviceId(), delayAlloc.ToInt32(), out var @out), NativeMethods.OK); this.NativePtr = @out; this._Blob = new NDBlob(@out); }