Functions

typecast.cc File Reference

#include "mx-base.h"
#include "defun-dld.h"
#include "error.h"
#include "gripes.h"
#include "oct-obj.h"
#include "unwind-prot.h"
Include dependency graph for typecast.cc:

Go to the source code of this file.

Functions

 DEFUN_DLD (typecast, args,,"-*- texinfo -*-\n\ @deftypefn {Loadable Function} {} typecast (@var{x}, @var{class})\n\ Return a new array @var{y} resulting from interpreting the data of\n\ @var{x} in memory as data of the numeric class @var{class}. Both the class\n\ of @var{x} and @var{class} must be one of the built-in numeric classes:\n\ \n\ @example\n\ @group\n\ \"logical\"\n\ \"char\"\n\ \"int8\"\n\ \"int16\"\n\ \"int32\"\n\ \"int64\"\n\ \"uint8\"\n\ \"uint16\"\n\ \"uint32\"\n\ \"uint64\"\n\ \"double\"\n\ \"single\"\n\ \"double complex\"\n\ \"single complex\"\n\ @end group\n\ @end example\n\ \n\ @noindent\n\ the last two are reserved for @var{class}; they indicate that a\n\ complex-valued result is requested. Complex arrays are stored in memory as\n\ consecutive pairs of real numbers. The sizes of integer types are given by\n\ their bit counts. Both logical and char are typically one byte wide;\n\ however, this is not guaranteed by C++. If your system is IEEE conformant,\n\ single and double should be 4 bytes and 8 bytes wide, respectively.\n\ \"logical\" is not allowed for @var{class}. If the input is a row vector,\n\ the return value is a row vector, otherwise it is a column vector. If the\n\ bit length of @var{x} is not divisible by that of @var{class}, an error\n\ occurs.\n\ \n\ An example of the use of typecast on a little-endian machine is\n\ \n\ @example\n\ @group\n\ @var{x} = uint16 ([1, 65535]);\n\ typecast (@var{x}, 'uint8')\n\ @result{} [ 1, 0, 255, 255]\n\ @end group\n\ @end example\n\ @seealso{cast, bitunpack, bitpack, swapbytes}\n\ @end deftypefn")
 DEFUN_DLD (bitunpack, args,,"-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{y} =} bitunpack (@var{x})\n\ Return an array @var{y} corresponding to the raw bit patterns of\n\ @var{x}. @var{x} must belong to one of the built-in numeric classes:\n\ \n\ @example\n\ @group\n\ \"char\"\n\ \"int8\"\n\ \"int16\"\n\ \"int32\"\n\ \"int64\"\n\ \"uint8\"\n\ \"uint16\"\n\ \"uint32\"\n\ \"uint64\"\n\ \"double\"\n\ \"single\"\n\ @end group\n\ @end example\n\ \n\ The result is a row vector if @var{x} is a row vector; otherwise, it is a\n\ column vector.\n\ @seealso{bitpack, typecast}\n\ @end deftypefn")
 DEFUN_DLD (bitpack, args,,"-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{y} =} bitpack (@var{x}, @var{class})\n\ Return a new array @var{y} resulting from interpreting an array\n\ @var{x} as raw bit patterns for data of the numeric class @var{class}.\n\ @var{class} must be one of the built-in numeric classes:\n\ \n\ @example\n\ @group\n\ \"char\"\n\ \"int8\"\n\ \"int16\"\n\ \"int32\"\n\ \"int64\"\n\ \"uint8\"\n\ \"uint16\"\n\ \"uint32\"\n\ \"uint64\"\n\ \"double\"\n\ \"single\"\n\ @end group\n\ @end example\n\ \n\ The number of elements of @var{x} should be divisible by the bit length of\n\ @var{class}. If it is not, excess bits are discarded. Bits come in\n\ increasing order of significance, i.e., @code{x(1)} is bit 0, @code{x(2)} is\n\ bit 1, etc. The result is a row vector if @var{x} is a row vector, otherwise\n\ it is a column vector.\n\ @seealso{bitunpack, typecast}\n\ @end deftypefn")
template<class ArrayType >
ArrayType do_bitpack (const boolNDArray &bitp)
template<class ArrayType >
boolNDArray do_bitunpack (const ArrayType &array)
template<class ArrayType >
static void get_data_and_bytesize (const ArrayType &array, const void *&data, octave_idx_type &byte_size, dim_vector &old_dims, unwind_protect &frame)
static dim_vector get_vec_dims (const dim_vector &old_dims, octave_idx_type n)
template<class ArrayType >
static ArrayType reinterpret_copy (const void *data, octave_idx_type byte_size, const dim_vector &old_dims)

Function Documentation

DEFUN_DLD ( typecast  ,
args   
)
DEFUN_DLD ( bitunpack  ,
args   
)
DEFUN_DLD ( bitpack  ,
args   
)
template<class ArrayType >
ArrayType do_bitpack ( const boolNDArray bitp  ) 
template<class ArrayType >
boolNDArray do_bitunpack ( const ArrayType &  array  ) 

Definition at line 359 of file typecast.cc.

References Array< T >::fortran_vec(), get_vec_dims(), and Array< T >::numel().

Referenced by DEFUN_DLD().

template<class ArrayType >
static void get_data_and_bytesize ( const ArrayType &  array,
const void *&  data,
octave_idx_type byte_size,
dim_vector old_dims,
unwind_protect frame 
) [static]

Definition at line 49 of file typecast.cc.

References unwind_protect::add_delete().

Referenced by DEFUN_DLD().

static dim_vector get_vec_dims ( const dim_vector old_dims,
octave_idx_type  n 
) [static]

Definition at line 37 of file typecast.cc.

References dim_vector::length().

Referenced by do_bitpack(), do_bitunpack(), and reinterpret_copy().

template<class ArrayType >
static ArrayType reinterpret_copy ( const void *  data,
octave_idx_type  byte_size,
const dim_vector old_dims 
) [static]

Definition at line 67 of file typecast.cc.

References error(), and get_vec_dims().

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines