/// <summary> /// minimum of all elements of array A /// </summary> /// <param name="A">n-dim array</param> /// <returns><para>scalar minimum of all elements of A.</para> /// <para>If A is empty, an empty array will be returned.</para></returns> /// <exception cref="ILNumerics.Exceptions.ILArgumentException">if A was null.</exception> /// <seealso cref="ILNumerics.BuiltInFunctions.ILMath.min(ILArray<double>)"/> public static ILArray <Int64> minall(ILArray <Int64> A) { if (object.Equals(A, null)) { throw new ILArgumentException("minall: argument must not be null!"); } if (A.IsEmpty) { return(ILArray <Int64> .empty(A.Dimensions)); } Int64 retArr = Int64.MaxValue; unsafe { fixed(Int64 *inArrStart = A.m_data) { Int64 *inArrWalk = inArrStart; Int64 *inArrEnd = inArrStart + A.Dimensions.NumberOfElements; while (inArrWalk < inArrEnd) { if (retArr > *inArrWalk) { retArr = *inArrWalk; } inArrWalk++; } } } return(new ILArray <Int64> (new Int64 [1] { retArr }, 1, 1)); }
public unsafe void CopyTo(EditBitmap destinationBitmap, int top, int left, int height, int width) { lock (LockObject) { // Find smallest array //int size = (int)Math.Min(ByteLength, destinationBitmap.ByteLength) / destinationBitmap.BytesPerPixel; // Copy memory //CopyMemory(ImageData, destinationBitmap.ImageData, size); //Marshal.Copy(src, destinationBitmap.ImageData, 0, size); // First copy int64 as far as we can (faster than copying single bytes) Int64 *src64 = (Int64 *)ImageData; Int64 *dst64 = (Int64 *)destinationBitmap.ImageData; byte * src8 = (byte *)ImageData; byte * dst8 = (byte *)destinationBitmap.ImageData; int maxWidth = Math.Min(Math.Min(Width - left, destinationBitmap.Width - left), width + top); int maxHeight = Math.Min(Math.Min(Height - top, destinationBitmap.Height - top), height + top); for (int x = top; x < maxHeight; x++) { for (int y = left; y < maxWidth; y++) { int srcp = (x * Width) + y; int dstp = (x * destinationBitmap.Width) + y; dst8[dstp] = src8[srcp]; } } } }
/// <summary> /// convert numerical ILArray to single precision floating point precision /// </summary> /// <param name="X">numeric input array</param> /// <returns><![CDATA[ILArray<float>]]> of same size as X having all elements converted to /// single precision floating point format.</returns> /// <remarks>All overloads of this function will return a solid physical copy /// of the input array X.</remarks> public static ILArray <float> single(ILArray <Int64> X) { int nrX = X.m_dimensions.NumberOfElements; float [] retArr = new float [nrX]; ILArray <float> ret = new ILArray <float> (retArr, X.m_dimensions); if (X.IsReference) { for (int i = 0; i < nrX; i++) { retArr[i] = (float)X.GetValue(i); } } else { unsafe { fixed(float *outArr = ret.m_data) fixed(Int64 * inArr = X.m_data) { float *lastElementAfter = outArr + nrX; float *outArrP = outArr; Int64 *inArrP = inArr; while (outArrP < lastElementAfter) { *outArrP++ = (float)*inArrP++; } } } } return(ret); }
public ParseBuffer(Token *queue, Int64 *stack) { mQueue = queue; mStack = stack; mQueueIndex = -1; mStackIndex = -1; }
/// <summary> /// sum all elements of array A /// </summary> /// <param name="A">n-dim array</param> /// <returns><para>scalar sum of all elements of A.</para> /// <para>If A is empty, an empty array will be returned.</para></returns> /// <exception cref="ILNumerics.Exceptions.ILArgumentException">if A was null.</exception> /// <seealso cref="ILNumerics.BuiltInFunctions.ILMath.sum(ILArray<double>)"/> public static ILArray<Int64> sumall ( ILArray<Int64> A) { if (object.Equals(A,null)) throw new ILArgumentException("sumall: argument must not be null!"); if (A.IsEmpty) { return ILArray<Int64> .empty(0,0); } Int64 retArr = 0 ; if (A.m_indexOffset == null) { unsafe { fixed ( Int64 * inArrStart = A.m_data) { Int64 * inArrWalk = inArrStart; Int64 * inArrEnd = inArrStart + A.Dimensions.NumberOfElements; while (inArrWalk < inArrEnd) { retArr += *inArrWalk++; } } } } else { unsafe { fixed ( Int64 * inArrStart = A.m_data) { for (int i = A.Dimensions.NumberOfElements; i -->0;) { retArr += *(inArrStart + A.getBaseIndex(i)); } } } } return new ILArray<Int64> (new Int64 [1]{retArr},1,1); }
public static unsafe int CallArrayDoubleArrayDouble(DataStructure *data) { if (data->printf_fct != null) { return(CaptureStdOutput(CallArrayDoubleArrayDouble, data)); } CallArrayDoubleArrayDoubleIO *input = (CallArrayDoubleArrayDoubleIO *)data->inputs; var vec = new double[input->nb]; double *src = (double *)input->p; for (int i = 0; i < vec.Length; ++i) { vec[i] = src[i]; } Int64 *p_fct = (Int64 *)data->exc; var fctref = ObjectStorage.Inst.Get(*p_fct); var fct = fctref.MethodInfo; var cs_output = fct.Invoke(null, new object[] { vec }) as double[]; CallArrayDoubleArrayDoubleIO *output = (CallArrayDoubleArrayDoubleIO *)data->outputs; output->nb = cs_output.Length; if (cs_output.Length > 0) { NativeAllocation allocate = MarshalDelegate <NativeAllocation>(data->allocate_fct); int size = cs_output.Length * sizeof(double); allocate(size, out output->p); Marshal.Copy(cs_output, 0, (IntPtr)output->p, cs_output.Length); } return(0); }
/// <summary> /// convert numerical ILArray to single precision floating point precision /// </summary> /// <param name="X">numeric input array</param> /// <returns><![CDATA[ILArray<float>]]> of same size as X having all elements converted to /// single precision floating point format.</returns> /// <remarks>All overloads of this function will return a solid physical copy /// of the input array X.</remarks> public static ILArray <float> single(ILArray <Int64> X) { int nrX = X.m_dimensions.NumberOfElements; float [] retArr = new float [nrX]; ILArray <float> ret = new ILArray <float> (retArr, X.m_dimensions); unsafe { fixed(float *outArr = ret.m_data) fixed(Int64 * inArr = X.m_data) { float *lastElementAfter = outArr + nrX; float *outArrP = outArr; Int64 *inArrP = inArr; while (outArrP < lastElementAfter) { *outArrP++ = (float)*inArrP++; } } } return(ret); }
public static unsafe void AsBgra(Int64 *val, out BGRA left, out BGRA right) { UInt32 *ptr = (UInt32 *)val; left = *ptr; right = *(++ptr); }
public TestProducer() { Shared = Marshal.AllocCoTaskMem(TotalSize); //pm = Shared; unsafe { pu = (Int64 *)Shared.ToPointer(); } unsafe { ps = (Int64 *)Shared.ToPointer(); } }
public static void MemSet([NotNull] this byte[] array, byte value) { if (array == null) { throw new ArgumentNullException("array"); } byte[] rawValue = new[] { value, value, value, value, value, value, value, value }; Int64 fillValue = BitConverter.ToInt64(rawValue, 0); fixed(byte *ptr = array) { Int64 *dest = (Int64 *)ptr; int length = array.Length; while (length >= 8) { *dest = fillValue; dest++; length -= 8; } byte *bDest = (byte *)dest; for (byte i = 0; i < length; i++) { *bDest = value; bDest++; } } }
/// <summary> /// Liefert den Wert (und neuen Offset) von der angegebenen Stelle im Byte-Array. /// </summary> /// <param name="Array"></param> /// <param name="Offset">Position, ab der gelesen wird.</param> unsafe static public (Int64, Int32) CopyInt64Offset(this byte [] Array, Int32 Offset) { fixed(byte *ptr = Array) { Int64 *vpInt64 = (Int64 *)(ptr + Offset); return(*vpInt64, Offset + sizeof(Int64)); } }
/// <summary> /// Liefert den Wert von der angegebenen Stelle im Byte-Array. /// </summary> /// <param name="Array"></param> /// <param name="Offset"></param> unsafe static public Int64 CopyInt64(this byte [] Array, Int32 Offset) { fixed(byte *ptr = Array) { Int64 *vpInt64 = (Int64 *)(ptr + Offset); return(*vpInt64); } }
/// <summary> /// Kopiert die Werte einzeln via *ptr++. /// </summary> /// <param name="Source"></param> /// <param name="Target"></param> /// <param name="Length"></param> unsafe static public void CopyInt64s(Int64 *Source, Int64 *Target, int Length) { for (int i = 0; i < Length; i++) { *Target = *Source; // Source++; Target++; } }
public static unsafe Int64 SpanSpanCopyEx(Span <byte> span) { // Span to span copy with unsafe cast to span Int64 *b = stackalloc Int64[1]; var s = new Span <byte>((void *)b, sizeof(Int64)); span.Slice(0, sizeof(long)).CopyTo(s); return(b[0]); }
/// <summary> /// Kopiert den Wert an die angegebene Stelle in das Byte-Array. /// </summary> /// <param name="Array"></param> /// <param name="Offset">Position, ab der geschrieben wird. Erhöht sich um die Anzhal der gelesenen Bytes!</param> /// <param name="Value"></param> unsafe static public void CopyInt64(this byte [] Array, ref Int32 Offset, Int64 Value) { fixed(byte *ptr = Array) { Int64 *vp = (Int64 *)(ptr + Offset); *vp = Value; Offset += sizeof(Int64); } }
/// <summary> /// Liefert die Bytes ab der Stelle <paramref name="Offset"/> als Wert. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="Array"></param> /// <param name="Offset">Position, ab der gelesen wird. Erhöht sich um die Anzhal der gelesenen Bytes!</param> /// <returns></returns> unsafe static public dynamic CopyValue <T> (this byte [] Array, ref Int32 Offset) where T : unmanaged { try { fixed(byte *ptr = Array) { switch (Type.GetTypeCode(typeof(T))) { case TypeCode.SByte: SByte *vpSByte = (SByte *)(ptr + Offset); return(*vpSByte); case TypeCode.Byte: Byte *vpByte = (Byte *)(ptr + Offset); return(*vpByte); case TypeCode.Int16: Int16 *vpInt16 = (Int16 *)(ptr + Offset); return(*vpInt16); case TypeCode.UInt16: UInt16 *vpUInt16 = (UInt16 *)(ptr + Offset); return(*vpUInt16); case TypeCode.Int32: Int32 *vpInt32 = (Int32 *)(ptr + Offset); return(*vpInt32); case TypeCode.UInt32: UInt32 *vpUInt32 = (UInt32 *)(ptr + Offset); return(*vpUInt32); case TypeCode.Int64: Int64 *vpInt64 = (Int64 *)(ptr + Offset); return(*vpInt64); case TypeCode.UInt64: UInt64 *vpUInt64 = (UInt64 *)(ptr + Offset); return(*vpUInt64); case TypeCode.Char: Char *vpChar = (Char *)(ptr + Offset); return(*vpChar); case TypeCode.Boolean: Boolean *vpBoolean = (Boolean *)(ptr + Offset); return(*vpBoolean); } } } finally { Offset += sizeof(T); } throw new Exception("Not implemented!"); }
/// <summary> /// maximum for all elements of A /// </summary> /// <param name="A">n-dim array</param> /// <returns><para>scalar maximum of all elements for A.</para> /// <para>If A is empty, an empty array will be returned.</para></returns> /// <exception cref="ILNumerics.Exceptions.ILArgumentException">if A was null.</exception> /// <seealso cref="ILNumerics.BuiltInFunctions.ILMath.max(ILArray<double>)"/> public static ILArray <Int64> maxall(ILArray <Int64> A) { if (object.Equals(A, null)) { throw new ILArgumentException("maxall: argument must not be null!"); } if (A.IsEmpty) { return(ILArray <Int64> .empty(0, 0)); } Int64 retArr = Int64.MinValue; if (A.m_indexOffset == null) { unsafe { fixed(Int64 *inArrStart = A.m_data) { Int64 *inArrWalk = inArrStart; Int64 *inArrEnd = inArrStart + A.Dimensions.NumberOfElements; while (inArrWalk < inArrEnd) { if (retArr < *inArrWalk) { retArr = *inArrWalk; } inArrWalk++; } } } } else { Int64 tmp; unsafe { fixed(Int64 *inArrStart = A.m_data) { for (int i = A.Dimensions.NumberOfElements; i-- > 0;) { tmp = *(inArrStart + A.getBaseIndex(i)); if (retArr < tmp) { retArr = tmp; } } } } } return(new ILArray <Int64> (new Int64 [1] { retArr }, 1, 1)); }
public unsafe Int64 SumAndSwitch(Int64 *int64PtrX, Int64 *int64PtrY) { Int64 sum = *int64PtrX + *int64PtrY; Int64 temp = *int64PtrX; *int64PtrX = *int64PtrY; *int64PtrY = temp; return(sum); }
public static byte[] ImageDetails(string name) { var osr = OpenSlideInterface.Openslide_open(name); if (osr == IntPtr.Zero) { return(null); } var vendor = Marshal.PtrToStringAnsi(OpenSlideInterface.Openslide_detect_vendor(name)); var levels = OpenSlideInterface.Openslide_get_level_count(osr); var widths = new Int64[levels]; var heights = new Int64[levels]; var dimensions = "[\r\n\t\t"; var offset = LoadText(name + ".txt"); if (offset == null) { offset = "\"0,0\""; } unsafe { Int64 w, h; Int64 *pw = &w; Int64 *ph = &h; for (var l = 0; l < levels; l++) { OpenSlideInterface.Openslide_get_level_dimensions(osr, l, pw, ph); widths[l] = w; heights[l] = h; dimensions += "\"" + l.ToString() + "," + w.ToString() + "," + h.ToString() + "\"" + ((l < levels - 1) ? ",\r\n\t\t" : ""); } } dimensions += "\r\n\t]"; OpenSlideInterface.Openslide_close(osr); var json = "{\r\n\t\"Name\":\"" + Path.GetFileName(name) + "\", \r\n\t\"Vendor\":\"" + vendor + "\", \r\n\t\"Levels\":" + levels.ToString() + ", \r\n\t\"Width\":" + widths[0].ToString() + ", \r\n\t\"Height\":" + heights[0].ToString() + ", \r\n\t\"Dimensions\":" + dimensions + ", \r\n\t\"Offset\":" + offset + "\r\n}"; return(Encoding.ASCII.GetBytes(json)); }
/// <summary> /// Kopiert den Wert an die angegebene Stelle in das Byte-Array und liefert den neuen Offset zurück. /// </summary> /// <param name="Array"></param> /// <param name="Offset"></param> /// <param name="Value"></param> /// <returns>Liefert den neuen Offset.</returns> unsafe static public Int32 CopyInt64(this byte [] Array, Int32 Offset, Int64 Value) { fixed(byte *ptr = Array) { Int64 *vp = (Int64 *)(ptr + Offset); *vp = Value; } return(Offset + sizeof(Int64)); }
public static Int64 ToInt64(byte[] bytes, int offset = 0) { unsafe { fixed(byte *ptr = &bytes[offset]) { Int64 *primitivePtr = (Int64 *)ptr; return(*primitivePtr); } } }
public static void GetBytes(Int64 primitive, byte[] bytes, int offset = 0) { unsafe { fixed(byte *ptr = &bytes[offset]) { Int64 *primitivePtr = (Int64 *)ptr; *primitivePtr = primitive; } } }
public static unsafe int CallVoid(DataStructure *data) { if (data->printf_fct != null) { return(CaptureStdOutput(CallVoid, data)); } Int64 *p_fct = (Int64 *)data->exc; var fctref = ObjectStorage.Inst.Get(*p_fct); var fct = fctref.MethodInfo; fct.Invoke(null, null); return(0); }
public unsafe static DLManagedTensor FromBlob<T>(T* data, Int32 ndim, Int64* shape, Int64* strides = null) where T : unmanaged { var dl_managed_tensor = new DLManagedTensor(); dl_managed_tensor.dl_tensor.data = (IntPtr)data; dl_managed_tensor.dl_tensor.ctx.device_type = DLDeviceType.kDLCPU; dl_managed_tensor.dl_tensor.ndim = ndim; dl_managed_tensor.dl_tensor.dtype = DLDataType.From<T>(); dl_managed_tensor.dl_tensor.shape = (IntPtr)shape; dl_managed_tensor.dl_tensor.strides = (IntPtr)strides; dl_managed_tensor.dl_tensor.byte_offset = 0; dl_managed_tensor.deleter = EmptyDeleter; return dl_managed_tensor; }
public static Int64 ToInt64(byte[] bytes, ref int offset) { unsafe { fixed(byte *ptr = &bytes[offset]) { offset += sizeof(Int64); Int64 *primitivePtr = (Int64 *)ptr; return(*primitivePtr); } } }
public static void GetBytes(Int64 primitive, byte[] bytes, ref int offset) { unsafe { fixed(byte *ptr = &bytes[offset]) { offset += sizeof(Int64); Int64 *primitivePtr = (Int64 *)ptr; *primitivePtr = primitive; } } }
// загрузка exl файла unsafe private bool LoadExcel(string FileName) { // открываем документ, надеемся что он структурирован этим же конвертором xD excelapp = new Excel.Application(); //excelapp.Visible = true; Excel.Workbook excelappworkbook = excelapp.Workbooks.Open(FileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); // получаем страницы книги excelsheets = excelappworkbook.Worksheets; // сворачиваем для увеличения скорости excelsheets.Application.WindowState = Excel.XlWindowState.xlMinimized; excelsheets.Application.Visible = false; for (int i = 0; i < ITEM_MAX_TYPES; i++) { // поехали по страницам книги excelworksheet = (Excel.Worksheet)excelsheets.get_Item(i + 1); excelworksheet.Activate(); progressBar3.Value = i; for (int j = 0; j < ITEM_MAX_IN_TYPE; j++) { // поехали по строкам progressBar2.Value = j; // считываем имя excelcells = (Excel.Range)excelworksheet.Cells[j + 3, 3]; Items[i, j].ItemName = Convert.ToString(excelcells.Value2); // считываем остальные ячейки fixed(Int64 *buff2 = Items[i, j].Numbers) { excelcells = excelworksheet.get_Range(ColumnTempName[3] + Convert.ToString(j + 3), ColumnTempName[3 + MyItemColumns.Length - 1] + Convert.ToString(j + 3)); System.Array SomeNumbers = excelcells.Value2 as System.Array; int k = 0; foreach (Object Number in SomeNumbers) { Int64 *buff = buff2 + k; * buff = Convert.ToInt64(Number); k++; } } } } excelapp.Quit(); return(true); }
/// <summary> /// Liefert den Wert von der angegebenen Stelle im Byte-Array. /// </summary> /// <param name="Array"></param> /// <param name="Offset">Position, ab der geschrieben wird. Erhöht sich um die Anzhal der gelesenen Bytes!</param> unsafe static public Int64 CopyInt64(this byte [] Array, ref Int32 Offset) { try { fixed(byte *ptr = Array) { Int64 *vpInt64 = (Int64 *)(ptr + Offset); return(*vpInt64); } } finally { Offset += sizeof(Int64); } }
/// <summary> /// invert elements of A, return result as out argument /// </summary> /// <param name="A"></param> /// <param name="outArray"></param> public static void invert(ILArray <Int64> A, ILArray <Int64> outArray) { #region array + array ILDimension inDim = A.Dimensions; if (!inDim.IsSameSize(outArray.Dimensions)) { throw new ILDimensionMismatchException(); } int leadDim = 0, leadDimLen = inDim [0]; // walk along the longest dimension (for performance reasons) for (int i = 1; i < inDim.NumberOfDimensions; i++) { if (leadDimLen < inDim [i]) { leadDimLen = inDim [i]; leadDim = i; } } unsafe { fixed(Int64 *inA1 = A.m_data) fixed(Int64 * inA2 = outArray.m_data) { Int64 *pInA1 = inA1; Int64 *pInA2 = inA2; int c = 0; Int64 *outEnd = inA2 + outArray.m_data.Length; if (A.IsReference) { while (pInA2 < outEnd) //HC07 { *pInA2++ = (*(pInA1 + A.getBaseIndex(c++)) * (-1)); } } else { while (pInA2 < outEnd) //HC11 { *pInA2++ = (*pInA1++ /*HC:*/ *(-1)); } } } #endregion array + array } return; }
Int64 _GetMarshalTestInt64Value(byte ofs, out byte[] data) { IntPtr mem = Marshal.AllocCoTaskMem(8); data = new byte[8]; for (byte i = 0; i < data.Length; i++) { Marshal.WriteByte((IntPtr)(mem.ToInt64() + i), data[i] = (byte)(ofs + i)); } Int64 *_val = (Int64 *)mem; Int64 result = *_val; Marshal.FreeCoTaskMem(mem); return(result); }
unsafe internal CounterData(Int64 * pCounterData) { m_offset = pCounterData; * m_offset = 0; }