LibraryLink`
LibraryLink`

MNumericArray_convertType (C Function)

errcode_t MNumericArray_convertType(MNumericArray* out, const MNumericArray na,const numericarray_data_t type, const numericarray_convert_method_t method, const mreal tol)

is a library callback function that converts the data type of an MNumericArray.

Details

  • Used in C/C++ code in a library function called from the Wolfram Language.
  • Converts the data type of MNumericArray object.
  • A nonzero error code value will be returned if type, method or tol arguments are incorrect or if there is not sufficient memory.
  • The destination should either be null (0) or an MNumericArray allocated with MNumericArray_new.
  • If is null, then the result will be allocated.
  • If is an allocated MNumericArray with appropriate type and dimensions, then the data in *out will be modified.
  • Possible settings for type include:
  • MNumericArray_Type_Bit8"Integer8"signed 8-bit integers from through
    MNumericArray_Type_UBit8"UnsignedInteger8"integers 0 through 255
    MNumericArray_Type_Bit16"Integer16"signed 16-bit integers from through
    MNumericArray_Type_UBit16"UnsignedInteger16"integers 0 through 65535
    MNumericArray_Type_Bit32"Integer32"signed 32-bit integers from through
    MNumericArray_Type_UBit32"UnsignedInteger32"integers 0 through 2^(32)-1
    MNumericArray_Type_Bit64"Integer64"signed 64-bit integers from through
    MNumericArray_Type_UBit64"UnsignedInteger64"integers 0 through 2^(64)-1
    MNumericArray_Type_Real32"Real32"single-precision reals (32-bit)
    MNumericArray_Type_Real64"Real64"double-precision reals (64-bit)
    MNumericArray_Type_Complex_Real32"ComplexReal32"single-precision complex numbers
    MNumericArray_Type_Complex_Real64"ComplexReal64"double-precision complex numbers
  • Possible settings for method include:
  • MNumericArray_Convert_Check"Check"checks values to be compatible with type
    MNumericArray_Convert_Coerce"Coerce"coerces to type
    MNumericArray_Convert_Round"Round"rounds reals to integers
    MNumericArray_Convert_Clip_Check"ClipAndCheck"clips to the range and checks values to be compatible with type
    MNumericArray_Convert_Clip_Coerce"ClipAndCoerce"clips to the range and coerces to type
    MNumericArray_Convert_Clip_Round"ClipAndRound"clips to the range and rounds reals to integers
  • Two nonzero numbers x and y with decimal precision p are considered equal to decimal tolerance tol if TemplateBox[{{x, -, y}}, Abs]<=10^(tol-p) max(TemplateBox[{x}, Abs],TemplateBox[{y}, Abs]).

Examples

Basic Examples  (1)

This converts MNumericArray to MNumericArray_Type_Real32 type using MNumericArray_Convert_Coerce method and tolerance of 1 decimal digit:

MNumericArray A0, A1 = NULL;
...
errcode_t err = libData->numericarrayLibraryFunctions->MNumericArray_convertType(&A1, A0, MNumericArray_Type_Real32, MNumericArray_Convert_Coerce, 1);