Mathematical Structures


Data Structures

struct  psVector
 An vector to support primitive types. More...

Defines

#define P_PSVECTOR_SET_NALLOC(vec, n)   *(long*)&(vec->nalloc) = n
#define PS_ASSERT_VECTOR_NON_NULL(NAME, RVAL)   PS_ASSERT_GENERAL_VECTOR_NON_NULL(NAME, return RVAL)
#define PS_ASSERT_GENERAL_VECTOR_NON_NULL(NAME, CLEANUP)
#define PS_ASSERT_VECTOR_NON_EMPTY(NAME, RVAL)   PS_ASSERT_GENERAL_VECTOR_NON_EMPTY(NAME, return RVAL)
#define PS_ASSERT_GENERAL_VECTOR_NON_EMPTY(NAME, CLEANUP)
#define PS_ASSERT_VECTOR_TYPE_F32_OR_F64(NAME, RVAL)
#define PS_ASSERT_VECTOR_TYPE_S16_S32_F32(NAME, RVAL)
#define PS_ASSERT_VECTOR_TYPE(NAME, TYPE, RVAL)
#define PS_ASSERT_VECTORS_SIZE_EQUAL(VEC1, VEC2, RVAL)
#define PS_ASSERT_VECTOR_SIZE(VEC, SIZE, RVAL)
#define PS_ASSERT_VECTOR_TYPE_EQUAL(VEC1, VEC2, RVAL)
#define PS_VECTOR_PRINT_F32(NAME)
#define PS_VECTOR_PRINT_F64(NAME)

Functions

bool psMemCheckVector (psPtr ptr)
 Checks the type of a particular pointer.
psVectorpsVectorAlloc (long nalloc, psElemType type)
 Allocate a vector, with length set to number allocated.
psVectorpsVectorAllocEmpty (long nalloc, psElemType type)
 Allocate a vector, with length set to zero.
psVectorpsVectorRealloc (psVector *vector, long nalloc)
 Reallocate a vector.
psVectorpsVectorExtend (psVector *vector, long delta, long nExtend)
 Extend a vector's length.
psVectorpsVectorRecycle (psVector *vector, long nalloc, psElemType type)
 Recycle a vector.
psVectorpsVectorCopy (psVector *output, const psVector *input, psElemType type)
 Copy a vector, converting types.
psVectorpsVectorSort (psVector *outVector, const psVector *inVector)
 Sort an array of floats.
psVectorpsVectorSortIndex (psVector *outVector, const psVector *inVector)
 Creates an array of indices based on sort ordered of array.
psString psVectorToString (const psVector *vector, int maxLength)
 Creates a string from a psVector's values in the form "[x0,x1,x2]".
psF64 p_psVectorGetElementF64 (const psVector *vector, int position)
 Returns an element in the vector as a psF64 value.
bool p_psVectorPrint (int fd, const psVector *a, char *name)
 Print a vector to a stream.
bool psVectorInit (psVector *vector,...)
 Initializes the vector with the given value.
psVectorpsVectorCreate (psVector *input, double lower, double upper, double delta, psElemType type)
 Creates a new vector, or reallocates the provided vector if input is not NULL.
bool psVectorSet (psVector *input, long position, double complex value)
 Sets the value of the input vector at the specified position to value.
double complex psVectorGet (const psVector *input, long position)
 Returns the value of the input vector at the specified position.
long psVectorCountPixelMask (psVector *mask, psMaskType value)
 Returns the number of pixels in the vector which satisfy any of the mask bits.
long psVectorLength (const psVector *vector)
 Get the number of elements in use from a specified psVector.


Define Documentation

#define P_PSVECTOR_SET_NALLOC ( vec,
 )     *(long*)&(vec->nalloc) = n

Definition at line 53 of file psVector.h.

#define PS_ASSERT_GENERAL_VECTOR_NON_EMPTY ( NAME,
CLEANUP   ) 

Value:

if ((NAME)->n < 1) { \
    psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
            "Unallowable operation: psVector %s has no elements.", \
            #NAME); \
    CLEANUP; \
} \

Definition at line 293 of file psVector.h.

#define PS_ASSERT_GENERAL_VECTOR_NON_NULL ( NAME,
CLEANUP   ) 

Value:

if ((NAME) == NULL || (NAME)->data.U8 == NULL) { \
    psError(PS_ERR_BAD_PARAMETER_NULL, true, \
            "Unallowable operation: psVector %s or its data is NULL.", \
            #NAME); \
    CLEANUP; \
} \

Definition at line 284 of file psVector.h.

#define PS_ASSERT_VECTOR_NON_EMPTY ( NAME,
RVAL   )     PS_ASSERT_GENERAL_VECTOR_NON_EMPTY(NAME, return RVAL)

Definition at line 292 of file psVector.h.

