Orbiter 2022
Combinatorial Objects
vector_builder.cpp
Go to the documentation of this file.
1/*
2 * vector_builder.cpp
3 *
4 * Created on: Nov 1, 2021
5 * Author: betten
6 */
7
8
9#include "foundations.h"
10
11using namespace std;
12
13
14
15namespace orbiter {
16namespace layer1_foundations {
17namespace data_structures {
18
19
21{
22 Descr = NULL;
23 F = NULL;
24 v = NULL;
25 f_has_k = FALSE;
26 k = 0;
27 len = 0;
28}
29
31{
32 if (v) {
33 FREE_int(v);
34 v = NULL;
35 }
36}
37
40 int verbose_level)
41{
42 int f_v = (verbose_level >= 1);
43
44 if (f_v) {
45 cout << "vector_builder::init" << endl;
46 }
47
50
51 if (Descr->f_dense) {
52 if (f_v) {
53 cout << "vector_builder::init -dense" << endl;
54 }
56
57 if (Descr->f_format) {
58 f_has_k = TRUE;
59 k = Descr->format_k;
60 }
61
62 }
63 else if (Descr->f_compact) {
64 if (f_v) {
65 cout << "vector_builder::init -compact" << endl;
66 }
67 int i, j;
68 char c;
69
70 //len = Descr->compact_text.length();
71 len = 0;
72 for (i = 0; i < Descr->compact_text.length(); i++) {
73 c = Descr->compact_text[i];
74 if (c == ' ' || c == ',' || c == '\n') {
75 continue;
76 }
77 len++;
78 }
79 v = NEW_int(len);
80 j = 0;
81 for (i = 0; i < Descr->compact_text.length(); i++) {
82 c = Descr->compact_text[i];
83 if (c == ' ' || c == ',' || c == '\n') {
84 continue;
85 }
86 v[j++] = c - '0';
87 }
88
89 if (Descr->f_format) {
90 f_has_k = TRUE;
91 k = Descr->format_k;
92 }
93
94 }
95 else if (Descr->f_repeat) {
96 if (f_v) {
97 cout << "vector_builder::init -repeat" << endl;
98 }
99 int *w;
100 int sz;
101 int i;
102
104 if (f_v) {
105 cout << "vector_builder::init repeat pattern: ";
106 Int_vec_print(cout, w, sz);
107 cout << endl;
108 }
109
112
113 for (i = 0; i < Descr->repeat_length; i++) {
114 v[i] = w[i % sz];
115 }
116
117 if (Descr->f_format) {
118 f_has_k = TRUE;
119 k = Descr->format_k;
120 }
121
122 }
123 else if (Descr->f_file) {
124 if (f_v) {
125 cout << "vector_builder::init -file " << Descr->file_name << endl;
126 }
128 int m, n;
129
130 Fio.int_matrix_read_csv(Descr->file_name, v, m, n, verbose_level);
131 len = m * n;
132 f_has_k = TRUE;
133 k = m;
134
135 }
136 else if (Descr->f_sparse) {
137 if (f_v) {
138 cout << "vector_builder::init -sparse" << endl;
139 }
140 int *pairs;
141 int sz;
142 int nb_pairs;
143 int i, idx;
144 int c;
145
146 Int_vec_scan(Descr->sparse_pairs, pairs, sz);
147
149 v = NEW_int(len);
151 nb_pairs = sz >> 1;
152 for (i = 0; i < nb_pairs; i++) {
153 c = pairs[2 * i + 0];
154 idx = pairs[2 * i + 1];
155 if (idx < 0 || idx >= len) {
156 cout << "vector_builder::init idx is out of range" << endl;
157 exit(1);
158 }
159 v[idx] = c;
160 }
161 FREE_int(pairs);
162
163 if (Descr->f_format) {
164 f_has_k = TRUE;
165 k = Descr->format_k;
166 }
167
168 }
169 else if (Descr->concatenate_list.size()) {
170
171 int i, j;
172
173 len = 0;
174
175 for (i = 0; i < Descr->concatenate_list.size(); i++) {
176 vector_builder *VB;
177
179 len += VB->len;
180 }
181 v = NEW_int(len);
182 j = 0;
183 for (i = 0; i < Descr->concatenate_list.size(); i++) {
184 vector_builder *VB;
185
187 Int_vec_copy(VB->v, v + j, VB->len);
188 j += VB->len;
189 }
190
191 }
192 else if (Descr->f_loop) {
193 if (f_v) {
194 cout << "vector_builder::init using index set through loop, start="
195 << Descr->loop_start
196 << " upper_bound=" << Descr->loop_upper_bound
197 << " increment=" << Descr->loop_increment << endl;
198 }
199 int i, cnt;
200
201 len = 0;
202 for (i = Descr->loop_start; i < Descr->loop_upper_bound;
203 i += Descr->loop_increment) {
204 len++;
205 }
206 v = NEW_int(len);
207 cnt = 0;
208 for (i = Descr->loop_start; i < Descr->loop_upper_bound;
209 i += Descr->loop_increment) {
210
211
212 v[cnt++] = i;
213
214 }
215 }
216 else {
217 cout << "vector_builder::init please specify how the vector should be created" << endl;
218 exit(1);
219 }
220
221 if (Descr->f_field) {
222 int i, a;
223
224 for (i = 0; i < len; i++) {
225 a = v[i];
226 if (a < 0) {
227 cout << "vector_builder::init entry is out of range: value = " << a << endl;
228 exit(1);
229 }
230 if (a >= F->q) {
231 cout << "vector_builder::init entry is out of range: value = " << a << endl;
232 exit(1);
233 }
234 }
235 }
236
237 if (f_v) {
238 cout << "vector_builder::init created vector of length " << len << endl;
239 Int_vec_print(cout, v, len);
240 cout << endl;
241 if (f_has_k) {
242 cout << "also seen as matrix of size " << k << " x " << len / k << endl;
244 cout << endl;
245
246 }
247 }
248
249
250 if (f_v) {
251 cout << "vector_builder::init done" << endl;
252 }
253}
254
255
256
257
258}}}
259
260
261
to create a vector of field elements from class vector_builder_description
void init(vector_builder_description *Descr, field_theory::finite_field *F, int verbose_level)
void int_matrix_read_csv(std::string &fname, int *&M, int &m, int &n, int verbose_level)
Definition: file_io.cpp:1477
data_structures::vector_builder * get_object_of_type_vector(std::string &label)
#define Int_vec_scan(A, B, C)
Definition: foundations.h:716
#define FREE_int(p)
Definition: foundations.h:640
#define Int_vec_zero(A, B)
Definition: foundations.h:713
#define NEW_int(n)
Definition: foundations.h:625
#define TRUE
Definition: foundations.h:231
#define FALSE
Definition: foundations.h:234
#define Int_vec_copy(A, B, C)
Definition: foundations.h:693
#define Int_vec_print(A, B, C)
Definition: foundations.h:685
orbiter_kernel_system::orbiter_session * Orbiter
global Orbiter session
the orbiter library for the classification of combinatorial objects