Repository navigation
Expand file tree
/
Copy pathtensor.h
More file actions
171 lines (141 loc) · 4.81 KB
/
Copy pathtensor.h
File metadata and controls
171 lines (141 loc) · 4.81 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#ifndef _TENSOR_H_
#define _TENSOR_H_
#include "mmio.h"
#include "types.h"
#include "vector.h"
#include <stdio.h>
namespace permutation_heuristic {
typedef enum {
none,
naive_minimum,
naive_median
} type_t;
}
namespace file_format {
typedef enum {
unknown,
mmio,
matlab
} type_t;
}
namespace strategy {
typedef enum {
unknown,
array,
coordinate,
compressed,
gundersen,
slice,
ekmr,
zzekmr
} type_t;
}
namespace orientation {
typedef enum {
unknown,
row,
column,
tube,
lateral,
horizontal,
frontal
} type_t;
}
typedef struct {
uint l, m, n, nnz;
strategy::type_t strategy;
orientation::type_t orientation;
ownership::type_t owner;
void *storage;
double *values;
} tensor_t;
typedef struct {
uint i, j, k;
uint index;
} coordinate_tuple_t;
typedef int (*index_compare_t)(const void *a, const void *b);
typedef uint (*index_encoder_t)(coordinate_tuple_t const *tuple);
typedef void (*index_copy_t)(void *destination, void const *source, uint i);
typedef struct {
index_compare_t index_compare;
index_encoder_t index_r_encoder;
index_encoder_t index_c_encoder;
index_copy_t index_copy;
} conversion_callbacks_t;
typedef struct {
conversion_callbacks_t *callbacks;
} tensor_storage_base_t;
typedef struct {
tensor_storage_base_t dummy;
coordinate_tuple_t *tuples;
} tensor_storage_coordinate_t;
typedef struct {
tensor_storage_base_t base;
uint n, rn, cn, tn, kn;
uint *RO, *CO, *TO, *KO;
} tensor_storage_compressed_t;
typedef struct {
tensor_storage_base_t base;
uint rn, ckn;
uint *RO, *CK;
} tensor_storage_extended_t;
typedef struct {
tensor_storage_extended_t dummy;
} tensor_storage_ekmr_t;
typedef struct {
tensor_storage_extended_t dummy;
} tensor_storage_zzekmr_t;
#define STORAGE_BASE(x) ((tensor_storage_base_t*)x->storage)
#define STORAGE_COORIDINATE(x) ((tensor_storage_coordinate_t*)x->storage)
#define STORAGE_COMPRESSED(x) ((tensor_storage_compressed_t*)x->storage)
#define STORAGE_EXTENDED(x) ((tensor_storage_extended_t*)x->storage)
tensor_t* tensor_malloc(uint l, uint m, uint n, ownership::type_t owner = ownership::creator);
tensor_t* tensor_malloc(uint l, uint m, uint n, uint nnz, strategy::type_t strategy,
orientation::type_t orientation = orientation::unknown,
ownership::type_t owner = ownership::creator);
tensor_t* tensor_malloc_from_template(tensor_t const *tensor);
void tensor_free(tensor_t *tensor);
tensor_t* tensor_copy_shallow(tensor_t *source);
void tensor_copy_shallow(tensor_t *destination, tensor_t *source);
void tensor_transfer_ownership(tensor_t *destination, tensor_t *source);
void tensor_clear(tensor_t *tensor);
tensor_t *tensor_convert(tensor_t *tensor, strategy::type_t strategy, orientation::type_t orientation = orientation::unknown);
void tensor_convert(tensor_t *destination, tensor_t *source);
tensor_t* tensor_permute(tensor_t *tensor, permutation_heuristic::type_t heuristic);
tensor_t *tensor_read(char const *filename);
tensor_t *tensor_fread(FILE *file);
tensor_t *tensor_fread_data(FILE *file, MM_typecode type);
void tensor_write(char const *filename, tensor_t const *tensor);
void tensor_fwrite(FILE *file, tensor_t const *tensor);
void tensor_emit_latex(FILE *file, tensor_t const *tensor);
void tensor_supported(tensor_t const *t1);
void tensor_validate(tensor_t const *tensor);
char const* strategy_to_string(strategy::type_t strategy);
char const* orientation_to_string(orientation::type_t orientation);
char const* orientation_to_latex_macro(orientation::type_t orientation);
char const* permutation_heuristic_to_string(permutation_heuristic::type_t heuristic);
strategy::type_t string_to_strategy(char const *name);
orientation::type_t string_to_orientation(char const *name);
permutation_heuristic::type_t string_to_permutation_heuristic(char const *name);
strategy::type_t typecode_to_strategy(MM_typecode type);
void strategy_to_typecode(MM_typecode *type, strategy::type_t strategy);
void print_strategies(char const *format);
void print_orientations(char const *format);
void print_operations(char const *format);
void print_operations_with_descriptions(char const *format);
void print_permutation_heuristics(char const *format);
void print_permutation_heuristics_with_descriptions(char const *format);
#if 0
void tensor_add(tensor_t *t1, tensor_t const *t2);
tensor_t *tensor_add(tensor_t const *t1, tensor_t const *t2);
void tensor_subtract(tensor_t *t1, tensor_t const *t2);
tensor_t *tensor_subtract(tensor_t const *t1, tensor_t const *t2);
void tensor_multiply(tensor_t *tr, tensor_t const *t1, tensor_t const *t2);
tensor_t *tensor_multiply(tensor_t const *t1, tensor_t const *t2);
#endif
#endif
/*
Local Variables:
mode: C++
End:
*/