#define PS_ASSERT_VECTOR_NON_NULL ( NAME,
RVAL   )     PS_ASSERT_GENERAL_VECTOR_NON_NULL(NAME, return RVAL)

Definition at line 283 of file psVector.h.

#define PS_ASSERT_VECTOR_SIZE ( VEC,
SIZE,
RVAL   ) 

Value:

if ((VEC)->n != (SIZE)) { \
    psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
            "psVector %s has size %ld, should be %ld.", \
            #VEC, (VEC)->n, (SIZE)); \
    return(RVAL); \
}

Definition at line 333 of file psVector.h.

#define PS_ASSERT_VECTOR_TYPE ( NAME,
TYPE,
RVAL   ) 

Value:

if ((NAME)->type.type != TYPE) { \
    psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
            "Unallowable operation: psVector %s has incorrect type.", \
            #NAME); \
    return(RVAL); \
}

Definition at line 317 of file psVector.h.

#define PS_ASSERT_VECTOR_TYPE_EQUAL ( VEC1,
VEC2,
RVAL   ) 

Value:

if ((VEC1)->type.type != (VEC2)->type.type) { \
    psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
            "psVector %s has size %d, psVector %s has size %d.", \
            #VEC1, (VEC1)->type.type, #VEC2, (VEC2)->type.type); \
    return(RVAL); \
}

Definition at line 341 of file psVector.h.

#define PS_ASSERT_VECTOR_TYPE_F32_OR_F64 ( NAME,
RVAL   ) 

Value:

if (((NAME)->type.type != PS_TYPE_F32) && ((NAME)->type.type != PS_TYPE_F64)) { \
    psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
            "psVector %s: bad type(%d)", \
            #NAME, (NAME)->type.type); \
    return(RVAL); \
} \

Definition at line 301 of file psVector.h.

#define PS_ASSERT_VECTOR_TYPE_S16_S32_F32 ( NAME,
RVAL   ) 

Value:

if (((NAME)->type.type != PS_TYPE_S16) && ((NAME)->type.type != PS_TYPE_S32) && ((NAME)->type.type != PS_TYPE_F32)) { \
    psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
            "psVector %s: bad type(%d)", \
            #NAME, (NAME)->type.type); \
    return(RVAL); \
} \

Definition at line 309 of file psVector.h.

#define PS_ASSERT_VECTORS_SIZE_EQUAL ( VEC1,
VEC2,
RVAL   ) 

Value:

if ((VEC1)->n != (VEC2)->n) { \
    psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
            "psVector %s has size %ld, psVector %s has size %ld.", \
            #VEC1, (VEC1)->n, #VEC2, (VEC2)->n); \
    return(RVAL); \
}

Definition at line 325 of file psVector.h.

#define PS_VECTOR_PRINT_F32 ( NAME   ) 

Value:

