streaming_algorithms  0.0.5
A collection of streaming data algorithms
matrix.h
Go to the documentation of this file.
1 /* -*- Mode: C; tab_width: 8; indent_tabs_mode: nil; c_basic_offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 /** Matrix data storage @file */
8 
9 #ifndef sa_matrix_h_
10 #define sa_matrix_h_
11 
12 #include <stddef.h>
13 #include <stdint.h>
14 
17 
18 #ifdef __cplusplus
19 extern "C"
20 {
21 #endif
22 
23 /**
24  * Allocates and initializes the data structure.
25  *
26  * @param rows
27  * @param cols
28  *
29  * @return Pointer to matrix_int
30  *
31  */
32 sa_matrix_int* sa_create_matrix_int(int rows, int cols);
33 sa_matrix_flt* sa_create_matrix_flt(int rows, int cols);
34 
35 /**
36  * Zeros out the matrix.
37  * - matrix_int is set to all zeros
38  * - matrix_flt is ste to all NAN
39  *
40  * @param m Pointer to matrix_int
41  */
44 
45 /**
46  * Zeros out the specified matrix row.
47  * - matrix_int is set to all zeros
48  * - matrix_flt is ste to all NAN
49  *
50  * @param m Pointer to matrix_int
51  * @param row
52  *
53  */
54 void sa_init_matrix_row_int(sa_matrix_int *m, int row);
55 void sa_init_matrix_row_flt(sa_matrix_flt *m, int row);
56 
57 /**
58  * Adds the specified value to the matrix.
59  *
60  * @param m Pointer to matrix_int
61  * @param row
62  * @param col
63  * @param v Value to add
64  *
65  * @return current value
66  *
67  */
68 int sa_add_matrix_int(sa_matrix_int *m, int row, int col, int v);
69 float sa_add_matrix_flt(sa_matrix_flt *m, int row, int col, float v);
70 
71 /**
72  * Sets the time series row to the specified value.
73  *
74  * @param m Pointer to matrix_int
75  * @param row
76  * @param col
77  * @param v Value to set
78  *
79  * @return current value
80  *
81  */
82 int sa_set_matrix_int(sa_matrix_int *m, int row, int col, int v);
83 float sa_set_matrix_flt(sa_matrix_flt *m, int row, int col, float v);
84 
85 
86 /**
87  * Gets the value of the time series row.
88  *
89  * @param m Pointer to matrix_int
90  * @param row
91  * @param cols
92  *
93  * @return current value
94  *
95  */
96 int sa_get_matrix_int(sa_matrix_int *m, int row, int cols);
97 float sa_get_matrix_flt(sa_matrix_flt *m, int row, int cols);
98 
99 
100 /**
101  * Free the associated memory.
102  *
103  * @param m Pointer to matrix_int
104  *
105  */
108 
109 /**
110  * Serialize the internal state to a buffer.
111  *
112  * @param m Pointer to matrix_int
113  * @param len Length of the returned buffer
114  *
115  * @return char* Serialized representation MUST be freed by the caller
116  */
117 char* sa_serialize_matrix_int(sa_matrix_int *m, size_t *len);
118 char* sa_serialize_matrix_flt(sa_matrix_flt *m, size_t *len);
119 
120 /**
121  * Restores the internal state from the serialized output.
122  *
123  * @param m Pointer to matrix_int
124  * @param buf Buffer containing the output of serialize_matrix_int
125  * @param len Length of the buffer
126  *
127  * @return 0 = success
128  * 1 = invalid buffer length
129  * 2 = invalid rows
130  * 3 = invalid cols
131  *
132  */
133 int
135  const char *buf,
136  size_t len);
137 int
139  const char *buf,
140  size_t len);
141 
142 #ifdef __cplusplus
143 }
144 #endif
145 
146 #endif
float sa_get_matrix_flt(sa_matrix_flt *m, int row, int cols)
void sa_init_matrix_flt(sa_matrix_flt *m)
struct sa_matrix_int sa_matrix_int
Definition: matrix.h:15
int sa_deserialize_matrix_flt(sa_matrix_flt *m, const char *buf, size_t len)
void sa_init_matrix_int(sa_matrix_int *m)
Zeros out the matrix.
char * sa_serialize_matrix_flt(sa_matrix_flt *m, size_t *len)
sa_matrix_int * sa_create_matrix_int(int rows, int cols)
Allocates and initializes the data structure.
float sa_set_matrix_flt(sa_matrix_flt *m, int row, int col, float v)
int sa_get_matrix_int(sa_matrix_int *m, int row, int cols)
Gets the value of the time series row.
int sa_deserialize_matrix_int(sa_matrix_int *m, const char *buf, size_t len)
Restores the internal state from the serialized output.
sa_matrix_flt * sa_create_matrix_flt(int rows, int cols)
int sa_add_matrix_int(sa_matrix_int *m, int row, int col, int v)
Adds the specified value to the matrix.
int sa_set_matrix_int(sa_matrix_int *m, int row, int col, int v)
Sets the time series row to the specified value.
float sa_add_matrix_flt(sa_matrix_flt *m, int row, int col, float v)
void sa_init_matrix_row_flt(sa_matrix_flt *m, int row)
char * sa_serialize_matrix_int(sa_matrix_int *m, size_t *len)
Serialize the internal state to a buffer.
void sa_init_matrix_row_int(sa_matrix_int *m, int row)
Zeros out the specified matrix row.
struct sa_matrix_flt sa_matrix_flt
Definition: matrix.h:16
void sa_destroy_matrix_flt(sa_matrix_flt *m)
void sa_destroy_matrix_int(sa_matrix_int *m)
Free the associated memory.