forked from Craigacp/MIToolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArrayOperations.h
84 lines (72 loc) · 3.79 KB
/
ArrayOperations.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*******************************************************************************
** ArrayOperations.h
** Part of the mutual information toolbox
**
** Contains functions to floor arrays, and to merge arrays into a joint
** state.
**
** Author: Adam Pocock
** Created 17/2/2010
** Updated - 22/02/2014 - Added checking on calloc, and an increment array function.
**
** Copyright 2010,2014 Adam Pocock, The University Of Manchester
** www.cs.manchester.ac.uk
**
** This file is part of MIToolbox, licensed under the 3-clause BSD license.
*******************************************************************************/
#ifndef __ArrayOperations_H
#define __ArrayOperations_H
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
** A version of calloc which checks to see if memory was allocated.
*******************************************************************************/
void* checkedCalloc(size_t vectorLength, size_t sizeOfType);
/*******************************************************************************
** Increments each value in a double array
*******************************************************************************/
void incrementVector(double* vector, int vectorLength);
/*******************************************************************************
** Simple print functions for debugging
*******************************************************************************/
void printDoubleVector(double *vector, int vectorlength);
void printIntVector(int *vector, int vectorLength);
/*******************************************************************************
** numberOfUniqueValues finds the number of unique values in an array by
** repeatedly iterating through the array and checking if a value has been
** seen previously
*******************************************************************************/
int numberOfUniqueValues(double *featureVector, int vectorLength);
/*******************************************************************************
** normaliseArray takes an input vector and writes an output vector
** which is a normalised version of the input, and returns the number of states
** A normalised array has min value = 0, max value = number of states
** and all values are integers
**
** length(inputVector) == length(outputVector) == vectorLength otherwise there
** is a memory leak
*******************************************************************************/
int normaliseArray(double *inputVector, int *outputVector, int vectorLength);
/*******************************************************************************
** mergeArrays takes in two arrays and writes the joint state of those arrays
** to the output vector
**
** the length of the vectors must be the same and equal to vectorLength
*******************************************************************************/
int mergeArrays(double *firstVector, double *secondVector, double *outputVector, int vectorLength);
int mergeArraysArities(double *firstVector, int numFirstStates, double *secondVector, int numSecondStates, double *outputVector, int vectorLength);
/*******************************************************************************
** mergeMultipleArrays takes in a matrix and repeatedly merges the matrix using
** merge arrays and writes the joint state of that matrix
** to the output vector
**
** the length of the vectors must be the same and equal to vectorLength
** matrixWidth = the number of columns in the matrix
*******************************************************************************/
int mergeMultipleArrays(double *inputMatrix, double *outputVector, int matrixWidth, int vectorLength);
int mergeMultipleArraysArities(double *inputMatrix, double *outputVector, int matrixWidth, int *arities, int vectorLength);
#ifdef __cplusplus
}
#endif
#endif