if ((NAME) != NULL) { \
    for (int i = 0; i < (NAME)->n; i++) { \
        printf("%s->data.F32[%d] is %f\n", #NAME, i, (NAME)->data.F32[i]); \
    } \
    printf("\n"); \
} else {\
    printf("MACRO WARNING: vector %s is NULL.\n", #NAME); \
}\

Definition at line 349 of file psVector.h.

#define PS_VECTOR_PRINT_F64 ( NAME   ) 

Value:

if ((NAME) != NULL) { \
    for (int i = 0; i < (NAME)->n; i++) { \
        printf("%s->data.F64[%d] is %f\n", #NAME, i, (NAME)->data.F64[i]); \
    } \
    printf("\n"); \
} else {\
    printf("MACRO WARNING: vector %s is NULL.\n", #NAME); \
}\

Definition at line 359 of file psVector.h.


Function Documentation

psF64 p_psVectorGetElementF64 ( const psVector vector,
int  position 
)

Returns an element in the vector as a psF64 value.

Returns:
psF64 the value at specified position, or NAN if position is invalid.
Parameters:
vector  vector to retrieve element
position  the vector position to get

bool p_psVectorPrint ( int  fd,
const psVector a,
char *  name 
)

Print a vector to a stream.

Returns:
psBool TRUE is successful, otherwise FALSE.
Parameters:
fd  output file descriptor
a  vector to print
name  name of vector (for title)

bool psMemCheckVector ( psPtr  ptr  ) 

Checks the type of a particular pointer.

Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.

Returns:
bool: True if the pointer matches a psVector structure, false otherwise.
Parameters:
ptr  the pointer whose type to check

psVector* psVectorAlloc ( long  nalloc,
psElemType  type 
)

Allocate a vector, with length set to number allocated.

Uses psLib memory allocation functions to create a vector collection of data as defined by the psType type.

Returns:
psVector* Pointer to psVector.
Parameters:
nalloc  Total number of elements to make available.
type  Type of data to be held by vector.

psVector* psVectorAllocEmpty ( long  nalloc,
psElemType  type 
)

Allocate a vector, with length set to zero.

Uses psLib memory allocation functions to create a vector collection of data as defined by the psType type.

Returns:
psVector* Pointer to psVector.
Parameters:
nalloc  Total number of elements to make available.
type  Type of data to be held by vector.

psVector* psVectorCopy ( psVector output,
const psVector input,
psElemType  type 
)

Copy a vector, converting types.

Performs a deep copy of the elements of one psVector to a new psVector, converting numeric types to a specified type.

Returns:
psVector* Pointer to resulting psVector.
Parameters:
output  if non-NULL, a psVector to recycle
input  the vector to copy.
type  the data type of the resulting psVector

long psVectorCountPixelMask ( psVector mask,
psMaskType  value 
)

Returns the number of pixels in the vector which satisfy any of the mask bits.

An error (eg, invalid vector) results in a return value of -1. The vector must be U8.

Returns:
long: the number of pixels counted
Parameters:
mask  input vector to count
value  the mask value to satisfy

psVector* psVectorCreate ( psVector input,
double  lower,
double  upper,
double  delta,
psElemType  type 
)

Creates a new vector, or reallocates the provided vector if input is not NULL.

The created vector consists of the data range starting at lower, running to upper, in steps of delta. The upper-end value is exclusive; the sequence is equivalent to for (x = lower; x <= upper - 1; x += delta).

Returns:
psVector*: the newly created psVector
Parameters:
input  Input vector
lower  lower bound
upper  upper bound
delta  size of increment
type  type of vector to create

psVector* psVectorExtend ( psVector vector,
long  delta,
long  nExtend 
)

Extend a vector's length.

Increments a vector's length, n, by the specified number of elements. If the allocated storage is less than the current vector's length plus twice the number of elements to be added, it is reallocated larger by a given amount.

Returns:
psVector* Pointer to the adjusted psVector
Parameters:
vector  Vector to extend
delta  Amount to expand allocation, if necessary
nExtend  Number of elements to add to vector length

double complex psVectorGet ( const psVector input,
long  position 
)

Returns the value of the input vector at the specified position.

A negative position means index from the end.

Returns:
complex: Value of the input vector at the specified position.
Parameters:
input  Input vector from which to get value
position  vector position

bool psVectorInit ( psVector vector,
  ... 
)

Initializes the vector with the given value.

The input data is cast to match the vector datatype, allowing for integers to be preserved.

Returns:
bool: True if successful, otherwise false.
Parameters:
vector  the vector to be initialized

long psVectorLength ( const psVector vector  ) 

Get the number of elements in use from a specified psVector.

(vector.n)

Returns:
long: The number of elements in use.
Parameters:
vector  input psVector

psVector* psVectorRealloc ( psVector vector,
long  nalloc 
)

Reallocate a vector.

Uses psLib memory allocation functions to reallocate a vector collection of data. The vector is reallocated according to the psType type member contained within the vector.

Returns:
psVector* Pointer to psVector.
Parameters:
vector  Vector to reallocate.
nalloc  Total number of elements to make available.

psVector* psVectorRecycle ( psVector vector,
long  nalloc,
psElemType  type 
)

Recycle a vector.

Uses psLib memory allocation functions to reallocate a vector collection of data. The vector is reallocated according to the psElemType type parameter.

Returns:
psVector* Pointer to psVector.
Parameters:
vector  Vector to recycle. If NULL, a new vector is created. No effort taken to preserve the values.
nalloc  Total number of elements to make available.
type  the datatype of the returned vector

bool psVectorSet ( psVector input,
long  position,
double complex  value 
)

Sets the value of the input vector at the specified position to value.

A negative position means index from the end.

Returns:
bool: True if successful, otherwise false.
Parameters:
input  Input vector to set
position  vector position
value  value to set

psVector* psVectorSort ( psVector outVector,
const psVector inVector 
)

Sort an array of floats.

Sorts an array of floats in ascending order. This function is valid for all non-complex data types.

Returns:
psVector* Pointer to sorted psVector.
Parameters:
outVector  the output vector to recycle, or NULL if new vector desired.
inVector  the vector to sort.

psVector* psVectorSortIndex ( psVector outVector,
const psVector inVector 
)

Creates an array of indices based on sort ordered of array.

Sorts a vector and creates an integer array holding indices of sorted float values based on pre-sort index positions.

Returns:
psVector* vector of the indices of sort.
Parameters:
outVector  vector to recycle
inVector  vector to sort

psString psVectorToString ( const psVector vector,
int  maxLength 
)

Creates a string from a psVector's values in the form "[x0,x1,x2]".

Returns:
psPtr a newly allocated string
Parameters:
vector  vector to create a string from
maxLength  the maximum length of the resulting string


Generated on Fri Feb 2 22:25:49 2007 for pslib by  doxygen 1.5.1