SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parameter.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2010 Soeren Sonnenburg
8  * Written (W) 2011 Heiko Strathmann
9  * Copyright (C) 2010 Berlin Institute of Technology
10  */
11 
12 #include <shogun/base/Parameter.h>
13 #include <shogun/base/class_list.h>
14 #include <shogun/lib/Hash.h>
15 
16 using namespace shogun;
17 
18 extern IO* sg_io;
19 
20 /* **************************************************************** */
21 /* Scalar wrappers */
22 
23 void
24 Parameter::add(bool* param, const char* name,
25  const char* description) {
26  TSGDataType type(CT_SCALAR, ST_NONE, PT_BOOL);
27  add_type(&type, param, name, description);
28 }
29 
30 void
31 Parameter::add(char* param, const char* name,
32  const char* description) {
33  TSGDataType type(CT_SCALAR, ST_NONE, PT_CHAR);
34  add_type(&type, param, name, description);
35 }
36 
37 void
38 Parameter::add(int8_t* param, const char* name,
39  const char* description) {
40  TSGDataType type(CT_SCALAR, ST_NONE, PT_INT8);
41  add_type(&type, param, name, description);
42 }
43 
44 void
45 Parameter::add(uint8_t* param, const char* name,
46  const char* description) {
47  TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT8);
48  add_type(&type, param, name, description);
49 }
50 
51 void
52 Parameter::add(int16_t* param, const char* name,
53  const char* description) {
54  TSGDataType type(CT_SCALAR, ST_NONE, PT_INT16);
55  add_type(&type, param, name, description);
56 }
57 
58 void
59 Parameter::add(uint16_t* param, const char* name,
60  const char* description) {
61  TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT16);
62  add_type(&type, param, name, description);
63 }
64 
65 void
66 Parameter::add(int32_t* param, const char* name,
67  const char* description) {
68  TSGDataType type(CT_SCALAR, ST_NONE, PT_INT32);
69  add_type(&type, param, name, description);
70 }
71 
72 void
73 Parameter::add(uint32_t* param, const char* name,
74  const char* description) {
75  TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT32);
76  add_type(&type, param, name, description);
77 }
78 
79 void
80 Parameter::add(int64_t* param, const char* name,
81  const char* description) {
82  TSGDataType type(CT_SCALAR, ST_NONE, PT_INT64);
83  add_type(&type, param, name, description);
84 }
85 
86 void
87 Parameter::add(uint64_t* param, const char* name,
88  const char* description) {
89  TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT64);
90  add_type(&type, param, name, description);
91 }
92 
93 void
94 Parameter::add(float32_t* param, const char* name,
95  const char* description) {
96  TSGDataType type(CT_SCALAR, ST_NONE, PT_FLOAT32);
97  add_type(&type, param, name, description);
98 }
99 
100 void
101 Parameter::add(float64_t* param, const char* name,
102  const char* description) {
103  TSGDataType type(CT_SCALAR, ST_NONE, PT_FLOAT64);
104  add_type(&type, param, name, description);
105 }
106 
107 void
108 Parameter::add(floatmax_t* param, const char* name,
109  const char* description) {
110  TSGDataType type(CT_SCALAR, ST_NONE, PT_FLOATMAX);
111  add_type(&type, param, name, description);
112 }
113 
114 void
116  const char* name, const char* description) {
117  TSGDataType type(CT_SCALAR, ST_NONE, PT_SGOBJECT);
118  add_type(&type, param, name, description);
119 }
120 
121 void
122 Parameter::add(SGString<bool>* param, const char* name,
123  const char* description) {
124  TSGDataType type(CT_SCALAR, ST_STRING, PT_BOOL);
125  add_type(&type, param, name, description);
126 }
127 
128 void
129 Parameter::add(SGString<char>* param, const char* name,
130  const char* description) {
131  TSGDataType type(CT_SCALAR, ST_STRING, PT_CHAR);
132  add_type(&type, param, name, description);
133 }
134 
135 void
136 Parameter::add(SGString<int8_t>* param, const char* name,
137  const char* description) {
138  TSGDataType type(CT_SCALAR, ST_STRING, PT_INT8);
139  add_type(&type, param, name, description);
140 }
141 
142 void
143 Parameter::add(SGString<uint8_t>* param, const char* name,
144  const char* description) {
145  TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT8);
146  add_type(&type, param, name, description);
147 }
148 
149 void
150 Parameter::add(SGString<int16_t>* param, const char* name,
151  const char* description) {
152  TSGDataType type(CT_SCALAR, ST_STRING, PT_INT16);
153  add_type(&type, param, name, description);
154 }
155 
156 void
157 Parameter::add(SGString<uint16_t>* param, const char* name,
158  const char* description) {
159  TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT16);
160  add_type(&type, param, name, description);
161 }
162 
163 void
164 Parameter::add(SGString<int32_t>* param, const char* name,
165  const char* description) {
166  TSGDataType type(CT_SCALAR, ST_STRING, PT_INT32);
167  add_type(&type, param, name, description);
168 }
169 
170 void
171 Parameter::add(SGString<uint32_t>* param, const char* name,
172  const char* description) {
173  TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT32);
174  add_type(&type, param, name, description);
175 }
176 
177 void
178 Parameter::add(SGString<int64_t>* param, const char* name,
179  const char* description) {
180  TSGDataType type(CT_SCALAR, ST_STRING, PT_INT64);
181  add_type(&type, param, name, description);
182 }
183 
184 void
185 Parameter::add(SGString<uint64_t>* param, const char* name,
186  const char* description) {
187  TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT64);
188  add_type(&type, param, name, description);
189 }
190 
191 void
192 Parameter::add(SGString<float32_t>* param, const char* name,
193  const char* description) {
194  TSGDataType type(CT_SCALAR, ST_STRING, PT_FLOAT32);
195  add_type(&type, param, name, description);
196 }
197 
198 void
199 Parameter::add(SGString<float64_t>* param, const char* name,
200  const char* description) {
201  TSGDataType type(CT_SCALAR, ST_STRING, PT_FLOAT64);
202  add_type(&type, param, name, description);
203 }
204 
205 void
206 Parameter::add(SGString<floatmax_t>* param, const char* name,
207  const char* description) {
208  TSGDataType type(CT_SCALAR, ST_STRING, PT_FLOATMAX);
209  add_type(&type, param, name, description);
210 }
211 
212 void
213 Parameter::add(SGSparseVector<bool>* param, const char* name,
214  const char* description) {
215  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_BOOL);
216  add_type(&type, param, name, description);
217 }
218 
219 void
220 Parameter::add(SGSparseVector<char>* param, const char* name,
221  const char* description) {
222  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_CHAR);
223  add_type(&type, param, name, description);
224 }
225 
226 void
227 Parameter::add(SGSparseVector<int8_t>* param, const char* name,
228  const char* description) {
229  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT8);
230  add_type(&type, param, name, description);
231 }
232 
233 void
234 Parameter::add(SGSparseVector<uint8_t>* param, const char* name,
235  const char* description) {
236  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT8);
237  add_type(&type, param, name, description);
238 }
239 
240 void
241 Parameter::add(SGSparseVector<int16_t>* param, const char* name,
242  const char* description) {
243  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT16);
244  add_type(&type, param, name, description);
245 }
246 
247 void
248 Parameter::add(SGSparseVector<uint16_t>* param, const char* name,
249  const char* description) {
250  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT16);
251  add_type(&type, param, name, description);
252 }
253 
254 void
255 Parameter::add(SGSparseVector<int32_t>* param, const char* name,
256  const char* description) {
257  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT32);
258  add_type(&type, param, name, description);
259 }
260 
261 void
262 Parameter::add(SGSparseVector<uint32_t>* param, const char* name,
263  const char* description) {
264  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT32);
265  add_type(&type, param, name, description);
266 }
267 
268 void
269 Parameter::add(SGSparseVector<int64_t>* param, const char* name,
270  const char* description) {
271  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT64);
272  add_type(&type, param, name, description);
273 }
274 
275 void
276 Parameter::add(SGSparseVector<uint64_t>* param, const char* name,
277  const char* description) {
278  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT64);
279  add_type(&type, param, name, description);
280 }
281 
282 void
283 Parameter::add(SGSparseVector<float32_t>* param, const char* name,
284  const char* description) {
285  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_FLOAT32);
286  add_type(&type, param, name, description);
287 }
288 
289 void
290 Parameter::add(SGSparseVector<float64_t>* param, const char* name,
291  const char* description) {
292  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_FLOAT64);
293  add_type(&type, param, name, description);
294 }
295 
296 void
298  const char* description) {
299  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_FLOATMAX);
300  add_type(&type, param, name, description);
301 }
302 
303 /* **************************************************************** */
304 /* Vector wrappers */
305 
306 void
308  bool** param, index_t* length, const char* name,
309  const char* description) {
310  TSGDataType type(CT_VECTOR, ST_NONE, PT_BOOL, length);
311  add_type(&type, param, name, description);
312 }
313 
314 void
316  char** param, index_t* length, const char* name,
317  const char* description) {
318  TSGDataType type(CT_VECTOR, ST_NONE, PT_CHAR, length);
319  add_type(&type, param, name, description);
320 }
321 
322 void
324  int8_t** param, index_t* length, const char* name,
325  const char* description) {
326  TSGDataType type(CT_VECTOR, ST_NONE, PT_INT8, length);
327  add_type(&type, param, name, description);
328 }
329 
330 void
332  uint8_t** param, index_t* length, const char* name,
333  const char* description) {
334  TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT8, length);
335  add_type(&type, param, name, description);
336 }
337 
338 void
340  int16_t** param, index_t* length, const char* name,
341  const char* description) {
342  TSGDataType type(CT_VECTOR, ST_NONE, PT_INT16, length);
343  add_type(&type, param, name, description);
344 }
345 
346 void
348  uint16_t** param, index_t* length, const char* name,
349  const char* description) {
350  TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT16, length);
351  add_type(&type, param, name, description);
352 }
353 
354 void
356  int32_t** param, index_t* length, const char* name,
357  const char* description) {
358  TSGDataType type(CT_VECTOR, ST_NONE, PT_INT32, length);
359  add_type(&type, param, name, description);
360 }
361 
362 void
364  uint32_t** param, index_t* length, const char* name,
365  const char* description) {
366  TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT32, length);
367  add_type(&type, param, name, description);
368 }
369 
370 void
372  int64_t** param, index_t* length, const char* name,
373  const char* description) {
374  TSGDataType type(CT_VECTOR, ST_NONE, PT_INT64, length);
375  add_type(&type, param, name, description);
376 }
377 
378 void
380  uint64_t** param, index_t* length, const char* name,
381  const char* description) {
382  TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT64, length);
383  add_type(&type, param, name, description);
384 }
385 
386 void
388  float32_t** param, index_t* length, const char* name,
389  const char* description) {
390  TSGDataType type(CT_VECTOR, ST_NONE, PT_FLOAT32, length);
391  add_type(&type, param, name, description);
392 }
393 
394 void
396  float64_t** param, index_t* length, const char* name,
397  const char* description) {
398  TSGDataType type(CT_VECTOR, ST_NONE, PT_FLOAT64, length);
399  add_type(&type, param, name, description);
400 }
401 
402 void
404  floatmax_t** param, index_t* length, const char* name,
405  const char* description) {
406  TSGDataType type(CT_VECTOR, ST_NONE, PT_FLOATMAX, length);
407  add_type(&type, param, name, description);
408 }
409 
410 void
412  const char* name, const char* description) {
413  TSGDataType type(CT_VECTOR, ST_NONE, PT_SGOBJECT,
414  length);
415  add_type(&type, param, name, description);
416 }
417 
418 void
420  const char* name, const char* description) {
421  TSGDataType type(CT_VECTOR, ST_STRING, PT_BOOL, length);
422  add_type(&type, param, name, description);
423 }
424 
425 void
427  const char* name, const char* description) {
428  TSGDataType type(CT_VECTOR, ST_STRING, PT_CHAR, length);
429  add_type(&type, param, name, description);
430 }
431 
432 void
434  const char* name, const char* description) {
435  TSGDataType type(CT_VECTOR, ST_STRING, PT_INT8, length);
436  add_type(&type, param, name, description);
437 }
438 
439 void
441  const char* name, const char* description) {
442  TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT8, length);
443  add_type(&type, param, name, description);
444 }
445 
446 void
448  const char* name, const char* description) {
449  TSGDataType type(CT_VECTOR, ST_STRING, PT_INT16, length);
450  add_type(&type, param, name, description);
451 }
452 
453 void
455  const char* name, const char* description) {
456  TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT16, length);
457  add_type(&type, param, name, description);
458 }
459 
460 void
462  const char* name, const char* description) {
463  TSGDataType type(CT_VECTOR, ST_STRING, PT_INT32, length);
464  add_type(&type, param, name, description);
465 }
466 
467 void
469  const char* name, const char* description) {
470  TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT32, length);
471  add_type(&type, param, name, description);
472 }
473 
474 void
476  const char* name, const char* description) {
477  TSGDataType type(CT_VECTOR, ST_STRING, PT_INT64, length);
478  add_type(&type, param, name, description);
479 }
480 
481 void
483  const char* name, const char* description) {
484  TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT64, length);
485  add_type(&type, param, name, description);
486 }
487 
488 void
490  const char* name, const char* description) {
491  TSGDataType type(CT_VECTOR, ST_STRING, PT_FLOAT32, length);
492  add_type(&type, param, name, description);
493 }
494 
495 void
497  const char* name, const char* description) {
498  TSGDataType type(CT_VECTOR, ST_STRING, PT_FLOAT64, length);
499  add_type(&type, param, name, description);
500 }
501 
502 void
504  const char* name, const char* description) {
505  TSGDataType type(CT_VECTOR, ST_STRING, PT_FLOATMAX, length);
506  add_type(&type, param, name, description);
507 }
508 
509 void
511  const char* name, const char* description) {
512  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_BOOL, length);
513  add_type(&type, param, name, description);
514 }
515 
516 void
518  const char* name, const char* description) {
519  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_CHAR, length);
520  add_type(&type, param, name, description);
521 }
522 
523 void
525  const char* name, const char* description) {
526  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT8, length);
527  add_type(&type, param, name, description);
528 }
529 
530 void
532  const char* name, const char* description) {
533  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT8, length);
534  add_type(&type, param, name, description);
535 }
536 
537 void
539  const char* name, const char* description) {
540  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT16, length);
541  add_type(&type, param, name, description);
542 }
543 
544 void
546  const char* name, const char* description) {
547  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT16, length);
548  add_type(&type, param, name, description);
549 }
550 
551 void
553  const char* name, const char* description) {
554  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT32, length);
555  add_type(&type, param, name, description);
556 }
557 
558 void
560  const char* name, const char* description) {
561  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT32, length);
562  add_type(&type, param, name, description);
563 }
564 
565 void
567  const char* name, const char* description) {
568  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT64, length);
569  add_type(&type, param, name, description);
570 }
571 
572 void
574  const char* name, const char* description) {
575  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT64, length);
576  add_type(&type, param, name, description);
577 }
578 
579 void
581  const char* name, const char* description) {
582  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_FLOAT32, length);
583  add_type(&type, param, name, description);
584 }
585 
586 void
588  const char* name, const char* description) {
589  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_FLOAT64, length);
590  add_type(&type, param, name, description);
591 }
592 
593 void
595  const char* name, const char* description) {
596  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_FLOATMAX, length);
597  add_type(&type, param, name, description);
598 }
599 
600 
601 
602 
603 void Parameter::add(SGVector<bool>* param, const char* name,
604  const char* description)
605 {
606  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_BOOL, &param->vlen);
607  add_type(&type, &param->vector, name, description);
608 }
609 
610 void Parameter::add(SGVector<char>* param, const char* name,
611  const char* description)
612 {
613  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_CHAR, &param->vlen);
614  add_type(&type, &param->vector, name, description);
615 }
616 
617 void Parameter::add(SGVector<int8_t>* param, const char* name,
618  const char* description)
619 {
620  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_INT8, &param->vlen);
621  add_type(&type, &param->vector, name, description);
622 }
623 
624 void Parameter::add(SGVector<uint8_t>* param, const char* name,
625  const char* description)
626 {
627  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_UINT8, &param->vlen);
628  add_type(&type, &param->vector, name, description);
629 }
630 
631 void Parameter::add(SGVector<int16_t>* param, const char* name,
632  const char* description)
633 {
634  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_INT16, &param->vlen);
635  add_type(&type, &param->vector, name, description);
636 }
637 
638 void Parameter::add(SGVector<uint16_t>* param, const char* name,
639  const char* description)
640 {
641  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_UINT16, &param->vlen);
642  add_type(&type, &param->vector, name, description);
643 }
644 
645 void Parameter::add(SGVector<int32_t>* param, const char* name,
646  const char* description)
647 {
648  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_INT32, &param->vlen);
649  add_type(&type, &param->vector, name, description);
650 }
651 
652 void Parameter::add(SGVector<uint32_t>* param, const char* name,
653  const char* description)
654 {
655  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_UINT32, &param->vlen);
656  add_type(&type, &param->vector, name, description);
657 }
658 
659 void Parameter::add(SGVector<int64_t>* param, const char* name,
660  const char* description)
661 {
662  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_INT64, &param->vlen);
663  add_type(&type, &param->vector, name, description);
664 }
665 
666 void Parameter::add(SGVector<uint64_t>* param, const char* name,
667  const char* description)
668 {
669  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_UINT64, &param->vlen);
670  add_type(&type, &param->vector, name, description);
671 }
672 
673 void Parameter::add(SGVector<float32_t>* param, const char* name,
674  const char* description)
675 {
676  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_FLOAT32, &param->vlen);
677  add_type(&type, &param->vector, name, description);
678 }
679 
680 void Parameter::add(SGVector<float64_t>* param, const char* name,
681  const char* description)
682 {
683  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_FLOAT64, &param->vlen);
684  add_type(&type, &param->vector, name, description);
685 }
686 
687 void Parameter::add(SGVector<floatmax_t>* param, const char* name,
688  const char* description)
689 {
690  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_FLOATMAX, &param->vlen);
691  add_type(&type, &param->vector, name, description);
692 }
693 
694 void Parameter::add(SGVector<CSGObject*>* param, const char* name,
695  const char* description)
696 {
697  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_SGOBJECT, &param->vlen);
698  add_type(&type, &param->vector, name, description);
699 }
700 
701 void Parameter::add(SGVector<SGString<bool> >* param, const char* name,
702  const char* description)
703 {
704  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_BOOL, &param->vlen);
705  add_type(&type, &param->vector, name, description);
706 }
707 
708 void Parameter::add(SGVector<SGString<char> >* param, const char* name,
709  const char* description)
710 {
711  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_CHAR, &param->vlen);
712  add_type(&type, &param->vector, name, description);
713 }
714 
716  const char* name, const char* description)
717 {
718  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_INT8, &param->vlen);
719  add_type(&type, &param->vector, name, description);
720 }
721 
723  const char* name, const char* description)
724 {
725  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_UINT8, &param->vlen);
726  add_type(&type, &param->vector, name, description);
727 }
728 
730  const char* name, const char* description)
731 {
732  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_INT16, &param->vlen);
733  add_type(&type, &param->vector, name, description);
734 }
735 
737  const char* name, const char* description)
738 {
739  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_UINT16, &param->vlen);
740  add_type(&type, &param->vector, name, description);
741 }
742 
744  const char* name, const char* description)
745 {
746  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_INT32, &param->vlen);
747  add_type(&type, &param->vector, name, description);
748 }
749 
751  const char* name, const char* description)
752 {
753  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_UINT32, &param->vlen);
754  add_type(&type, &param->vector, name, description);
755 }
756 
758  const char* name, const char* description)
759 {
760  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_INT64, &param->vlen);
761  add_type(&type, &param->vector, name, description);
762 }
763 
765  const char* name, const char* description)
766 {
767  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_UINT64, &param->vlen);
768  add_type(&type, &param->vector, name, description);
769 }
770 
772  const char* name, const char* description)
773 {
774  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_FLOAT32, &param->vlen);
775  add_type(&type, &param->vector, name, description);
776 }
777 
779  const char* name, const char* description)
780 {
781  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_FLOAT64, &param->vlen);
782  add_type(&type, &param->vector, name, description);
783 }
784 
786  const char* name, const char* description)
787 {
788  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_FLOATMAX, &param->vlen);
789  add_type(&type, &param->vector, name, description);
790 }
791 
793  const char* name, const char* description)
794 {
795  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_BOOL, &param->vlen);
796  add_type(&type, &param->vector, name, description);
797 }
798 
800  const char* name, const char* description)
801 {
802  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_CHAR, &param->vlen);
803  add_type(&type, &param->vector, name, description);
804 }
805 
807  const char* name, const char* description)
808 {
809  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_INT8, &param->vlen);
810  add_type(&type, &param->vector, name, description);
811 }
812 
814  const char* name, const char* description)
815 {
816  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_UINT8, &param->vlen);
817  add_type(&type, &param->vector, name, description);
818 }
819 
821  const char* name, const char* description)
822 {
823  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_INT16, &param->vlen);
824  add_type(&type, &param->vector, name, description);
825 }
826 
828  const char* name, const char* description)
829 {
830  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_UINT16, &param->vlen);
831  add_type(&type, &param->vector, name, description);
832 }
833 
835  const char* name, const char* description)
836 {
837  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_INT32, &param->vlen);
838  add_type(&type, &param->vector, name, description);
839 }
840 
842  const char* name, const char* description)
843 {
844  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_UINT32, &param->vlen);
845  add_type(&type, &param->vector, name, description);
846 }
847 
849  const char* name, const char* description)
850 {
851  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_INT64, &param->vlen);
852  add_type(&type, &param->vector, name, description);
853 }
854 
856  const char* name, const char* description)
857 {
858  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_UINT64, &param->vlen);
859  add_type(&type, &param->vector, name, description);
860 }
861 
863  const char* name, const char* description)
864 {
865  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_FLOAT32, &param->vlen);
866  add_type(&type, &param->vector, name, description);
867 }
868 
870  const char* name, const char* description)
871 {
872  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_FLOAT64, &param->vlen);
873  add_type(&type, &param->vector, name, description);
874 }
875 
877  const char* name, const char* description)
878 {
879  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_FLOATMAX, &param->vlen);
880  add_type(&type, &param->vector, name, description);
881 }
882 
883 /* **************************************************************** */
884 /* Matrix wrappers */
885 
886 void
888  bool** param, index_t* length_y, index_t* length_x,
889  const char* name, const char* description) {
890  TSGDataType type(CT_MATRIX, ST_NONE, PT_BOOL, length_y,
891  length_x);
892  add_type(&type, param, name, description);
893 }
894 
895 void
897  char** param, index_t* length_y, index_t* length_x,
898  const char* name, const char* description) {
899  TSGDataType type(CT_MATRIX, ST_NONE, PT_CHAR, length_y,
900  length_x);
901  add_type(&type, param, name, description);
902 }
903 
904 void
906  int8_t** param, index_t* length_y, index_t* length_x,
907  const char* name, const char* description) {
908  TSGDataType type(CT_MATRIX, ST_NONE, PT_INT8, length_y,
909  length_x);
910  add_type(&type, param, name, description);
911 }
912 
913 void
915  uint8_t** param, index_t* length_y, index_t* length_x,
916  const char* name, const char* description) {
917  TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT8, length_y,
918  length_x);
919  add_type(&type, param, name, description);
920 }
921 
922 void
924  int16_t** param, index_t* length_y, index_t* length_x,
925  const char* name, const char* description) {
926  TSGDataType type(CT_MATRIX, ST_NONE, PT_INT16, length_y,
927  length_x);
928  add_type(&type, param, name, description);
929 }
930 
931 void
933  uint16_t** param, index_t* length_y, index_t* length_x,
934  const char* name, const char* description) {
935  TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT16, length_y,
936  length_x);
937  add_type(&type, param, name, description);
938 }
939 
940 void
942  int32_t** param, index_t* length_y, index_t* length_x,
943  const char* name, const char* description) {
944  TSGDataType type(CT_MATRIX, ST_NONE, PT_INT32, length_y,
945  length_x);
946  add_type(&type, param, name, description);
947 }
948 
949 void
951  uint32_t** param, index_t* length_y, index_t* length_x,
952  const char* name, const char* description) {
953  TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT32, length_y,
954  length_x);
955  add_type(&type, param, name, description);
956 }
957 
958 void
960  int64_t** param, index_t* length_y, index_t* length_x,
961  const char* name, const char* description) {
962  TSGDataType type(CT_MATRIX, ST_NONE, PT_INT64, length_y,
963  length_x);
964  add_type(&type, param, name, description);
965 }
966 
967 void
969  uint64_t** param, index_t* length_y, index_t* length_x,
970  const char* name, const char* description) {
971  TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT64, length_y,
972  length_x);
973  add_type(&type, param, name, description);
974 }
975 
976 void
978  float32_t** param, index_t* length_y, index_t* length_x,
979  const char* name, const char* description) {
980  TSGDataType type(CT_MATRIX, ST_NONE, PT_FLOAT32, length_y,
981  length_x);
982  add_type(&type, param, name, description);
983 }
984 
985 void
987  float64_t** param, index_t* length_y, index_t* length_x,
988  const char* name, const char* description) {
989  TSGDataType type(CT_MATRIX, ST_NONE, PT_FLOAT64, length_y,
990  length_x);
991  add_type(&type, param, name, description);
992 }
993 
994 void
996  floatmax_t** param, index_t* length_y, index_t* length_x,
997  const char* name, const char* description) {
998  TSGDataType type(CT_MATRIX, ST_NONE, PT_FLOATMAX, length_y,
999  length_x);
1000  add_type(&type, param, name, description);
1001 }
1002 
1003 void
1005  CSGObject*** param, index_t* length_y, index_t* length_x,
1006  const char* name, const char* description) {
1007  TSGDataType type(CT_MATRIX, ST_NONE, PT_SGOBJECT,
1008  length_y, length_x);
1009  add_type(&type, param, name, description);
1010 }
1011 
1012 void
1014  index_t* length_y, index_t* length_x,
1015  const char* name, const char* description) {
1016  TSGDataType type(CT_MATRIX, ST_STRING, PT_BOOL, length_y,
1017  length_x);
1018  add_type(&type, param, name, description);
1019 }
1020 
1021 void
1023  index_t* length_y, index_t* length_x,
1024  const char* name, const char* description) {
1025  TSGDataType type(CT_MATRIX, ST_STRING, PT_CHAR, length_y,
1026  length_x);
1027  add_type(&type, param, name, description);
1028 }
1029 
1030 void
1032  index_t* length_y, index_t* length_x,
1033  const char* name, const char* description) {
1034  TSGDataType type(CT_MATRIX, ST_STRING, PT_INT8, length_y,
1035  length_x);
1036  add_type(&type, param, name, description);
1037 }
1038 
1039 void
1041  index_t* length_y, index_t* length_x,
1042  const char* name, const char* description) {
1043  TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT8, length_y,
1044  length_x);
1045  add_type(&type, param, name, description);
1046 }
1047 
1048 void
1050  index_t* length_y, index_t* length_x,
1051  const char* name, const char* description) {
1052  TSGDataType type(CT_MATRIX, ST_STRING, PT_INT16, length_y,
1053  length_x);
1054  add_type(&type, param, name, description);
1055 }
1056 
1057 void
1059  index_t* length_y, index_t* length_x,
1060  const char* name, const char* description) {
1061  TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT16, length_y,
1062  length_x);
1063  add_type(&type, param, name, description);
1064 }
1065 
1066 void
1068  index_t* length_y, index_t* length_x,
1069  const char* name, const char* description) {
1070  TSGDataType type(CT_MATRIX, ST_STRING, PT_INT32, length_y,
1071  length_x);
1072  add_type(&type, param, name, description);
1073 }
1074 
1075 void
1077  index_t* length_y, index_t* length_x,
1078  const char* name, const char* description) {
1079  TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT32, length_y,
1080  length_x);
1081  add_type(&type, param, name, description);
1082 }
1083 
1084 void
1086  index_t* length_y, index_t* length_x,
1087  const char* name, const char* description) {
1088  TSGDataType type(CT_MATRIX, ST_STRING, PT_INT64, length_y,
1089  length_x);
1090  add_type(&type, param, name, description);
1091 }
1092 
1093 void
1095  index_t* length_y, index_t* length_x,
1096  const char* name, const char* description) {
1097  TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT64, length_y,
1098  length_x);
1099  add_type(&type, param, name, description);
1100 }
1101 
1102 void
1104  index_t* length_y, index_t* length_x,
1105  const char* name, const char* description) {
1106  TSGDataType type(CT_MATRIX, ST_STRING, PT_FLOAT32, length_y,
1107  length_x);
1108  add_type(&type, param, name, description);
1109 }
1110 
1111 void
1113  index_t* length_y, index_t* length_x,
1114  const char* name, const char* description) {
1115  TSGDataType type(CT_MATRIX, ST_STRING, PT_FLOAT64, length_y,
1116  length_x);
1117  add_type(&type, param, name, description);
1118 }
1119 
1120 void
1122  index_t* length_y, index_t* length_x,
1123  const char* name, const char* description) {
1124  TSGDataType type(CT_MATRIX, ST_STRING, PT_FLOATMAX, length_y,
1125  length_x);
1126  add_type(&type, param, name, description);
1127 }
1128 
1129 void
1131  index_t* length_y, index_t* length_x,
1132  const char* name, const char* description) {
1133  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_BOOL, length_y,
1134  length_x);
1135  add_type(&type, param, name, description);
1136 }
1137 
1138 void
1140  index_t* length_y, index_t* length_x,
1141  const char* name, const char* description) {
1142  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_CHAR, length_y,
1143  length_x);
1144  add_type(&type, param, name, description);
1145 }
1146 
1147 void
1149  index_t* length_y, index_t* length_x,
1150  const char* name, const char* description) {
1151  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT8, length_y,
1152  length_x);
1153  add_type(&type, param, name, description);
1154 }
1155 
1156 void
1158  index_t* length_y, index_t* length_x,
1159  const char* name, const char* description) {
1160  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT8, length_y,
1161  length_x);
1162  add_type(&type, param, name, description);
1163 }
1164 
1165 void
1167  index_t* length_y, index_t* length_x,
1168  const char* name, const char* description) {
1169  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT16, length_y,
1170  length_x);
1171  add_type(&type, param, name, description);
1172 }
1173 
1174 void
1176  index_t* length_y, index_t* length_x,
1177  const char* name, const char* description) {
1178  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT16, length_y,
1179  length_x);
1180  add_type(&type, param, name, description);
1181 }
1182 
1183 void
1185  index_t* length_y, index_t* length_x,
1186  const char* name, const char* description) {
1187  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT32, length_y,
1188  length_x);
1189  add_type(&type, param, name, description);
1190 }
1191 
1192 void
1194  index_t* length_y, index_t* length_x,
1195  const char* name, const char* description) {
1196  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT32, length_y,
1197  length_x);
1198  add_type(&type, param, name, description);
1199 }
1200 
1201 void
1203  index_t* length_y, index_t* length_x,
1204  const char* name, const char* description) {
1205  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT64, length_y,
1206  length_x);
1207  add_type(&type, param, name, description);
1208 }
1209 
1210 void
1212  index_t* length_y, index_t* length_x,
1213  const char* name, const char* description) {
1214  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT64, length_y,
1215  length_x);
1216  add_type(&type, param, name, description);
1217 }
1218 
1219 void
1221  index_t* length_y, index_t* length_x,
1222  const char* name, const char* description) {
1223  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_FLOAT32, length_y,
1224  length_x);
1225  add_type(&type, param, name, description);
1226 }
1227 
1228 void
1230  index_t* length_y, index_t* length_x,
1231  const char* name, const char* description) {
1232  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_FLOAT64, length_y,
1233  length_x);
1234  add_type(&type, param, name, description);
1235 }
1236 
1237 void
1239  index_t* length_y, index_t* length_x,
1240  const char* name, const char* description) {
1241  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_FLOATMAX, length_y,
1242  length_x);
1243  add_type(&type, param, name, description);
1244 }
1245 
1246 
1247 
1248 
1249 void Parameter::add(SGMatrix<bool>* param, const char* name,
1250  const char* description)
1251 {
1252  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_BOOL, &param->num_rows,
1253  &param->num_cols);
1254  add_type(&type, &param->matrix, name, description);
1255 }
1256 
1257 void Parameter::add(SGMatrix<char>* param, const char* name,
1258  const char* description)
1259 {
1260  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_CHAR, &param->num_rows,
1261  &param->num_cols);
1262  add_type(&type, &param->matrix, name, description);
1263 }
1264 
1265 void Parameter::add(SGMatrix<int8_t>* param, const char* name,
1266  const char* description)
1267 {
1268  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_INT8, &param->num_rows,
1269  &param->num_cols);
1270  add_type(&type, &param->matrix, name, description);
1271 }
1272 
1273 void Parameter::add(SGMatrix<uint8_t>* param, const char* name,
1274  const char* description)
1275 {
1276  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_UINT8, &param->num_rows,
1277  &param->num_cols);
1278  add_type(&type, &param->matrix, name, description);
1279 }
1280 
1281 void Parameter::add(SGMatrix<int16_t>* param, const char* name,
1282  const char* description)
1283 {
1284  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_INT16, &param->num_rows,
1285  &param->num_cols);
1286  add_type(&type, &param->matrix, name, description);
1287 }
1288 
1289 void Parameter::add(SGMatrix<uint16_t>* param, const char* name,
1290  const char* description)
1291 {
1292  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_UINT16, &param->num_rows,
1293  &param->num_cols);
1294  add_type(&type, &param->matrix, name, description);
1295 }
1296 
1297 void Parameter::add(SGMatrix<int32_t>* param, const char* name,
1298  const char* description)
1299 {
1300  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_INT32, &param->num_rows,
1301  &param->num_cols);
1302  add_type(&type, &param->matrix, name, description);
1303 }
1304 
1305 void Parameter::add(SGMatrix<uint32_t>* param, const char* name,
1306  const char* description)
1307 {
1308  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_UINT32, &param->num_rows,
1309  &param->num_cols);
1310  add_type(&type, &param->matrix, name, description);
1311 }
1312 
1313 void Parameter::add(SGMatrix<int64_t>* param, const char* name,
1314  const char* description)
1315 {
1316  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_INT64, &param->num_rows,
1317  &param->num_cols);
1318  add_type(&type, &param->matrix, name, description);
1319 }
1320 
1321 void Parameter::add(SGMatrix<uint64_t>* param, const char* name,
1322  const char* description)
1323 {
1324  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_UINT64, &param->num_rows,
1325  &param->num_cols);
1326  add_type(&type, &param->matrix, name, description);
1327 }
1328 
1329 void Parameter::add(SGMatrix<float32_t>* param, const char* name,
1330  const char* description)
1331 {
1332  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_FLOAT32, &param->num_rows,
1333  &param->num_cols);
1334  add_type(&type, &param->matrix, name, description);
1335 }
1336 
1337 void Parameter::add(SGMatrix<float64_t>* param, const char* name,
1338  const char* description)
1339 {
1340  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_FLOAT64, &param->num_rows,
1341  &param->num_cols);
1342  add_type(&type, &param->matrix, name, description);
1343 }
1344 
1345 void Parameter::add(SGMatrix<floatmax_t>* param, const char* name,
1346  const char* description)
1347 {
1348  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_FLOATMAX, &param->num_rows,
1349  &param->num_cols);
1350  add_type(&type, &param->matrix, name, description);
1351 }
1352 
1353 void Parameter::add(SGMatrix<CSGObject*>* param, const char* name,
1354  const char* description)
1355 {
1356  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_SGOBJECT, &param->num_rows,
1357  &param->num_cols);
1358  add_type(&type, &param->matrix, name, description);
1359 }
1360 
1361 void Parameter::add(SGMatrix<SGString<bool> >* param, const char* name,
1362  const char* description)
1363 {
1364  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_BOOL, &param->num_rows,
1365  &param->num_cols);
1366  add_type(&type, &param->matrix, name, description);
1367 }
1368 
1369 void Parameter::add(SGMatrix<SGString<char> >* param, const char* name,
1370  const char* description)
1371 {
1372  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_CHAR, &param->num_rows,
1373  &param->num_cols);
1374  add_type(&type, &param->matrix, name, description);
1375 }
1376 
1378  const char* name, const char* description)
1379 {
1380  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_INT8, &param->num_rows,
1381  &param->num_cols);
1382  add_type(&type, &param->matrix, name, description);
1383 }
1384 
1386  const char* name, const char* description)
1387 {
1388  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_UINT8, &param->num_rows,
1389  &param->num_cols);
1390  add_type(&type, &param->matrix, name, description);
1391 }
1392 
1394  const char* name, const char* description)
1395 {
1396  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_INT16, &param->num_rows,
1397  &param->num_cols);
1398  add_type(&type, &param->matrix, name, description);
1399 }
1400 
1402  const char* name, const char* description)
1403 {
1404  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_UINT16, &param->num_rows,
1405  &param->num_cols);
1406  add_type(&type, &param->matrix, name, description);
1407 }
1408 
1410  const char* name, const char* description)
1411 {
1412  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_INT32, &param->num_rows,
1413  &param->num_cols);
1414  add_type(&type, &param->matrix, name, description);
1415 }
1416 
1418  const char* name, const char* description)
1419 {
1420  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_UINT32, &param->num_rows,
1421  &param->num_cols);
1422  add_type(&type, &param->matrix, name, description);
1423 }
1424 
1426  const char* name, const char* description)
1427 {
1428  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_INT64, &param->num_rows,
1429  &param->num_cols);
1430  add_type(&type, &param->matrix, name, description);
1431 }
1432 
1434  const char* name, const char* description)
1435 {
1436  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_UINT64, &param->num_rows,
1437  &param->num_cols);
1438  add_type(&type, &param->matrix, name, description);
1439 }
1440 
1442  const char* name, const char* description)
1443 {
1444  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_FLOAT32, &param->num_rows,
1445  &param->num_cols);
1446  add_type(&type, &param->matrix, name, description);
1447 }
1448 
1450  const char* name, const char* description)
1451 {
1452  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_FLOAT64, &param->num_rows,
1453  &param->num_cols);
1454  add_type(&type, &param->matrix, name, description);
1455 }
1456 
1458  const char* name, const char* description)
1459 {
1460  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_FLOATMAX, &param->num_rows,
1461  &param->num_cols);
1462  add_type(&type, &param->matrix, name, description);
1463 }
1464 
1466  const char* name, const char* description)
1467 {
1468  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_BOOL, &param->num_rows,
1469  &param->num_cols);
1470  add_type(&type, &param->matrix, name, description);
1471 }
1472 
1474  const char* name, const char* description)
1475 {
1476  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_CHAR, &param->num_rows,
1477  &param->num_cols);
1478  add_type(&type, &param->matrix, name, description);
1479 }
1480 
1482  const char* name, const char* description)
1483 {
1484  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT8, &param->num_rows,
1485  &param->num_cols);
1486  add_type(&type, &param->matrix, name, description);
1487 }
1488 
1490  const char* name, const char* description)
1491 {
1492  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT8, &param->num_rows,
1493  &param->num_cols);
1494  add_type(&type, &param->matrix, name, description);
1495 }
1496 
1498  const char* name, const char* description)
1499 {
1500  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT16, &param->num_rows,
1501  &param->num_cols);
1502  add_type(&type, &param->matrix, name, description);
1503 }
1504 
1506  const char* name, const char* description)
1507 {
1508  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT16, &param->num_rows,
1509  &param->num_cols);
1510  add_type(&type, &param->matrix, name, description);
1511 }
1512 
1514  const char* name, const char* description)
1515 {
1516  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT32, &param->num_rows,
1517  &param->num_cols);
1518  add_type(&type, &param->matrix, name, description);
1519 }
1520 
1522  const char* name, const char* description)
1523 {
1524  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT32, &param->num_rows,
1525  &param->num_cols);
1526  add_type(&type, &param->matrix, name, description);
1527 }
1528 
1530  const char* name, const char* description)
1531 {
1532  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT64, &param->num_rows,
1533  &param->num_cols);
1534  add_type(&type, &param->matrix, name, description);
1535 }
1536 
1538  const char* name, const char* description)
1539 {
1540  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT64, &param->num_rows,
1541  &param->num_cols);
1542  add_type(&type, &param->matrix, name, description);
1543 }
1544 
1546  const char* name, const char* description)
1547 {
1548  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOAT32, &param->num_rows,
1549  &param->num_cols);
1550  add_type(&type, &param->matrix, name, description);
1551 }
1552 
1554  const char* name, const char* description)
1555 {
1556  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOAT64, &param->num_rows,
1557  &param->num_cols);
1558  add_type(&type, &param->matrix, name, description);
1559 }
1560 
1562  const char* name, const char* description)
1563 {
1564  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOATMAX, &param->num_rows,
1565  &param->num_cols);
1566  add_type(&type, &param->matrix, name, description);
1567 }
1568 /* **************************************************************** */
1569 /* End of wrappers */
1570 
1571 TParameter::TParameter(const TSGDataType* datatype, void* parameter,
1572  const char* name, const char* description)
1573  :m_datatype(*datatype)
1574 {
1575  m_parameter = parameter;
1576  m_name = strdup(name);
1577  m_description = strdup(description);
1578  m_delete_data=false;
1580 }
1581 
1583 {
1584 // SG_SDEBUG("entering ~TParameter for \"%s\"\n", m_name);
1586  SG_FREE(m_name);
1587 
1588  /* possibly delete content, m_parameter variable */
1590  {
1591  SG_SDEBUG("deleting from scratch data\n");
1592 
1593  if (m_delete_data)
1594  {
1595  /* for non-scalar data, delete_cont does the job, rest is handled
1596  * below */
1597  SG_SDEBUG("deleting pure data\n");
1598  if (m_datatype.m_ctype!=CT_SCALAR)
1599  delete_cont();
1600 
1601  if (m_datatype.m_ctype==CT_SCALAR && m_datatype.m_ptype==PT_SGOBJECT)
1603  }
1604 
1605  /* free pointer/data */
1606  if (m_parameter)
1607  {
1608  SG_SDEBUG("freeing m_parameter pointer/data at %p\n", m_parameter);
1610  }
1611 
1612  /* free lengths */
1613  if (m_datatype.m_length_x)
1615 
1616  if (m_datatype.m_length_y)
1618  }
1619 
1620 // SG_SDEBUG("leaving ~TParameter\n");
1621 }
1622 
1623 char*
1624 TParameter::new_prefix(const char* s1, const char* s2)
1625 {
1626  char* tmp = SG_MALLOC(char, strlen(s1)+strlen(s2)+2);
1627 
1628  sprintf(tmp, "%s%s/", s1, s2);
1629 
1630  return tmp;
1631 }
1632 
1633 void
1634 TParameter::print(const char* prefix)
1635 {
1636  string_t buf;
1638 
1639  SG_SPRINT("\n%s\n%35s %24s :%s\n", prefix, m_description == NULL
1640  || *m_description == '\0' ? "(Parameter)": m_description,
1641  m_name, buf);
1642 
1643  if (m_datatype.m_ptype == PT_SGOBJECT
1644  && m_datatype.m_stype == ST_NONE
1645  && m_datatype.m_ctype == CT_SCALAR
1646  && *(CSGObject**) m_parameter != NULL) {
1647  char* p = new_prefix(prefix, m_name);
1648  (*(CSGObject**) m_parameter)->print_serializable(p);
1649  delete p;
1650  }
1651 }
1652 
1653 void
1654 TParameter::delete_cont()
1655 {
1656  if (*(void**) m_parameter != NULL) {
1657  index_t old_length = m_datatype.m_length_y ? *m_datatype.m_length_y : 0;
1658  switch (m_datatype.m_ctype) {
1659  case CT_NDARRAY:
1661  case CT_MATRIX: case CT_SGMATRIX:
1662  old_length *= *m_datatype.m_length_x; break;
1663  case CT_SCALAR: case CT_VECTOR: case CT_SGVECTOR: break;
1664  }
1665 
1666  switch (m_datatype.m_stype) {
1667  case ST_NONE:
1668  switch (m_datatype.m_ptype) {
1669  case PT_BOOL:
1670  SG_FREE(*(bool**) m_parameter); break;
1671  case PT_CHAR:
1672  SG_FREE(*(char**) m_parameter); break;
1673  case PT_INT8:
1674  SG_FREE(*(int8_t**) m_parameter); break;
1675  case PT_UINT8:
1676  SG_FREE(*(uint8_t**) m_parameter); break;
1677  case PT_INT16:
1678  SG_FREE(*(int16_t**) m_parameter); break;
1679  case PT_UINT16:
1680  SG_FREE(*(uint16_t**) m_parameter); break;
1681  case PT_INT32:
1682  SG_FREE(*(int32_t**) m_parameter); break;
1683  case PT_UINT32:
1684  SG_FREE(*(uint32_t**) m_parameter); break;
1685  case PT_INT64:
1686  SG_FREE(*(int64_t**) m_parameter); break;
1687  case PT_UINT64:
1688  SG_FREE(*(uint64_t**) m_parameter); break;
1689  case PT_FLOAT32:
1690  SG_FREE(*(float32_t**) m_parameter); break;
1691  case PT_FLOAT64:
1692  SG_FREE(*(float64_t**) m_parameter); break;
1693  case PT_FLOATMAX:
1694  SG_FREE(*(floatmax_t**) m_parameter); break;
1695  case PT_SGOBJECT:
1696  CSGObject** buf =
1697  *(CSGObject***) m_parameter;
1698  for (index_t i=0; i<old_length; i++)
1699  if (buf[i] != NULL) SG_UNREF(buf[i]);
1700 
1701  SG_FREE(buf);
1702  break;
1703  }
1704  break;
1705  case ST_STRING:
1706  for (index_t i=0; i<old_length; i++) {
1707  SGString<char>* buf = (SGString<char>*) (*(char**)
1709  if (buf->slen > 0) SG_FREE(buf->string);
1710  }
1711 
1712  switch (m_datatype.m_ptype) {
1713  case PT_BOOL:
1714  SG_FREE(*(SGString<bool>**) m_parameter); break;
1715  case PT_CHAR:
1716  SG_FREE(*(SGString<char>**) m_parameter); break;
1717  case PT_INT8:
1718  SG_FREE(*(SGString<int8_t>**) m_parameter); break;
1719  case PT_UINT8:
1720  SG_FREE(*(SGString<uint8_t>**) m_parameter); break;
1721  case PT_INT16:
1722  SG_FREE(*(SGString<int16_t>**) m_parameter); break;
1723  case PT_UINT16:
1724  SG_FREE(*(SGString<uint16_t>**) m_parameter); break;
1725  case PT_INT32:
1726  SG_FREE(*(SGString<int32_t>**) m_parameter); break;
1727  case PT_UINT32:
1728  SG_FREE(*(SGString<uint32_t>**) m_parameter); break;
1729  case PT_INT64:
1730  SG_FREE(*(SGString<int64_t>**) m_parameter); break;
1731  case PT_UINT64:
1732  SG_FREE(*(SGString<uint64_t>**) m_parameter); break;
1733  case PT_FLOAT32:
1735  case PT_FLOAT64:
1737  case PT_FLOATMAX:
1739  case PT_SGOBJECT:
1740  SG_SERROR("TParameter::delete_cont(): Implementation "
1741  "error: Could not delete "
1742  "String<SGSerializable*>");
1743  break;
1744  }
1745  break;
1746  case ST_SPARSE:
1747  for (index_t i=0; i<old_length; i++) {
1748  SGSparseVector<char>* buf = (SGSparseVector<char>*) (*(char**)
1750  if (buf->num_feat_entries > 0) SG_FREE(buf->features);
1751  }
1752 
1753  switch (m_datatype.m_ptype) {
1754  case PT_BOOL:
1756  case PT_CHAR:
1758  case PT_INT8:
1760  case PT_UINT8:
1762  case PT_INT16:
1764  case PT_UINT16:
1766  case PT_INT32:
1768  case PT_UINT32:
1770  case PT_INT64:
1772  case PT_UINT64:
1774  case PT_FLOAT32:
1776  case PT_FLOAT64:
1778  case PT_FLOATMAX:
1780  case PT_SGOBJECT:
1781  SG_SERROR("TParameter::delete_cont(): Implementation "
1782  "error: Could not delete "
1783  "Sparse<SGSerializable*>");
1784  break;
1785  }
1786  break;
1787  } /* switch (m_datatype.m_stype) */
1788  } /* if (*(void**) m_parameter != NULL) */
1789 
1790  *(void**) m_parameter = NULL;
1791 }
1792 
1793 void
1794 TParameter::new_cont(index_t new_len_y, index_t new_len_x)
1795 {
1796  char* s=SG_MALLOC(char, 200);
1797  m_datatype.to_string(s, 200);
1798  SG_SDEBUG("entering TParameter::new_cont(%d, %d) for \"%s\" of type %s\n",
1799  new_len_y, new_len_x, s, m_name ? m_name : "(nil)");
1800  SG_FREE(s);
1801  delete_cont();
1802 
1803  index_t new_length = new_len_y*new_len_x;
1804  if (new_length == 0) return;
1805 
1806  switch (m_datatype.m_stype) {
1807  case ST_NONE:
1808  switch (m_datatype.m_ptype) {
1809  case PT_BOOL:
1810  *(bool**) m_parameter
1811  = SG_MALLOC(bool, new_length); break;
1812  case PT_CHAR:
1813  *(char**) m_parameter
1814  = SG_MALLOC(char, new_length); break;
1815  case PT_INT8:
1816  *(int8_t**) m_parameter
1817  = SG_MALLOC(int8_t, new_length); break;
1818  case PT_UINT8:
1819  *(uint8_t**) m_parameter
1820  = SG_MALLOC(uint8_t, new_length); break;
1821  case PT_INT16:
1822  *(int16_t**) m_parameter
1823  = SG_MALLOC(int16_t, new_length); break;
1824  case PT_UINT16:
1825  *(uint16_t**) m_parameter
1826  = SG_MALLOC(uint16_t, new_length); break;
1827  case PT_INT32:
1828  *(int32_t**) m_parameter
1829  = SG_MALLOC(int32_t, new_length); break;
1830  case PT_UINT32:
1831  *(uint32_t**) m_parameter
1832  = SG_MALLOC(uint32_t, new_length); break;
1833  case PT_INT64:
1834  *(int64_t**) m_parameter
1835  = SG_MALLOC(int64_t, new_length); break;
1836  case PT_UINT64:
1837  *(uint64_t**) m_parameter
1838  = SG_MALLOC(uint64_t, new_length); break;
1839  case PT_FLOAT32:
1840  *(float32_t**) m_parameter
1841  = SG_MALLOC(float32_t, new_length); break;
1842  case PT_FLOAT64:
1843  *(float64_t**) m_parameter
1844  = SG_MALLOC(float64_t, new_length); break;
1845  case PT_FLOATMAX:
1846  *(floatmax_t**) m_parameter
1847  = SG_MALLOC(floatmax_t, new_length); break;
1848  case PT_SGOBJECT:
1849  *(CSGObject***) m_parameter
1850  = SG_CALLOC(CSGObject*, new_length);
1851  break;
1852  }
1853  break;
1854  case ST_STRING:
1855  switch (m_datatype.m_ptype) {
1856  case PT_BOOL:
1858  = SG_MALLOC(SGString<bool>, new_length); break;
1859  case PT_CHAR:
1861  = SG_MALLOC(SGString<char>, new_length); break;
1862  case PT_INT8:
1864  = SG_MALLOC(SGString<int8_t>, new_length); break;
1865  case PT_UINT8:
1867  = SG_MALLOC(SGString<uint8_t>, new_length); break;
1868  case PT_INT16:
1870  = SG_MALLOC(SGString<int16_t>, new_length); break;
1871  case PT_UINT16:
1873  = SG_MALLOC(SGString<uint16_t>, new_length); break;
1874  case PT_INT32:
1876  = SG_MALLOC(SGString<int32_t>, new_length); break;
1877  case PT_UINT32:
1879  = SG_MALLOC(SGString<uint32_t>, new_length); break;
1880  case PT_INT64:
1882  = SG_MALLOC(SGString<int64_t>, new_length); break;
1883  case PT_UINT64:
1885  = SG_MALLOC(SGString<uint64_t>, new_length); break;
1886  case PT_FLOAT32:
1888  = SG_MALLOC(SGString<float32_t>, new_length); break;
1889  case PT_FLOAT64:
1891  = SG_MALLOC(SGString<float64_t>, new_length); break;
1892  case PT_FLOATMAX:
1894  = SG_MALLOC(SGString<floatmax_t>, new_length); break;
1895  case PT_SGOBJECT:
1896  SG_SERROR("TParameter::new_cont(): Implementation "
1897  "error: Could not allocate "
1898  "String<SGSerializable*>");
1899  break;
1900  }
1901  memset(*(void**) m_parameter, 0, new_length
1903  break;
1904  case ST_SPARSE:
1905  switch (m_datatype.m_ptype) {
1906  case PT_BOOL:
1908  = SG_MALLOC(SGSparseVector<bool>, new_length); break;
1909  case PT_CHAR:
1911  = SG_MALLOC(SGSparseVector<char>, new_length); break;
1912  case PT_INT8:
1914  = SG_MALLOC(SGSparseVector<int8_t>, new_length); break;
1915  case PT_UINT8:
1917  = SG_MALLOC(SGSparseVector<uint8_t>, new_length); break;
1918  case PT_INT16:
1920  = SG_MALLOC(SGSparseVector<int16_t>, new_length); break;
1921  case PT_UINT16:
1923  = SG_MALLOC(SGSparseVector<uint16_t>, new_length); break;
1924  case PT_INT32:
1926  = SG_MALLOC(SGSparseVector<int32_t>, new_length); break;
1927  case PT_UINT32:
1929  = SG_MALLOC(SGSparseVector<uint32_t>, new_length); break;
1930  case PT_INT64:
1932  = SG_MALLOC(SGSparseVector<int64_t>, new_length); break;
1933  case PT_UINT64:
1935  = SG_MALLOC(SGSparseVector<uint64_t>, new_length); break;
1936  case PT_FLOAT32:
1938  = SG_MALLOC(SGSparseVector<float32_t>, new_length); break;
1939  case PT_FLOAT64:
1941  = SG_MALLOC(SGSparseVector<float64_t>, new_length); break;
1942  case PT_FLOATMAX:
1944  = SG_MALLOC(SGSparseVector<floatmax_t>, new_length); break;
1945  case PT_SGOBJECT:
1946  SG_SERROR("TParameter::new_cont(): Implementation "
1947  "error: Could not allocate "
1948  "Sparse<SGSerializable*>");
1949  break;
1950  }
1951  memset(*(void**) m_parameter, 0, new_length
1953  break;
1954  } /* switch (m_datatype.m_stype) */
1955 
1956  s=SG_MALLOC(char, 200);
1957  m_datatype.to_string(s, 200);
1958  SG_SDEBUG("leaving TParameter::new_cont(%d, %d) for \"%s\" of type %s\n",
1959  new_len_y, new_len_x, s, m_name ? m_name : "(nil)");
1960  SG_FREE(s);
1961 }
1962 
1963 bool
1964 TParameter::new_sgserial(CSGObject** param,
1965  EPrimitiveType generic,
1966  const char* sgserializable_name,
1967  const char* prefix)
1968 {
1969  if (*param != NULL)
1970  SG_UNREF(*param);
1971 
1972  *param = new_sgserializable(sgserializable_name, generic);
1973 
1974  if (*param == NULL) {
1975  string_t buf = {'\0'};
1976 
1977  if (generic != PT_NOT_GENERIC) {
1978  buf[0] = '<';
1979  TSGDataType::ptype_to_string(buf+1, generic,
1980  STRING_LEN - 3);
1981  strcat(buf, ">");
1982  }
1983 
1984  SG_SWARNING("TParameter::new_sgserial(): "
1985  "Class `C%s%s' was not listed during compiling Shogun"
1986  " :( ... Can not construct it for `%s%s'!",
1987  sgserializable_name, buf, prefix, m_name);
1988 
1989  return false;
1990  }
1991 
1992  SG_REF(*param);
1993  return true;
1994 }
1995 
1996 bool
1997 TParameter::save_ptype(CSerializableFile* file, const void* param,
1998  const char* prefix)
1999 {
2000  if (m_datatype.m_ptype == PT_SGOBJECT) {
2001  const char* sgserial_name = "";
2002  EPrimitiveType generic = PT_NOT_GENERIC;
2003 
2004  if (*(CSGObject**) param != NULL) {
2005  sgserial_name = (*(CSGObject**) param)->get_name();
2006  (*(CSGObject**) param)->is_generic(&generic);
2007  }
2008 
2009  if (!file->write_sgserializable_begin(
2010  &m_datatype, m_name, prefix, sgserial_name, generic))
2011  return false;
2012  if (*sgserial_name != '\0') {
2013  char* p = new_prefix(prefix, m_name);
2014  bool result = (*(CSGObject**) param)
2015  ->save_serializable(file, p);
2016  delete p;
2017  if (!result) return false;
2018  }
2019  if (!file->write_sgserializable_end(
2020  &m_datatype, m_name, prefix, sgserial_name, generic))
2021  return false;
2022  } else
2023  if (!file->write_scalar(&m_datatype, m_name, prefix,
2024  param)) return false;
2025 
2026  return true;
2027 }
2028 
2029 bool
2030 TParameter::load_ptype(CSerializableFile* file, void* param,
2031  const char* prefix)
2032 {
2033  if (m_datatype.m_ptype == PT_SGOBJECT) {
2034  string_t sgserial_name = {'\0'};
2035  EPrimitiveType generic = PT_NOT_GENERIC;
2036 
2037  if (!file->read_sgserializable_begin(
2038  &m_datatype, m_name, prefix, sgserial_name, &generic))
2039  return false;
2040  if (*sgserial_name != '\0') {
2041  if (!new_sgserial((CSGObject**) param, generic,
2042  sgserial_name, prefix))
2043  return false;
2044 
2045  char* p = new_prefix(prefix, m_name);
2046  bool result = (*(CSGObject**) param)
2047  ->load_serializable(file, p);
2048  delete p;
2049  if (!result) return false;
2050  }
2051  if (!file->read_sgserializable_end(
2052  &m_datatype, m_name, prefix, sgserial_name, generic))
2053  return false;
2054  } else
2055  if (!file->read_scalar(&m_datatype, m_name, prefix,
2056  param)) return false;
2057 
2058  return true;
2059 }
2060 
2061 bool
2062 TParameter::save_stype(CSerializableFile* file, const void* param,
2063  const char* prefix)
2064 {
2065  SGString<char>* str_ptr = (SGString<char>*) param;
2066  SGSparseVector<char>* spr_ptr = (SGSparseVector<char>*) param;
2067  index_t len_real;
2068 
2069  switch (m_datatype.m_stype) {
2070  case ST_NONE:
2071  if (!save_ptype(file, param, prefix)) return false;
2072  break;
2073  case ST_STRING:
2074  len_real = str_ptr->slen;
2075  if (str_ptr->string == NULL && len_real != 0) {
2076  SG_SWARNING("Inconsistency between data structure and "
2077  "len during saving string `%s%s'! Continuing"
2078  " with len=0.\n",
2079  prefix, m_name);
2080  len_real = 0;
2081  }
2082  if (!file->write_string_begin(
2083  &m_datatype, m_name, prefix, len_real)) return false;
2084  for (index_t i=0; i<len_real; i++) {
2085  if (!file->write_stringentry_begin(
2086  &m_datatype, m_name, prefix, i)) return false;
2087  if (!save_ptype(file, (char*) str_ptr->string
2088  + i *m_datatype.sizeof_ptype(), prefix))
2089  return false;
2090  if (!file->write_stringentry_end(
2091  &m_datatype, m_name, prefix, i)) return false;
2092  }
2093  if (!file->write_string_end(
2094  &m_datatype, m_name, prefix, len_real)) return false;
2095  break;
2096  case ST_SPARSE:
2097  len_real = spr_ptr->num_feat_entries;
2098  if (spr_ptr->features == NULL && len_real != 0) {
2099  SG_SWARNING("Inconsistency between data structure and "
2100  "len during saving sparse `%s%s'! Continuing"
2101  " with len=0.\n",
2102  prefix, m_name);
2103  len_real = 0;
2104  }
2105  if (!file->write_sparse_begin(
2106  &m_datatype, m_name, prefix, len_real)) return false;
2107  for (index_t i=0; i<len_real; i++) {
2109  ((char*) spr_ptr->features + i *TSGDataType
2111  if (!file->write_sparseentry_begin(
2112  &m_datatype, m_name, prefix, spr_ptr->features,
2113  cur->feat_index, i)) return false;
2114  if (!save_ptype(file, (char*) cur + TSGDataType
2115  ::offset_sparseentry(m_datatype.m_ptype),
2116  prefix)) return false;
2117  if (!file->write_sparseentry_end(
2118  &m_datatype, m_name, prefix, spr_ptr->features,
2119  cur->feat_index, i)) return false;
2120  }
2121  if (!file->write_sparse_end(
2122  &m_datatype, m_name, prefix, len_real)) return false;
2123  break;
2124  }
2125 
2126  return true;
2127 }
2128 
2129 bool
2130 TParameter::load_stype(CSerializableFile* file, void* param,
2131  const char* prefix)
2132 {
2133  SGString<char>* str_ptr = (SGString<char>*) param;
2134  SGSparseVector<char>* spr_ptr = (SGSparseVector<char>*) param;
2135  index_t len_real = 0;
2136 
2137  switch (m_datatype.m_stype) {
2138  case ST_NONE:
2139  if (!load_ptype(file, param, prefix)) return false;
2140  break;
2141  case ST_STRING:
2142  if (!file->read_string_begin(
2143  &m_datatype, m_name, prefix, &len_real))
2144  return false;
2145  str_ptr->string = len_real > 0
2146  ? SG_MALLOC(char, len_real*m_datatype.sizeof_ptype()): NULL;
2147  for (index_t i=0; i<len_real; i++) {
2148  if (!file->read_stringentry_begin(
2149  &m_datatype, m_name, prefix, i)) return false;
2150  if (!load_ptype(file, (char*) str_ptr->string
2151  + i *m_datatype.sizeof_ptype(), prefix))
2152  return false;
2153  if (!file->read_stringentry_end(
2154  &m_datatype, m_name, prefix, i)) return false;
2155  }
2156  if (!file->read_string_end(
2157  &m_datatype, m_name, prefix, len_real))
2158  return false;
2159  str_ptr->slen = len_real;
2160  break;
2161  case ST_SPARSE:
2162  if (!file->read_sparse_begin(
2163  &m_datatype, m_name, prefix, &len_real)) return false;
2164  spr_ptr->features = len_real > 0? (SGSparseVectorEntry<char>*)
2166  m_datatype.m_ptype)): NULL;
2167  for (index_t i=0; i<len_real; i++) {
2169  ((char*) spr_ptr->features + i *TSGDataType
2171  if (!file->read_sparseentry_begin(
2172  &m_datatype, m_name, prefix, spr_ptr->features,
2173  &cur->feat_index, i)) return false;
2174  if (!load_ptype(file, (char*) cur + TSGDataType
2175  ::offset_sparseentry(m_datatype.m_ptype),
2176  prefix)) return false;
2177  if (!file->read_sparseentry_end(
2178  &m_datatype, m_name, prefix, spr_ptr->features,
2179  &cur->feat_index, i)) return false;
2180  }
2181 
2182  if (!file->read_sparse_end(&m_datatype, m_name, prefix, len_real))
2183  return false;
2184 
2185  spr_ptr->num_feat_entries = len_real;
2186  break;
2187  }
2188 
2189  return true;
2190 }
2191 
2193  uint32_t& hash, uint32_t& carry, uint32_t& total_length)
2194 {
2195 
2196  switch (m_datatype.m_ctype)
2197  {
2198  case CT_NDARRAY:
2200  case CT_SCALAR:
2201  {
2202  uint8_t* data = ((uint8_t*) m_parameter);
2203  uint32_t size = m_datatype.sizeof_stype();
2204  total_length += size;
2206  &hash, &carry, data, size);
2207  break;
2208  }
2209  case CT_VECTOR: case CT_MATRIX: case CT_SGVECTOR: case CT_SGMATRIX:
2210  index_t len_real_y = 0, len_real_x = 0;
2211 
2212  if (m_datatype.m_length_y)
2213  len_real_y = *m_datatype.m_length_y;
2214 
2215  else
2216  len_real_y = 1;
2217 
2218  if (*(void**) m_parameter == NULL && len_real_y != 0)
2219  {
2220  SG_SWARNING("Inconsistency between data structure and "
2221  "len_y during hashing `%s'! Continuing with "
2222  "len_y=0.\n",
2223  m_name);
2224  len_real_y = 0;
2225  }
2226 
2227  switch (m_datatype.m_ctype)
2228  {
2229  case CT_NDARRAY:
2231  break;
2232  case CT_VECTOR: case CT_SGVECTOR:
2233  len_real_x = 1;
2234  break;
2235  case CT_MATRIX: case CT_SGMATRIX:
2236  len_real_x = *m_datatype.m_length_x;
2237 
2238  if (*(void**) m_parameter == NULL && len_real_x != 0)
2239  {
2240  SG_SWARNING("Inconsistency between data structure and "
2241  "len_x during hashing %s'! Continuing "
2242  "with len_x=0.\n",
2243  m_name);
2244  len_real_x = 0;
2245  }
2246 
2247  if (len_real_x *len_real_y == 0)
2248  len_real_x = len_real_y = 0;
2249 
2250  break;
2251 
2252  case CT_SCALAR: break;
2253  }
2254  uint32_t size = (len_real_x*len_real_y)*m_datatype.sizeof_stype();
2255 
2256  total_length += size;
2257 
2258  uint8_t* data = (*(uint8_t**) m_parameter);
2259 
2261  &hash, &carry, data, size);
2262  break;
2263  }
2264 }
2265 
2266 bool
2267 TParameter::save(CSerializableFile* file, const char* prefix)
2268 {
2269  const int32_t buflen=100;
2270  char* buf=SG_MALLOC(char, buflen);
2271  m_datatype.to_string(buf, buflen);
2272  SG_SDEBUG("Saving parameter '%s' of type '%s'\n", m_name, buf);
2273  SG_FREE(buf);
2274 
2275  if (!file->write_type_begin(&m_datatype, m_name, prefix))
2276  return false;
2277 
2278  switch (m_datatype.m_ctype) {
2279  case CT_NDARRAY:
2281  case CT_SCALAR:
2282  if (!save_stype(file, m_parameter, prefix)) return false;
2283  break;
2284  case CT_VECTOR: case CT_MATRIX: case CT_SGVECTOR: case CT_SGMATRIX:
2285  index_t len_real_y = 0, len_real_x = 0;
2286 
2287  len_real_y = *m_datatype.m_length_y;
2288  if (*(void**) m_parameter == NULL && len_real_y != 0) {
2289  SG_SWARNING("Inconsistency between data structure and "
2290  "len_y during saving `%s%s'! Continuing with "
2291  "len_y=0.\n",
2292  prefix, m_name);
2293  len_real_y = 0;
2294  }
2295 
2296  switch (m_datatype.m_ctype) {
2297  case CT_NDARRAY:
2299  break;
2300  case CT_VECTOR: case CT_SGVECTOR:
2301  len_real_x = 1;
2302  break;
2303  case CT_MATRIX: case CT_SGMATRIX:
2304  len_real_x = *m_datatype.m_length_x;
2305  if (*(void**) m_parameter == NULL && len_real_x != 0) {
2306  SG_SWARNING("Inconsistency between data structure and "
2307  "len_x during saving `%s%s'! Continuing "
2308  "with len_x=0.\n",
2309  prefix, m_name);
2310  len_real_x = 0;
2311  }
2312 
2313  if (len_real_x *len_real_y == 0)
2314  len_real_x = len_real_y = 0;
2315 
2316  break;
2317  case CT_SCALAR: break;
2318  }
2319 
2320  if (!file->write_cont_begin(&m_datatype, m_name, prefix,
2321  len_real_y, len_real_x))
2322  return false;
2323 
2324  /* ******************************************************** */
2325 
2326  for (index_t x=0; x<len_real_x; x++)
2327  for (index_t y=0; y<len_real_y; y++) {
2328  if (!file->write_item_begin(
2329  &m_datatype, m_name, prefix, y, x))
2330  return false;
2331 
2332  if (!save_stype(
2333  file, (*(char**) m_parameter)
2334  + (x*len_real_y + y)*m_datatype.sizeof_stype(),
2335  prefix)) return false;
2336  if (!file->write_item_end(
2337  &m_datatype, m_name, prefix, y, x))
2338  return false;
2339  }
2340 
2341  /* ******************************************************** */
2342 
2343  if (!file->write_cont_end(&m_datatype, m_name, prefix,
2344  len_real_y, len_real_x))
2345  return false;
2346 
2347  break;
2348  }
2349 
2350  if (!file->write_type_end(&m_datatype, m_name, prefix))
2351  return false;
2352 
2353  return true;
2354 }
2355 
2356 bool
2357 TParameter::load(CSerializableFile* file, const char* prefix)
2358 {
2359  const int32_t buflen=100;
2360  char* buf=SG_MALLOC(char, buflen);
2361  m_datatype.to_string(buf, buflen);
2362  SG_SDEBUG("Loading parameter '%s' of type '%s'\n", m_name, buf);
2363  SG_FREE(buf);
2364 
2365  if (!file->read_type_begin(&m_datatype, m_name, prefix))
2366  return false;
2367 
2368  switch (m_datatype.m_ctype)
2369  {
2370  case CT_NDARRAY:
2372  case CT_SCALAR:
2373  if (!load_stype(file, m_parameter, prefix))
2374  return false;
2375  break;
2376 
2377  case CT_VECTOR: case CT_MATRIX: case CT_SGVECTOR: case CT_SGMATRIX:
2378  index_t len_read_y = 0, len_read_x = 0;
2379 
2380  if (!file->read_cont_begin(&m_datatype, m_name, prefix,
2381  &len_read_y, &len_read_x))
2382  return false;
2383 
2384  switch (m_datatype.m_ctype)
2385  {
2386  case CT_NDARRAY:
2388  case CT_VECTOR: case CT_SGVECTOR:
2389  len_read_x = 1;
2390  new_cont(len_read_y, len_read_x);
2391  break;
2392  case CT_MATRIX: case CT_SGMATRIX:
2393  new_cont(len_read_y, len_read_x);
2394  break;
2395  case CT_SCALAR:
2396  break;
2397  }
2398 
2399  for (index_t x=0; x<len_read_x; x++)
2400  {
2401  for (index_t y=0; y<len_read_y; y++)
2402  {
2403  if (!file->read_item_begin(
2404  &m_datatype, m_name, prefix, y, x))
2405  return false;
2406 
2407  if (!load_stype(
2408  file, (*(char**) m_parameter)
2409  + (x*len_read_y + y)*m_datatype.sizeof_stype(),
2410  prefix)) return false;
2411  if (!file->read_item_end(
2412  &m_datatype, m_name, prefix, y, x))
2413  return false;
2414  }
2415  }
2416 
2417  switch (m_datatype.m_ctype)
2418  {
2419  case CT_NDARRAY:
2421  case CT_VECTOR: case CT_SGVECTOR:
2422  *m_datatype.m_length_y = len_read_y;
2423  break;
2424  case CT_MATRIX: case CT_SGMATRIX:
2425  *m_datatype.m_length_y = len_read_y;
2426  *m_datatype.m_length_x = len_read_x;
2427  break;
2428  case CT_SCALAR:
2429  break;
2430  }
2431 
2432  if (!file->read_cont_end(&m_datatype, m_name, prefix,
2433  len_read_y, len_read_x))
2434  return false;
2435 
2436  break;
2437  }
2438 
2439  if (!file->read_type_end(&m_datatype, m_name, prefix))
2440  return false;
2441 
2442  return true;
2443 }
2444 
2446 {
2447  SG_REF(sg_io);
2448 }
2449 
2451 {
2452  for (int32_t i=0; i<get_num_parameters(); i++)
2453  delete m_params.get_element(i);
2454 
2455  SG_UNREF(sg_io);
2456 }
2457 
2458 void
2459 Parameter::add_type(const TSGDataType* type, void* param,
2460  const char* name, const char* description)
2461 {
2462  if (name == NULL || *name == '\0')
2463  SG_SERROR("FATAL: Parameter::add_type(): `name' is empty!\n");
2464 
2465  for (int32_t i=0; i<get_num_parameters(); i++)
2466  if (strcmp(m_params.get_element(i)->m_name, name) == 0)
2467  SG_SERROR("FATAL: Parameter::add_type(): "
2468  "Double parameter `%s'!\n", name);
2469 
2471  new TParameter(type, param, name, description)
2472  );
2473 }
2474 
2475 void
2476 Parameter::print(const char* prefix)
2477 {
2478  for (int32_t i=0; i<get_num_parameters(); i++)
2479  m_params.get_element(i)->print(prefix);
2480 }
2481 
2482 bool
2483 Parameter::save(CSerializableFile* file, const char* prefix)
2484 {
2485  for (int32_t i=0; i<get_num_parameters(); i++)
2486  {
2487  if (!m_params.get_element(i)->save(file, prefix))
2488  return false;
2489  }
2490 
2491  return true;
2492 }
2493 
2494 //bool
2495 //Parameter::load(CSerializableFile* file, const char* prefix)
2496 //{
2497 // for (int32_t i=0; i<get_num_parameters(); i++)
2498 // if (!m_params.get_element(i)->load(file, prefix))
2499 // return false;
2500 //
2501 // return true;
2502 //}
2503 
2505 {
2506  /* iterate over parameters in the given list */
2507  for (index_t i=0; i<params->get_num_parameters(); ++i)
2508  {
2509  TParameter* current=params->get_parameter(i);
2510  TSGDataType current_type=current->m_datatype;
2511 
2513 
2514  /* search for own parameter with same name and check types if found */
2515  TParameter* own=NULL;
2516  for (index_t j=0; j<m_params.get_num_elements(); ++j)
2517  {
2518  own=m_params.get_element(j);
2519  if (!strcmp(own->m_name, current->m_name))
2520  {
2521  if (own->m_datatype==current_type)
2522  {
2523  own=m_params.get_element(j);
2524  break;
2525  }
2526  else
2527  {
2528  index_t l=200;
2529  char* given_type=SG_MALLOC(char, l);
2530  char* own_type=SG_MALLOC(char, l);
2531  current->m_datatype.to_string(given_type, l);
2532  own->m_datatype.to_string(own_type, l);
2533  SG_SERROR("given parameter \"%s\" has a different type (%s)"
2534  " than existing one (%s)\n", current->m_name,
2535  given_type, own_type);
2536  SG_FREE(given_type);
2537  SG_FREE(own_type);
2538  }
2539  }
2540  else
2541  own=NULL;
2542  }
2543 
2544  if (!own)
2545  {
2546  SG_SERROR("parameter with name %s does not exist\n",
2547  current->m_name);
2548  }
2549 
2550  /* check if parameter contained CSGobjects (update reference counts) */
2551  if (current_type.m_ptype==PT_SGOBJECT)
2552  {
2553  /* PT_SGOBJECT only occurs for ST_NONE */
2554  if (own->m_datatype.m_stype==ST_NONE)
2555  {
2556  if (own->m_datatype.m_ctype==CT_SCALAR)
2557  {
2558  CSGObject** to_unref=(CSGObject**) own->m_parameter;
2559  CSGObject** to_ref=(CSGObject**) current->m_parameter;
2560 
2561  if ((*to_ref)!=(*to_unref))
2562  {
2563  SG_REF((*to_ref));
2564  SG_UNREF((*to_unref));
2565  }
2566 
2567  }
2568  else
2569  {
2570  /* unref all SGObjects and reference the new ones */
2571  CSGObject*** to_unref=(CSGObject***) own->m_parameter;
2572  CSGObject*** to_ref=(CSGObject***) current->m_parameter;
2573 
2574  for (index_t j=0; j<own->m_datatype.get_num_elements(); ++j)
2575  {
2576  if ((*to_ref)[j]!=(*to_unref)[j])
2577  {
2578  SG_REF(((*to_ref)[j]));
2579  SG_UNREF(((*to_unref)[j]));
2580  }
2581  }
2582  }
2583  }
2584  else
2585  SG_SERROR("primitive type PT_SGOBJECT occurred with structure "
2586  "type other than ST_NONE");
2587  }
2588 
2589  /* construct pointers to the to be copied parameter data */
2590  void* dest=NULL;
2591  void* source=NULL;
2592  if (current_type.m_ctype==CT_SCALAR)
2593  {
2594  /* for scalar values, just copy content the pointer points to */
2595  dest=own->m_parameter;
2596  source=current->m_parameter;
2597 
2598  /* in case of CSGObject, pointers are not equal if CSGObjects are
2599  * equal, so check. For other values, the pointers are equal and
2600  * the not-copying is handled below before the memcpy call */
2601  if (own->m_datatype.m_ptype==PT_SGOBJECT)
2602  {
2603  if (*((CSGObject**)dest) == *((CSGObject**)source))
2604  {
2605  dest=NULL;
2606  source=NULL;
2607  }
2608  }
2609  }
2610  else
2611  {
2612  /* for matrices and vectors, sadly m_parameter has to be
2613  * de-referenced once, because a pointer to the array address is
2614  * saved, but the array address itself has to be copied.
2615  * consequently, for dereferencing, a type distinction is needed */
2616  switch (own->m_datatype.m_ptype)
2617  {
2618  case PT_FLOAT64:
2619  dest=*((float64_t**) own->m_parameter);
2620  source=*((float64_t**) current->m_parameter);
2621  break;
2622  case PT_SGOBJECT:
2623  dest=*((CSGObject**) own->m_parameter);
2624  source=*((CSGObject**) current->m_parameter);
2625  break;
2626  default:
2628  break;
2629  }
2630  }
2631 
2632  /* copy parameter data, size in memory is equal because of same type */
2633  if (dest!=source)
2634  memcpy(dest, source, own->m_datatype.get_size());
2635  }
2636 }
2637 
2639 {
2640  for (index_t i=0; i<params->get_num_parameters(); ++i)
2641  {
2642  TParameter* current=params->get_parameter(i);
2643  add_type(&(current->m_datatype), current->m_parameter, current->m_name,
2644  current->m_description);
2645  }
2646 }
2647 
2648 bool Parameter::contains_parameter(const char* name)
2649 {
2650  for (index_t i=0; i<m_params.get_num_elements(); ++i)
2651  {
2652  if (!strcmp(name, m_params[i]->m_name))
2653  return true;
2654  }
2655 
2656  return false;
2657 }
2658 
2659 bool TParameter::operator==(const TParameter& other) const
2660 {
2661  bool result=true;
2662  result&=!strcmp(m_name, other.m_name);
2663  return result;
2664 }
2665 
2666 bool TParameter::operator<(const TParameter& other) const
2667 {
2668  return strcmp(m_name, other.m_name)<0;
2669 }
2670 
2671 bool TParameter::operator>(const TParameter& other) const
2672 {
2673  return strcmp(m_name, other.m_name)>0;
2674 }
2675 
2677  bool new_cont_call)
2678 {
2679  SG_SDEBUG("entering TParameter::allocate_data_from_scratch(%d,%d) of "
2680  "\"%s\"\n", len_y, len_x, m_name);
2681 
2682  /* set flag to delete all this stuff later on */
2684 
2685  /* length has to be allocated for matrices/vectors */
2686  switch (m_datatype.m_ctype)
2687  {
2688  case CT_VECTOR: case CT_SGVECTOR:
2690  *m_datatype.m_length_y=len_y;
2691  break;
2692  case CT_MATRIX: case CT_SGMATRIX:
2695  *m_datatype.m_length_y=len_y;
2696  *m_datatype.m_length_x=len_x;
2697  break;
2698  case CT_SCALAR:
2699  m_datatype.m_length_x=NULL;
2700  m_datatype.m_length_y=NULL;
2701  break;
2702  case CT_NDARRAY:
2704  }
2705 
2706  /* check if there is no data loss */
2707  if (m_parameter)
2708  SG_SERROR("TParameter::allocate_data_from_scratch must not be called "
2709  "when the underlying TParameter instance already has data.\n");
2710 
2711  /* scalars are treated differently than vectors/matrices. memory has to
2712  * be allocated for the data itself */
2713  if (m_datatype.m_ctype==CT_SCALAR)
2714  {
2715  /* sgobjects are treated differently than the rest */
2716  if (m_datatype.m_ptype!=PT_SGOBJECT)
2717  {
2718  /* for non-sgobject allocate memory because normally they are on
2719  * stack and excluded in the TParameter data allocation.
2720  * Will be deleted by the TParameter destructor */
2722  }
2723  else
2724  {
2725  /* for sgobjects, allocate memory for pointer and set to NULL
2726  * Will be deleted by the TParameter destructor */
2728  *((CSGObject**)m_parameter)=NULL;
2729  }
2730  }
2731  else
2732  {
2733  /* allocate pointer for data pointer */
2734  void** data_p=SG_MALLOC(void*, 1);
2735  *data_p=NULL;
2736 
2737  /* allocate dummy data at the point the above pointer points to
2738  * will be freed by the delete_cont() method of TParameter.
2739  * This is needed because new_cont/delete_cont cannot handle
2740  * non-existing data. Set to NULL to avoid problems */
2741  if (new_cont_call)
2742  {
2743  *data_p=SG_MALLOC(void**, 1);
2744  **(void***)data_p=NULL;
2745  }
2746 
2747  m_parameter=data_p;
2748 
2749  /* perform one data allocation. This may be repeated and therefore
2750  * redundant if load() is called afterwards, however, if one wants
2751  * to write directly to the array data after this call, it is
2752  * necessary */
2753  if (new_cont_call)
2754  new_cont(len_y, len_x);
2755  }
2756 
2757  SG_SDEBUG("leaving TParameter::allocate_data_from_scratch(%d,%d) of "
2758  "\"%s\"\n", len_y, len_x, m_name);
2759 }
2760 
2762 {
2763  SG_SDEBUG("entering TParameter::copy_data for %s\n", m_name);
2764 
2765  /* assert that type is equal */
2769 
2770  /* first delete old data if non-scalar */
2771  if (m_datatype.m_ctype!=CT_SCALAR)
2772  delete_cont();
2773 
2774  /* then copy data in case of numeric scalars, or pointer to data else */
2775  if (m_datatype.m_ctype==CT_SCALAR && m_datatype.m_ptype!=PT_SGOBJECT)
2776  {
2777  /* just copy value behind pointer */
2778  SG_SDEBUG("Copying scalar data of size %d from %p to %p\n",
2780  memcpy(m_parameter, source->m_parameter,
2781  m_datatype.get_size());
2782  }
2783  else
2784  {
2785  /* if this is a sgobject, the old one has to be unrefed */
2786  if (m_datatype.m_ptype==PT_SGOBJECT)
2787  {
2788  if (m_datatype.m_ctype==CT_SCALAR)
2789  {
2791  }
2792  else
2793  {
2794  int32_t length=1;
2795  length*=m_datatype.m_length_x ? *m_datatype.m_length_x : 1;
2796  length*=m_datatype.m_length_y ? *m_datatype.m_length_y : 1;
2797 
2798  for (index_t j=0; j<length; ++j)
2799  {
2800  SG_UNREF(((CSGObject**)(m_parameter))[j]);
2801  }
2802  }
2803  }
2804 
2805  /* in this case, data is a pointer pointing to the actual
2806  * data, so copy pointer if non-NULL*/
2807  SG_SDEBUG("Copying non-scalar pointer %p\n", *((void**)source->m_parameter));
2808  *((void**)m_parameter)=*((void**)source->m_parameter);
2809  }
2810 
2811  /* copy lengths */
2812  if (source->m_datatype.m_length_x)
2814 
2815  if (source->m_datatype.m_length_y)
2817 
2818  SG_SDEBUG("leaving TParameter::copy_data for %s\n", m_name);
2819 }

SHOGUN Machine Learning Toolbox - Documentation