#include "mx-base.h"
#include "defun-dld.h"
#include "error.h"
#include "gripes.h"
#include "oct-obj.h"
#include "unwind-prot.h"
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) |
DEFUN_DLD | ( | typecast | , | |
args | ||||
) |
Definition at line 89 of file typecast.cc.
References octave_value::array_value(), octave_value::bool_array_value(), octave_value::char_array_value(), octave_value::class_name(), octave_value::complex_array_value(), error(), error_state, octave_value::float_array_value(), octave_value::float_complex_array_value(), get_data_and_bytesize(), octave_value::int16_array_value(), octave_value::int32_array_value(), octave_value::int64_array_value(), octave_value::int8_array_value(), octave_value::is_bool_type(), octave_value::is_complex_type(), octave_value::is_dq_string(), octave_value::is_int16_type(), octave_value::is_int32_type(), octave_value::is_int64_type(), octave_value::is_int8_type(), octave_value::is_integer_type(), octave_value::is_real_type(), octave_value::is_single_type(), octave_value::is_string(), octave_value::is_uint16_type(), octave_value::is_uint32_type(), octave_value::is_uint64_type(), octave_value::is_uint8_type(), octave_value::is_undefined(), octave_value(), print_usage(), octave_value::uint16_array_value(), octave_value::uint32_array_value(), octave_value::uint64_array_value(), and octave_value::uint8_array_value().
DEFUN_DLD | ( | bitunpack | , | |
args | ||||
) |
Definition at line 383 of file typecast.cc.
References octave_value::array_value(), octave_value::char_array_value(), octave_value::class_name(), octave_value::complex_array_value(), do_bitunpack(), error(), octave_value::float_array_value(), octave_value::float_complex_array_value(), octave_value::int16_array_value(), octave_value::int32_array_value(), octave_value::int64_array_value(), octave_value::int8_array_value(), octave_value::is_complex_type(), octave_value::is_int16_type(), octave_value::is_int32_type(), octave_value::is_int64_type(), octave_value::is_int8_type(), octave_value::is_integer_type(), octave_value::is_real_type(), octave_value::is_single_type(), octave_value::is_string(), octave_value::is_uint16_type(), octave_value::is_uint32_type(), octave_value::is_uint64_type(), octave_value::is_uint8_type(), print_usage(), octave_value::uint16_array_value(), octave_value::uint32_array_value(), octave_value::uint64_array_value(), and octave_value::uint8_array_value().
DEFUN_DLD | ( | bitpack | , | |
args | ||||
) |
Definition at line 274 of file typecast.cc.
References error(), error_state, octave_value::is_undefined(), octave_value(), and print_usage().
ArrayType do_bitpack | ( | const boolNDArray & | bitp | ) |
Definition at line 240 of file typecast.cc.
References Array< T >::dims(), error(), Array< T >::fortran_vec(), get_vec_dims(), and Array< T >::numel().
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().
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().
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().