SHOGUN  6.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
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-2013 Heiko Strathmann
9  * Copyright (C) 2010 Berlin Institute of Technology
10  */
11 
12 #include <string.h>
13 #include <cctype>
14 
15 #include <shogun/base/Parameter.h>
16 #include <shogun/base/class_list.h>
17 #include <shogun/lib/Hash.h>
18 #include <shogun/lib/memory.h>
19 #include <shogun/io/SGIO.h>
21 #include <shogun/lib/common.h>
22 #include <shogun/lib/DataType.h>
23 
24 #include <shogun/lib/SGString.h>
25 #include <shogun/lib/SGVector.h>
27 #include <shogun/lib/SGMatrix.h>
30 
31 using namespace shogun;
32 
33 
34 /* **************************************************************** */
35 /* Scalar wrappers */
36 
37 void
38 Parameter::add(bool* param, const char* name,
39  const char* description) {
40  TSGDataType type(CT_SCALAR, ST_NONE, PT_BOOL);
41  add_type(&type, param, name, description);
42 }
43 
44 void
45 Parameter::add(char* param, const char* name,
46  const char* description) {
47  TSGDataType type(CT_SCALAR, ST_NONE, PT_CHAR);
48  add_type(&type, param, name, description);
49 }
50 
51 void
52 Parameter::add(int8_t* param, const char* name,
53  const char* description) {
54  TSGDataType type(CT_SCALAR, ST_NONE, PT_INT8);
55  add_type(&type, param, name, description);
56 }
57 
58 void
59 Parameter::add(uint8_t* param, const char* name,
60  const char* description) {
61  TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT8);
62  add_type(&type, param, name, description);
63 }
64 
65 void
66 Parameter::add(int16_t* param, const char* name,
67  const char* description) {
68  TSGDataType type(CT_SCALAR, ST_NONE, PT_INT16);
69  add_type(&type, param, name, description);
70 }
71 
72 void
73 Parameter::add(uint16_t* param, const char* name,
74  const char* description) {
75  TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT16);
76  add_type(&type, param, name, description);
77 }
78 
79 void
80 Parameter::add(int32_t* param, const char* name,
81  const char* description) {
82  TSGDataType type(CT_SCALAR, ST_NONE, PT_INT32);
83  add_type(&type, param, name, description);
84 }
85 
86 void
87 Parameter::add(uint32_t* param, const char* name,
88  const char* description) {
89  TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT32);
90  add_type(&type, param, name, description);
91 }
92 
93 void
94 Parameter::add(int64_t* param, const char* name,
95  const char* description) {
96  TSGDataType type(CT_SCALAR, ST_NONE, PT_INT64);
97  add_type(&type, param, name, description);
98 }
99 
100 void
101 Parameter::add(uint64_t* param, const char* name,
102  const char* description) {
103  TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT64);
104  add_type(&type, param, name, description);
105 }
106 
107 void
108 Parameter::add(float32_t* param, const char* name,
109  const char* description) {
110  TSGDataType type(CT_SCALAR, ST_NONE, PT_FLOAT32);
111  add_type(&type, param, name, description);
112 }
113 
114 void
115 Parameter::add(float64_t* param, const char* name,
116  const char* description) {
117  TSGDataType type(CT_SCALAR, ST_NONE, PT_FLOAT64);
118  add_type(&type, param, name, description);
119 }
120 
121 void
122 Parameter::add(floatmax_t* param, const char* name,
123  const char* description) {
124  TSGDataType type(CT_SCALAR, ST_NONE, PT_FLOATMAX);
125  add_type(&type, param, name, description);
126 }
127 
128 void
129 Parameter::add(complex128_t* param, const char* name,
130  const char* description) {
131  TSGDataType type(CT_SCALAR, ST_NONE, PT_COMPLEX128);
132  add_type(&type, param, name, description);
133 }
134 
135 void
137  const char* name, const char* description) {
138  TSGDataType type(CT_SCALAR, ST_NONE, PT_SGOBJECT);
139  add_type(&type, param, name, description);
140 }
141 
142 void
143 Parameter::add(SGString<bool>* param, const char* name,
144  const char* description) {
145  TSGDataType type(CT_SCALAR, ST_STRING, PT_BOOL);
146  add_type(&type, param, name, description);
147 }
148 
149 void
150 Parameter::add(SGString<char>* param, const char* name,
151  const char* description) {
152  TSGDataType type(CT_SCALAR, ST_STRING, PT_CHAR);
153  add_type(&type, param, name, description);
154 }
155 
156 void
157 Parameter::add(SGString<int8_t>* param, const char* name,
158  const char* description) {
159  TSGDataType type(CT_SCALAR, ST_STRING, PT_INT8);
160  add_type(&type, param, name, description);
161 }
162 
163 void
164 Parameter::add(SGString<uint8_t>* param, const char* name,
165  const char* description) {
166  TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT8);
167  add_type(&type, param, name, description);
168 }
169 
170 void
171 Parameter::add(SGString<int16_t>* param, const char* name,
172  const char* description) {
173  TSGDataType type(CT_SCALAR, ST_STRING, PT_INT16);
174  add_type(&type, param, name, description);
175 }
176 
177 void
178 Parameter::add(SGString<uint16_t>* param, const char* name,
179  const char* description) {
180  TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT16);
181  add_type(&type, param, name, description);
182 }
183 
184 void
185 Parameter::add(SGString<int32_t>* param, const char* name,
186  const char* description) {
187  TSGDataType type(CT_SCALAR, ST_STRING, PT_INT32);
188  add_type(&type, param, name, description);
189 }
190 
191 void
192 Parameter::add(SGString<uint32_t>* param, const char* name,
193  const char* description) {
194  TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT32);
195  add_type(&type, param, name, description);
196 }
197 
198 void
199 Parameter::add(SGString<int64_t>* param, const char* name,
200  const char* description) {
201  TSGDataType type(CT_SCALAR, ST_STRING, PT_INT64);
202  add_type(&type, param, name, description);
203 }
204 
205 void
206 Parameter::add(SGString<uint64_t>* param, const char* name,
207  const char* description) {
208  TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT64);
209  add_type(&type, param, name, description);
210 }
211 
212 void
213 Parameter::add(SGString<float32_t>* param, const char* name,
214  const char* description) {
215  TSGDataType type(CT_SCALAR, ST_STRING, PT_FLOAT32);
216  add_type(&type, param, name, description);
217 }
218 
219 void
220 Parameter::add(SGString<float64_t>* param, const char* name,
221  const char* description) {
222  TSGDataType type(CT_SCALAR, ST_STRING, PT_FLOAT64);
223  add_type(&type, param, name, description);
224 }
225 
226 void
227 Parameter::add(SGString<floatmax_t>* param, const char* name,
228  const char* description) {
229  TSGDataType type(CT_SCALAR, ST_STRING, PT_FLOATMAX);
230  add_type(&type, param, name, description);
231 }
232 
233 void
234 Parameter::add(SGSparseVector<bool>* param, const char* name,
235  const char* description) {
236  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_BOOL);
237  add_type(&type, param, name, description);
238 }
239 
240 void
241 Parameter::add(SGSparseVector<char>* param, const char* name,
242  const char* description) {
243  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_CHAR);
244  add_type(&type, param, name, description);
245 }
246 
247 void
248 Parameter::add(SGSparseVector<int8_t>* param, const char* name,
249  const char* description) {
250  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT8);
251  add_type(&type, param, name, description);
252 }
253 
254 void
255 Parameter::add(SGSparseVector<uint8_t>* param, const char* name,
256  const char* description) {
257  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT8);
258  add_type(&type, param, name, description);
259 }
260 
261 void
262 Parameter::add(SGSparseVector<int16_t>* param, const char* name,
263  const char* description) {
264  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT16);
265  add_type(&type, param, name, description);
266 }
267 
268 void
269 Parameter::add(SGSparseVector<uint16_t>* param, const char* name,
270  const char* description) {
271  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT16);
272  add_type(&type, param, name, description);
273 }
274 
275 void
276 Parameter::add(SGSparseVector<int32_t>* param, const char* name,
277  const char* description) {
278  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT32);
279  add_type(&type, param, name, description);
280 }
281 
282 void
283 Parameter::add(SGSparseVector<uint32_t>* param, const char* name,
284  const char* description) {
285  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT32);
286  add_type(&type, param, name, description);
287 }
288 
289 void
290 Parameter::add(SGSparseVector<int64_t>* param, const char* name,
291  const char* description) {
292  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT64);
293  add_type(&type, param, name, description);
294 }
295 
296 void
297 Parameter::add(SGSparseVector<uint64_t>* param, const char* name,
298  const char* description) {
299  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT64);
300  add_type(&type, param, name, description);
301 }
302 
303 void
304 Parameter::add(SGSparseVector<float32_t>* param, const char* name,
305  const char* description) {
306  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_FLOAT32);
307  add_type(&type, param, name, description);
308 }
309 
310 void
311 Parameter::add(SGSparseVector<float64_t>* param, const char* name,
312  const char* description) {
313  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_FLOAT64);
314  add_type(&type, param, name, description);
315 }
316 
317 void
319  const char* description) {
320  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_FLOATMAX);
321  add_type(&type, param, name, description);
322 }
323 
324 void
326  const char* description) {
327  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_COMPLEX128);
328  add_type(&type, param, name, description);
329 }
330 
331 /* **************************************************************** */
332 /* Vector wrappers */
333 
334 void
336  bool** param, index_t* length, const char* name,
337  const char* description) {
338  TSGDataType type(CT_VECTOR, ST_NONE, PT_BOOL, length);
339  add_type(&type, param, name, description);
340 }
341 
342 void
344  char** param, index_t* length, const char* name,
345  const char* description) {
346  TSGDataType type(CT_VECTOR, ST_NONE, PT_CHAR, length);
347  add_type(&type, param, name, description);
348 }
349 
350 void
352  int8_t** param, index_t* length, const char* name,
353  const char* description) {
354  TSGDataType type(CT_VECTOR, ST_NONE, PT_INT8, length);
355  add_type(&type, param, name, description);
356 }
357 
358 void
360  uint8_t** param, index_t* length, const char* name,
361  const char* description) {
362  TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT8, length);
363  add_type(&type, param, name, description);
364 }
365 
366 void
368  int16_t** param, index_t* length, const char* name,
369  const char* description) {
370  TSGDataType type(CT_VECTOR, ST_NONE, PT_INT16, length);
371  add_type(&type, param, name, description);
372 }
373 
374 void
376  uint16_t** param, index_t* length, const char* name,
377  const char* description) {
378  TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT16, length);
379  add_type(&type, param, name, description);
380 }
381 
382 void
384  int32_t** param, index_t* length, const char* name,
385  const char* description) {
386  TSGDataType type(CT_VECTOR, ST_NONE, PT_INT32, length);
387  add_type(&type, param, name, description);
388 }
389 
390 void
392  uint32_t** param, index_t* length, const char* name,
393  const char* description) {
394  TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT32, length);
395  add_type(&type, param, name, description);
396 }
397 
398 void
400  int64_t** param, index_t* length, const char* name,
401  const char* description) {
402  TSGDataType type(CT_VECTOR, ST_NONE, PT_INT64, length);
403  add_type(&type, param, name, description);
404 }
405 
406 void
408  uint64_t** param, index_t* length, const char* name,
409  const char* description) {
410  TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT64, length);
411  add_type(&type, param, name, description);
412 }
413 
414 void
416  float32_t** param, index_t* length, const char* name,
417  const char* description) {
418  TSGDataType type(CT_VECTOR, ST_NONE, PT_FLOAT32, length);
419  add_type(&type, param, name, description);
420 }
421 
422 void
424  float64_t** param, index_t* length, const char* name,
425  const char* description) {
426  TSGDataType type(CT_VECTOR, ST_NONE, PT_FLOAT64, length);
427  add_type(&type, param, name, description);
428 }
429 
430 void
432  floatmax_t** param, index_t* length, const char* name,
433  const char* description) {
434  TSGDataType type(CT_VECTOR, ST_NONE, PT_FLOATMAX, length);
435  add_type(&type, param, name, description);
436 }
437 
438 void
440  complex128_t** param, index_t* length, const char* name,
441  const char* description) {
442  TSGDataType type(CT_VECTOR, ST_NONE, PT_COMPLEX128, 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_NONE, PT_SGOBJECT,
450  length);
451  add_type(&type, param, name, description);
452 }
453 
454 void
456  const char* name, const char* description) {
457  TSGDataType type(CT_VECTOR, ST_STRING, PT_BOOL, length);
458  add_type(&type, param, name, description);
459 }
460 
461 void
463  const char* name, const char* description) {
464  TSGDataType type(CT_VECTOR, ST_STRING, PT_CHAR, length);
465  add_type(&type, param, name, description);
466 }
467 
468 void
470  const char* name, const char* description) {
471  TSGDataType type(CT_VECTOR, ST_STRING, PT_INT8, length);
472  add_type(&type, param, name, description);
473 }
474 
475 void
477  const char* name, const char* description) {
478  TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT8, length);
479  add_type(&type, param, name, description);
480 }
481 
482 void
484  const char* name, const char* description) {
485  TSGDataType type(CT_VECTOR, ST_STRING, PT_INT16, length);
486  add_type(&type, param, name, description);
487 }
488 
489 void
491  const char* name, const char* description) {
492  TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT16, length);
493  add_type(&type, param, name, description);
494 }
495 
496 void
498  const char* name, const char* description) {
499  TSGDataType type(CT_VECTOR, ST_STRING, PT_INT32, length);
500  add_type(&type, param, name, description);
501 }
502 
503 void
505  const char* name, const char* description) {
506  TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT32, length);
507  add_type(&type, param, name, description);
508 }
509 
510 void
512  const char* name, const char* description) {
513  TSGDataType type(CT_VECTOR, ST_STRING, PT_INT64, length);
514  add_type(&type, param, name, description);
515 }
516 
517 void
519  const char* name, const char* description) {
520  TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT64, length);
521  add_type(&type, param, name, description);
522 }
523 
524 void
526  const char* name, const char* description) {
527  TSGDataType type(CT_VECTOR, ST_STRING, PT_FLOAT32, length);
528  add_type(&type, param, name, description);
529 }
530 
531 void
533  const char* name, const char* description) {
534  TSGDataType type(CT_VECTOR, ST_STRING, PT_FLOAT64, length);
535  add_type(&type, param, name, description);
536 }
537 
538 void
540  const char* name, const char* description) {
541  TSGDataType type(CT_VECTOR, ST_STRING, PT_FLOATMAX, length);
542  add_type(&type, param, name, description);
543 }
544 
545 void
547  const char* name, const char* description) {
548  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_BOOL, length);
549  add_type(&type, param, name, description);
550 }
551 
552 void
554  const char* name, const char* description) {
555  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_CHAR, length);
556  add_type(&type, param, name, description);
557 }
558 
559 void
561  const char* name, const char* description) {
562  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT8, length);
563  add_type(&type, param, name, description);
564 }
565 
566 void
568  const char* name, const char* description) {
569  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT8, length);
570  add_type(&type, param, name, description);
571 }
572 
573 void
575  const char* name, const char* description) {
576  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT16, length);
577  add_type(&type, param, name, description);
578 }
579 
580 void
582  const char* name, const char* description) {
583  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT16, length);
584  add_type(&type, param, name, description);
585 }
586 
587 void
589  const char* name, const char* description) {
590  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT32, length);
591  add_type(&type, param, name, description);
592 }
593 
594 void
596  const char* name, const char* description) {
597  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT32, length);
598  add_type(&type, param, name, description);
599 }
600 
601 void
603  const char* name, const char* description) {
604  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT64, length);
605  add_type(&type, param, name, description);
606 }
607 
608 void
610  const char* name, const char* description) {
611  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT64, length);
612  add_type(&type, param, name, description);
613 }
614 
615 void
617  const char* name, const char* description) {
618  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_FLOAT32, length);
619  add_type(&type, param, name, description);
620 }
621 
622 void
624  const char* name, const char* description) {
625  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_FLOAT64, length);
626  add_type(&type, param, name, description);
627 }
628 
629 void
631  const char* name, const char* description) {
632  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_FLOATMAX, length);
633  add_type(&type, param, name, description);
634 }
635 
636 void
638  const char* name, const char* description) {
639  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_COMPLEX128, length);
640  add_type(&type, param, name, description);
641 }
642 
643 
644 
645 
646 void Parameter::add(SGVector<bool>* param, const char* name,
647  const char* description)
648 {
649  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_BOOL, &param->vlen);
650  add_type(&type, &param->vector, name, description);
651 }
652 
653 void Parameter::add(SGVector<char>* param, const char* name,
654  const char* description)
655 {
656  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_CHAR, &param->vlen);
657  add_type(&type, &param->vector, name, description);
658 }
659 
660 void Parameter::add(SGVector<int8_t>* param, const char* name,
661  const char* description)
662 {
663  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_INT8, &param->vlen);
664  add_type(&type, &param->vector, name, description);
665 }
666 
667 void Parameter::add(SGVector<uint8_t>* param, const char* name,
668  const char* description)
669 {
670  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_UINT8, &param->vlen);
671  add_type(&type, &param->vector, name, description);
672 }
673 
674 void Parameter::add(SGVector<int16_t>* param, const char* name,
675  const char* description)
676 {
677  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_INT16, &param->vlen);
678  add_type(&type, &param->vector, name, description);
679 }
680 
681 void Parameter::add(SGVector<uint16_t>* param, const char* name,
682  const char* description)
683 {
684  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_UINT16, &param->vlen);
685  add_type(&type, &param->vector, name, description);
686 }
687 
688 void Parameter::add(SGVector<int32_t>* param, const char* name,
689  const char* description)
690 {
691  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_INT32, &param->vlen);
692  add_type(&type, &param->vector, name, description);
693 }
694 
695 void Parameter::add(SGVector<uint32_t>* param, const char* name,
696  const char* description)
697 {
698  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_UINT32, &param->vlen);
699  add_type(&type, &param->vector, name, description);
700 }
701 
702 void Parameter::add(SGVector<int64_t>* param, const char* name,
703  const char* description)
704 {
705  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_INT64, &param->vlen);
706  add_type(&type, &param->vector, name, description);
707 }
708 
709 void Parameter::add(SGVector<uint64_t>* param, const char* name,
710  const char* description)
711 {
712  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_UINT64, &param->vlen);
713  add_type(&type, &param->vector, name, description);
714 }
715 
716 void Parameter::add(SGVector<float32_t>* param, const char* name,
717  const char* description)
718 {
719  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_FLOAT32, &param->vlen);
720  add_type(&type, &param->vector, name, description);
721 }
722 
723 void Parameter::add(SGVector<float64_t>* param, const char* name,
724  const char* description)
725 {
726  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_FLOAT64, &param->vlen);
727  add_type(&type, &param->vector, name, description);
728 }
729 
730 void Parameter::add(SGVector<floatmax_t>* param, const char* name,
731  const char* description)
732 {
733  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_FLOATMAX, &param->vlen);
734  add_type(&type, &param->vector, name, description);
735 }
736 
737 void Parameter::add(SGVector<complex128_t>* param, const char* name,
738  const char* description)
739 {
740  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_COMPLEX128, &param->vlen);
741  add_type(&type, &param->vector, name, description);
742 }
743 
744 void Parameter::add(SGVector<CSGObject*>* param, const char* name,
745  const char* description)
746 {
747  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_SGOBJECT, &param->vlen);
748  add_type(&type, &param->vector, name, description);
749 }
750 
751 void Parameter::add(SGVector<SGString<bool> >* param, const char* name,
752  const char* description)
753 {
754  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_BOOL, &param->vlen);
755  add_type(&type, &param->vector, name, description);
756 }
757 
758 void Parameter::add(SGVector<SGString<char> >* param, const char* name,
759  const char* description)
760 {
761  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_CHAR, &param->vlen);
762  add_type(&type, &param->vector, name, description);
763 }
764 
766  const char* name, const char* description)
767 {
768  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_INT8, &param->vlen);
769  add_type(&type, &param->vector, name, description);
770 }
771 
773  const char* name, const char* description)
774 {
775  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_UINT8, &param->vlen);
776  add_type(&type, &param->vector, name, description);
777 }
778 
780  const char* name, const char* description)
781 {
782  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_INT16, &param->vlen);
783  add_type(&type, &param->vector, name, description);
784 }
785 
787  const char* name, const char* description)
788 {
789  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_UINT16, &param->vlen);
790  add_type(&type, &param->vector, name, description);
791 }
792 
794  const char* name, const char* description)
795 {
796  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_INT32, &param->vlen);
797  add_type(&type, &param->vector, name, description);
798 }
799 
801  const char* name, const char* description)
802 {
803  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_UINT32, &param->vlen);
804  add_type(&type, &param->vector, name, description);
805 }
806 
808  const char* name, const char* description)
809 {
810  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_INT64, &param->vlen);
811  add_type(&type, &param->vector, name, description);
812 }
813 
815  const char* name, const char* description)
816 {
817  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_UINT64, &param->vlen);
818  add_type(&type, &param->vector, name, description);
819 }
820 
822  const char* name, const char* description)
823 {
824  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_FLOAT32, &param->vlen);
825  add_type(&type, &param->vector, name, description);
826 }
827 
829  const char* name, const char* description)
830 {
831  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_FLOAT64, &param->vlen);
832  add_type(&type, &param->vector, name, description);
833 }
834 
836  const char* name, const char* description)
837 {
838  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_FLOATMAX, &param->vlen);
839  add_type(&type, &param->vector, name, description);
840 }
841 
843  const char* name, const char* description)
844 {
845  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_BOOL, &param->vlen);
846  add_type(&type, &param->vector, name, description);
847 }
848 
850  const char* name, const char* description)
851 {
852  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_CHAR, &param->vlen);
853  add_type(&type, &param->vector, name, description);
854 }
855 
857  const char* name, const char* description)
858 {
859  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_INT8, &param->vlen);
860  add_type(&type, &param->vector, name, description);
861 }
862 
864  const char* name, const char* description)
865 {
866  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_UINT8, &param->vlen);
867  add_type(&type, &param->vector, name, description);
868 }
869 
871  const char* name, const char* description)
872 {
873  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_INT16, &param->vlen);
874  add_type(&type, &param->vector, name, description);
875 }
876 
878  const char* name, const char* description)
879 {
880  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_UINT16, &param->vlen);
881  add_type(&type, &param->vector, name, description);
882 }
883 
885  const char* name, const char* description)
886 {
887  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_INT32, &param->vlen);
888  add_type(&type, &param->vector, name, description);
889 }
890 
892  const char* name, const char* description)
893 {
894  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_UINT32, &param->vlen);
895  add_type(&type, &param->vector, name, description);
896 }
897 
899  const char* name, const char* description)
900 {
901  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_INT64, &param->vlen);
902  add_type(&type, &param->vector, name, description);
903 }
904 
906  const char* name, const char* description)
907 {
908  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_UINT64, &param->vlen);
909  add_type(&type, &param->vector, name, description);
910 }
911 
913  const char* name, const char* description)
914 {
915  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_FLOAT32, &param->vlen);
916  add_type(&type, &param->vector, name, description);
917 }
918 
920  const char* name, const char* description)
921 {
922  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_FLOAT64, &param->vlen);
923  add_type(&type, &param->vector, name, description);
924 }
925 
927  const char* name, const char* description)
928 {
929  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_FLOATMAX, &param->vlen);
930  add_type(&type, &param->vector, name, description);
931 }
932 
934  const char* name, const char* description)
935 {
936  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_COMPLEX128, &param->vlen);
937  add_type(&type, &param->vector, name, description);
938 }
939 
940 /* **************************************************************** */
941 /* Matrix wrappers */
942 
943 void
945  bool** param, index_t* length_y, index_t* length_x,
946  const char* name, const char* description) {
947  TSGDataType type(CT_MATRIX, ST_NONE, PT_BOOL, length_y,
948  length_x);
949  add_type(&type, param, name, description);
950 }
951 
952 void
954  char** param, index_t* length_y, index_t* length_x,
955  const char* name, const char* description) {
956  TSGDataType type(CT_MATRIX, ST_NONE, PT_CHAR, length_y,
957  length_x);
958  add_type(&type, param, name, description);
959 }
960 
961 void
963  int8_t** param, index_t* length_y, index_t* length_x,
964  const char* name, const char* description) {
965  TSGDataType type(CT_MATRIX, ST_NONE, PT_INT8, length_y,
966  length_x);
967  add_type(&type, param, name, description);
968 }
969 
970 void
972  uint8_t** param, index_t* length_y, index_t* length_x,
973  const char* name, const char* description) {
974  TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT8, length_y,
975  length_x);
976  add_type(&type, param, name, description);
977 }
978 
979 void
981  int16_t** param, index_t* length_y, index_t* length_x,
982  const char* name, const char* description) {
983  TSGDataType type(CT_MATRIX, ST_NONE, PT_INT16, length_y,
984  length_x);
985  add_type(&type, param, name, description);
986 }
987 
988 void
990  uint16_t** param, index_t* length_y, index_t* length_x,
991  const char* name, const char* description) {
992  TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT16, length_y,
993  length_x);
994  add_type(&type, param, name, description);
995 }
996 
997 void
999  int32_t** param, index_t* length_y, index_t* length_x,
1000  const char* name, const char* description) {
1001  TSGDataType type(CT_MATRIX, ST_NONE, PT_INT32, length_y,
1002  length_x);
1003  add_type(&type, param, name, description);
1004 }
1005 
1006 void
1008  uint32_t** param, index_t* length_y, index_t* length_x,
1009  const char* name, const char* description) {
1010  TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT32, length_y,
1011  length_x);
1012  add_type(&type, param, name, description);
1013 }
1014 
1015 void
1017  int64_t** param, index_t* length_y, index_t* length_x,
1018  const char* name, const char* description) {
1019  TSGDataType type(CT_MATRIX, ST_NONE, PT_INT64, length_y,
1020  length_x);
1021  add_type(&type, param, name, description);
1022 }
1023 
1024 void
1026  uint64_t** param, index_t* length_y, index_t* length_x,
1027  const char* name, const char* description) {
1028  TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT64, length_y,
1029  length_x);
1030  add_type(&type, param, name, description);
1031 }
1032 
1033 void
1035  float32_t** param, index_t* length_y, index_t* length_x,
1036  const char* name, const char* description) {
1037  TSGDataType type(CT_MATRIX, ST_NONE, PT_FLOAT32, length_y,
1038  length_x);
1039  add_type(&type, param, name, description);
1040 }
1041 
1042 void
1044  float64_t** param, index_t* length_y, index_t* length_x,
1045  const char* name, const char* description) {
1046  TSGDataType type(CT_MATRIX, ST_NONE, PT_FLOAT64, length_y,
1047  length_x);
1048  add_type(&type, param, name, description);
1049 }
1050 
1051 void
1053  floatmax_t** param, index_t* length_y, index_t* length_x,
1054  const char* name, const char* description) {
1055  TSGDataType type(CT_MATRIX, ST_NONE, PT_FLOATMAX, length_y,
1056  length_x);
1057  add_type(&type, param, name, description);
1058 }
1059 
1060 void
1062  complex128_t** param, index_t* length_y, index_t* length_x,
1063  const char* name, const char* description) {
1064  TSGDataType type(CT_MATRIX, ST_NONE, PT_COMPLEX128, length_y,
1065  length_x);
1066  add_type(&type, param, name, description);
1067 }
1068 
1069 void
1071  CSGObject*** param, index_t* length_y, index_t* length_x,
1072  const char* name, const char* description) {
1073  TSGDataType type(CT_MATRIX, ST_NONE, PT_SGOBJECT,
1074  length_y, length_x);
1075  add_type(&type, param, name, description);
1076 }
1077 
1078 void
1080  index_t* length_y, index_t* length_x,
1081  const char* name, const char* description) {
1082  TSGDataType type(CT_MATRIX, ST_STRING, PT_BOOL, length_y,
1083  length_x);
1084  add_type(&type, param, name, description);
1085 }
1086 
1087 void
1089  index_t* length_y, index_t* length_x,
1090  const char* name, const char* description) {
1091  TSGDataType type(CT_MATRIX, ST_STRING, PT_CHAR, length_y,
1092  length_x);
1093  add_type(&type, param, name, description);
1094 }
1095 
1096 void
1098  index_t* length_y, index_t* length_x,
1099  const char* name, const char* description) {
1100  TSGDataType type(CT_MATRIX, ST_STRING, PT_INT8, length_y,
1101  length_x);
1102  add_type(&type, param, name, description);
1103 }
1104 
1105 void
1107  index_t* length_y, index_t* length_x,
1108  const char* name, const char* description) {
1109  TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT8, length_y,
1110  length_x);
1111  add_type(&type, param, name, description);
1112 }
1113 
1114 void
1116  index_t* length_y, index_t* length_x,
1117  const char* name, const char* description) {
1118  TSGDataType type(CT_MATRIX, ST_STRING, PT_INT16, length_y,
1119  length_x);
1120  add_type(&type, param, name, description);
1121 }
1122 
1123 void
1125  index_t* length_y, index_t* length_x,
1126  const char* name, const char* description) {
1127  TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT16, length_y,
1128  length_x);
1129  add_type(&type, param, name, description);
1130 }
1131 
1132 void
1134  index_t* length_y, index_t* length_x,
1135  const char* name, const char* description) {
1136  TSGDataType type(CT_MATRIX, ST_STRING, PT_INT32, length_y,
1137  length_x);
1138  add_type(&type, param, name, description);
1139 }
1140 
1141 void
1143  index_t* length_y, index_t* length_x,
1144  const char* name, const char* description) {
1145  TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT32, length_y,
1146  length_x);
1147  add_type(&type, param, name, description);
1148 }
1149 
1150 void
1152  index_t* length_y, index_t* length_x,
1153  const char* name, const char* description) {
1154  TSGDataType type(CT_MATRIX, ST_STRING, PT_INT64, length_y,
1155  length_x);
1156  add_type(&type, param, name, description);
1157 }
1158 
1159 void
1161  index_t* length_y, index_t* length_x,
1162  const char* name, const char* description) {
1163  TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT64, length_y,
1164  length_x);
1165  add_type(&type, param, name, description);
1166 }
1167 
1168 void
1170  index_t* length_y, index_t* length_x,
1171  const char* name, const char* description) {
1172  TSGDataType type(CT_MATRIX, ST_STRING, PT_FLOAT32, length_y,
1173  length_x);
1174  add_type(&type, param, name, description);
1175 }
1176 
1177 void
1179  index_t* length_y, index_t* length_x,
1180  const char* name, const char* description) {
1181  TSGDataType type(CT_MATRIX, ST_STRING, PT_FLOAT64, length_y,
1182  length_x);
1183  add_type(&type, param, name, description);
1184 }
1185 
1186 void
1188  index_t* length_y, index_t* length_x,
1189  const char* name, const char* description) {
1190  TSGDataType type(CT_MATRIX, ST_STRING, PT_FLOATMAX, length_y,
1191  length_x);
1192  add_type(&type, param, name, description);
1193 }
1194 
1195 void
1197  index_t* length_y, index_t* length_x,
1198  const char* name, const char* description) {
1199  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_BOOL, length_y,
1200  length_x);
1201  add_type(&type, param, name, description);
1202 }
1203 
1204 void
1206  index_t* length_y, index_t* length_x,
1207  const char* name, const char* description) {
1208  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_CHAR, length_y,
1209  length_x);
1210  add_type(&type, param, name, description);
1211 }
1212 
1213 void
1215  index_t* length_y, index_t* length_x,
1216  const char* name, const char* description) {
1217  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT8, length_y,
1218  length_x);
1219  add_type(&type, param, name, description);
1220 }
1221 
1222 void
1224  index_t* length_y, index_t* length_x,
1225  const char* name, const char* description) {
1226  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT8, length_y,
1227  length_x);
1228  add_type(&type, param, name, description);
1229 }
1230 
1231 void
1233  index_t* length_y, index_t* length_x,
1234  const char* name, const char* description) {
1235  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT16, length_y,
1236  length_x);
1237  add_type(&type, param, name, description);
1238 }
1239 
1240 void
1242  index_t* length_y, index_t* length_x,
1243  const char* name, const char* description) {
1244  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT16, length_y,
1245  length_x);
1246  add_type(&type, param, name, description);
1247 }
1248 
1249 void
1251  index_t* length_y, index_t* length_x,
1252  const char* name, const char* description) {
1253  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT32, length_y,
1254  length_x);
1255  add_type(&type, param, name, description);
1256 }
1257 
1258 void
1260  index_t* length_y, index_t* length_x,
1261  const char* name, const char* description) {
1262  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT32, length_y,
1263  length_x);
1264  add_type(&type, param, name, description);
1265 }
1266 
1267 void
1269  index_t* length_y, index_t* length_x,
1270  const char* name, const char* description) {
1271  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT64, length_y,
1272  length_x);
1273  add_type(&type, param, name, description);
1274 }
1275 
1276 void
1278  index_t* length_y, index_t* length_x,
1279  const char* name, const char* description) {
1280  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT64, length_y,
1281  length_x);
1282  add_type(&type, param, name, description);
1283 }
1284 
1285 void
1287  index_t* length_y, index_t* length_x,
1288  const char* name, const char* description) {
1289  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_FLOAT32, length_y,
1290  length_x);
1291  add_type(&type, param, name, description);
1292 }
1293 
1294 void
1296  index_t* length_y, index_t* length_x,
1297  const char* name, const char* description) {
1298  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_FLOAT64, length_y,
1299  length_x);
1300  add_type(&type, param, name, description);
1301 }
1302 
1303 void
1305  index_t* length_y, index_t* length_x,
1306  const char* name, const char* description) {
1307  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_FLOATMAX, length_y,
1308  length_x);
1309  add_type(&type, param, name, description);
1310 }
1311 
1312 void
1314  index_t* length_y, index_t* length_x,
1315  const char* name, const char* description) {
1316  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_COMPLEX128, length_y,
1317  length_x);
1318  add_type(&type, param, name, description);
1319 }
1320 
1321 
1322 
1323 
1324 void Parameter::add(SGMatrix<bool>* param, const char* name,
1325  const char* description)
1326 {
1327  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_BOOL, &param->num_rows,
1328  &param->num_cols);
1329  add_type(&type, &param->matrix, name, description);
1330 }
1331 
1332 void Parameter::add(SGMatrix<char>* param, const char* name,
1333  const char* description)
1334 {
1335  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_CHAR, &param->num_rows,
1336  &param->num_cols);
1337  add_type(&type, &param->matrix, name, description);
1338 }
1339 
1340 void Parameter::add(SGMatrix<int8_t>* param, const char* name,
1341  const char* description)
1342 {
1343  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_INT8, &param->num_rows,
1344  &param->num_cols);
1345  add_type(&type, &param->matrix, name, description);
1346 }
1347 
1348 void Parameter::add(SGMatrix<uint8_t>* param, const char* name,
1349  const char* description)
1350 {
1351  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_UINT8, &param->num_rows,
1352  &param->num_cols);
1353  add_type(&type, &param->matrix, name, description);
1354 }
1355 
1356 void Parameter::add(SGMatrix<int16_t>* param, const char* name,
1357  const char* description)
1358 {
1359  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_INT16, &param->num_rows,
1360  &param->num_cols);
1361  add_type(&type, &param->matrix, name, description);
1362 }
1363 
1364 void Parameter::add(SGMatrix<uint16_t>* param, const char* name,
1365  const char* description)
1366 {
1367  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_UINT16, &param->num_rows,
1368  &param->num_cols);
1369  add_type(&type, &param->matrix, name, description);
1370 }
1371 
1372 void Parameter::add(SGMatrix<int32_t>* param, const char* name,
1373  const char* description)
1374 {
1375  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_INT32, &param->num_rows,
1376  &param->num_cols);
1377  add_type(&type, &param->matrix, name, description);
1378 }
1379 
1380 void Parameter::add(SGMatrix<uint32_t>* param, const char* name,
1381  const char* description)
1382 {
1383  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_UINT32, &param->num_rows,
1384  &param->num_cols);
1385  add_type(&type, &param->matrix, name, description);
1386 }
1387 
1388 void Parameter::add(SGMatrix<int64_t>* param, const char* name,
1389  const char* description)
1390 {
1391  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_INT64, &param->num_rows,
1392  &param->num_cols);
1393  add_type(&type, &param->matrix, name, description);
1394 }
1395 
1396 void Parameter::add(SGMatrix<uint64_t>* param, const char* name,
1397  const char* description)
1398 {
1399  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_UINT64, &param->num_rows,
1400  &param->num_cols);
1401  add_type(&type, &param->matrix, name, description);
1402 }
1403 
1404 void Parameter::add(SGMatrix<float32_t>* param, const char* name,
1405  const char* description)
1406 {
1407  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_FLOAT32, &param->num_rows,
1408  &param->num_cols);
1409  add_type(&type, &param->matrix, name, description);
1410 }
1411 
1412 void Parameter::add(SGMatrix<float64_t>* param, const char* name,
1413  const char* description)
1414 {
1415  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_FLOAT64, &param->num_rows,
1416  &param->num_cols);
1417  add_type(&type, &param->matrix, name, description);
1418 }
1419 
1420 void Parameter::add(SGMatrix<floatmax_t>* param, const char* name,
1421  const char* description)
1422 {
1423  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_FLOATMAX, &param->num_rows,
1424  &param->num_cols);
1425  add_type(&type, &param->matrix, name, description);
1426 }
1427 
1428 void Parameter::add(SGMatrix<complex128_t>* param, const char* name,
1429  const char* description)
1430 {
1431  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_COMPLEX128, &param->num_rows,
1432  &param->num_cols);
1433  add_type(&type, &param->matrix, name, description);
1434 }
1435 
1436 void Parameter::add(SGMatrix<CSGObject*>* param, const char* name,
1437  const char* description)
1438 {
1439  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_SGOBJECT, &param->num_rows,
1440  &param->num_cols);
1441  add_type(&type, &param->matrix, name, description);
1442 }
1443 
1444 void Parameter::add(SGMatrix<SGString<bool> >* param, const char* name,
1445  const char* description)
1446 {
1447  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_BOOL, &param->num_rows,
1448  &param->num_cols);
1449  add_type(&type, &param->matrix, name, description);
1450 }
1451 
1452 void Parameter::add(SGMatrix<SGString<char> >* param, const char* name,
1453  const char* description)
1454 {
1455  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_CHAR, &param->num_rows,
1456  &param->num_cols);
1457  add_type(&type, &param->matrix, name, description);
1458 }
1459 
1461  const char* name, const char* description)
1462 {
1463  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_INT8, &param->num_rows,
1464  &param->num_cols);
1465  add_type(&type, &param->matrix, name, description);
1466 }
1467 
1469  const char* name, const char* description)
1470 {
1471  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_UINT8, &param->num_rows,
1472  &param->num_cols);
1473  add_type(&type, &param->matrix, name, description);
1474 }
1475 
1477  const char* name, const char* description)
1478 {
1479  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_INT16, &param->num_rows,
1480  &param->num_cols);
1481  add_type(&type, &param->matrix, name, description);
1482 }
1483 
1485  const char* name, const char* description)
1486 {
1487  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_UINT16, &param->num_rows,
1488  &param->num_cols);
1489  add_type(&type, &param->matrix, name, description);
1490 }
1491 
1493  const char* name, const char* description)
1494 {
1495  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_INT32, &param->num_rows,
1496  &param->num_cols);
1497  add_type(&type, &param->matrix, name, description);
1498 }
1499 
1501  const char* name, const char* description)
1502 {
1503  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_UINT32, &param->num_rows,
1504  &param->num_cols);
1505  add_type(&type, &param->matrix, name, description);
1506 }
1507 
1509  const char* name, const char* description)
1510 {
1511  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_INT64, &param->num_rows,
1512  &param->num_cols);
1513  add_type(&type, &param->matrix, name, description);
1514 }
1515 
1517  const char* name, const char* description)
1518 {
1519  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_UINT64, &param->num_rows,
1520  &param->num_cols);
1521  add_type(&type, &param->matrix, name, description);
1522 }
1523 
1525  const char* name, const char* description)
1526 {
1527  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_FLOAT32, &param->num_rows,
1528  &param->num_cols);
1529  add_type(&type, &param->matrix, name, description);
1530 }
1531 
1533  const char* name, const char* description)
1534 {
1535  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_FLOAT64, &param->num_rows,
1536  &param->num_cols);
1537  add_type(&type, &param->matrix, name, description);
1538 }
1539 
1541  const char* name, const char* description)
1542 {
1543  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_FLOATMAX, &param->num_rows,
1544  &param->num_cols);
1545  add_type(&type, &param->matrix, name, description);
1546 }
1547 
1549  const char* name, const char* description)
1550 {
1551  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_BOOL, &param->num_rows,
1552  &param->num_cols);
1553  add_type(&type, &param->matrix, name, description);
1554 }
1555 
1557  const char* name, const char* description)
1558 {
1559  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_CHAR, &param->num_rows,
1560  &param->num_cols);
1561  add_type(&type, &param->matrix, name, description);
1562 }
1563 
1565  const char* name, const char* description)
1566 {
1567  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT8, &param->num_rows,
1568  &param->num_cols);
1569  add_type(&type, &param->matrix, name, description);
1570 }
1571 
1573  const char* name, const char* description)
1574 {
1575  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT8, &param->num_rows,
1576  &param->num_cols);
1577  add_type(&type, &param->matrix, name, description);
1578 }
1579 
1581  const char* name, const char* description)
1582 {
1583  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT16, &param->num_rows,
1584  &param->num_cols);
1585  add_type(&type, &param->matrix, name, description);
1586 }
1587 
1589  const char* name, const char* description)
1590 {
1591  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT16, &param->num_rows,
1592  &param->num_cols);
1593  add_type(&type, &param->matrix, name, description);
1594 }
1595 
1597  const char* name, const char* description)
1598 {
1599  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT32, &param->num_rows,
1600  &param->num_cols);
1601  add_type(&type, &param->matrix, name, description);
1602 }
1603 
1605  const char* name, const char* description)
1606 {
1607  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT32, &param->num_rows,
1608  &param->num_cols);
1609  add_type(&type, &param->matrix, name, description);
1610 }
1611 
1613  const char* name, const char* description)
1614 {
1615  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT64, &param->num_rows,
1616  &param->num_cols);
1617  add_type(&type, &param->matrix, name, description);
1618 }
1619 
1621  const char* name, const char* description)
1622 {
1623  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT64, &param->num_rows,
1624  &param->num_cols);
1625  add_type(&type, &param->matrix, name, description);
1626 }
1627 
1629  const char* name, const char* description)
1630 {
1631  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOAT32, &param->num_rows,
1632  &param->num_cols);
1633  add_type(&type, &param->matrix, name, description);
1634 }
1635 
1637  const char* name, const char* description)
1638 {
1639  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOAT64, &param->num_rows,
1640  &param->num_cols);
1641  add_type(&type, &param->matrix, name, description);
1642 }
1643 
1645  const char* name, const char* description)
1646 {
1647  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOATMAX, &param->num_rows,
1648  &param->num_cols);
1649  add_type(&type, &param->matrix, name, description);
1650 }
1651 
1653  const char* name, const char* description)
1654 {
1655  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_COMPLEX128, &param->num_rows,
1656  &param->num_cols);
1657  add_type(&type, &param->matrix, name, description);
1658 }
1659 
1661  const char* name, const char* description)
1662 {
1663  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_BOOL, &param->num_vectors,
1664  &param->num_features);
1665  add_type(&type, &param->sparse_matrix, name, description);
1666 }
1667 
1669  const char* name, const char* description)
1670 {
1671  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_CHAR, &param->num_vectors,
1672  &param->num_features);
1673  add_type(&type, &param->sparse_matrix, name, description);
1674 }
1675 
1677  const char* name, const char* description)
1678 {
1679  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT8, &param->num_vectors,
1680  &param->num_features);
1681  add_type(&type, &param->sparse_matrix, name, description);
1682 }
1683 
1685  const char* name, const char* description)
1686 {
1687  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT8, &param->num_vectors,
1688  &param->num_features);
1689  add_type(&type, &param->sparse_matrix, name, description);
1690 }
1691 
1693  const char* name, const char* description)
1694 {
1695  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT16, &param->num_vectors,
1696  &param->num_features);
1697  add_type(&type, &param->sparse_matrix, name, description);
1698 }
1699 
1701  const char* name, const char* description)
1702 {
1703  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT16, &param->num_vectors,
1704  &param->num_features);
1705  add_type(&type, &param->sparse_matrix, name, description);
1706 }
1707 
1709  const char* name, const char* description)
1710 {
1711  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT32, &param->num_vectors,
1712  &param->num_features);
1713  add_type(&type, &param->sparse_matrix, name, description);
1714 }
1715 
1717  const char* name, const char* description)
1718 {
1719  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT32, &param->num_vectors,
1720  &param->num_features);
1721  add_type(&type, &param->sparse_matrix, name, description);
1722 }
1723 
1725  const char* name, const char* description)
1726 {
1727  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT64, &param->num_vectors,
1728  &param->num_features);
1729  add_type(&type, &param->sparse_matrix, name, description);
1730 }
1731 
1733  const char* name, const char* description)
1734 {
1735  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT64, &param->num_vectors,
1736  &param->num_features);
1737  add_type(&type, &param->sparse_matrix, name, description);
1738 }
1739 
1741  const char* name, const char* description)
1742 {
1743  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOAT32, &param->num_vectors,
1744  &param->num_features);
1745  add_type(&type, &param->sparse_matrix, name, description);
1746 }
1747 
1749  const char* name, const char* description)
1750 {
1751  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOAT64, &param->num_vectors,
1752  &param->num_features);
1753  add_type(&type, &param->sparse_matrix, name, description);
1754 }
1755 
1757  const char* name, const char* description)
1758 {
1759  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOATMAX, &param->num_vectors,
1760  &param->num_features);
1761  add_type(&type, &param->sparse_matrix, name, description);
1762 }
1763 
1765  const char* name, const char* description)
1766 {
1767  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_COMPLEX128, &param->num_vectors,
1768  &param->num_features);
1769  add_type(&type, &param->sparse_matrix, name, description);
1770 }
1771 
1773  const char* name, const char* description)
1774 {
1775  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_SGOBJECT, &param->num_vectors,
1776  &param->num_features);
1777  add_type(&type, &param->sparse_matrix, name, description);
1778 }
1779 
1780 /* **************************************************************** */
1781 /* End of wrappers */
1782 
1783 TParameter::TParameter(const TSGDataType* datatype, void* parameter,
1784  const char* name, const char* description)
1785  :m_datatype(*datatype)
1786 {
1787  m_parameter = parameter;
1788  m_name = get_strdup(name);
1789  m_description = get_strdup(description);
1790 }
1791 
1793 {
1794  SG_FREE(m_description);
1795  SG_FREE(m_name);
1796 }
1797 
1798 char*
1799 TParameter::new_prefix(const char* s1, const char* s2)
1800 {
1801  char* tmp = SG_MALLOC(char, strlen(s1)+strlen(s2)+2);
1802 
1803  sprintf(tmp, "%s%s/", s1, s2);
1804 
1805  return tmp;
1806 }
1807 
1808 void
1809 TParameter::print(const char* prefix)
1810 {
1811  string_t buf;
1813 
1814  SG_SPRINT("\n%s\n%35s %24s :%s\n", prefix, m_description == NULL
1815  || *m_description == '\0' ? "(Parameter)": m_description,
1816  m_name, buf);
1817 
1818  if (m_datatype.m_ptype == PT_SGOBJECT
1819  && m_datatype.m_stype == ST_NONE
1820  && m_datatype.m_ctype == CT_SCALAR
1821  && *(CSGObject**) m_parameter != NULL) {
1822  char* p = new_prefix(prefix, m_name);
1823  (*(CSGObject**) m_parameter)->print_serializable(p);
1824  SG_FREE(p);
1825  }
1826 }
1827 
1828 void
1829 TParameter::delete_cont()
1830 {
1831  if (*(void**) m_parameter != NULL) {
1832  index_t old_length = m_datatype.m_length_y ? *m_datatype.m_length_y : 0;
1833  switch (m_datatype.m_ctype) {
1834  case CT_NDARRAY:
1836  break;
1837  case CT_MATRIX: case CT_SGMATRIX:
1838  old_length *= *m_datatype.m_length_x; break;
1839  case CT_SCALAR: case CT_VECTOR: case CT_SGVECTOR: break;
1840  case CT_UNDEFINED: default:
1841  SG_SERROR("Implementation error: undefined container type\n");
1842  break;
1843  }
1844 
1845  switch (m_datatype.m_stype) {
1846  case ST_NONE:
1847  switch (m_datatype.m_ptype) {
1848  case PT_BOOL:
1849  SG_FREE(*(bool**) m_parameter); break;
1850  case PT_CHAR:
1851  SG_FREE(*(char**) m_parameter); break;
1852  case PT_INT8:
1853  SG_FREE(*(int8_t**) m_parameter); break;
1854  case PT_UINT8:
1855  SG_FREE(*(uint8_t**) m_parameter); break;
1856  case PT_INT16:
1857  SG_FREE(*(int16_t**) m_parameter); break;
1858  case PT_UINT16:
1859  SG_FREE(*(uint16_t**) m_parameter); break;
1860  case PT_INT32:
1861  SG_FREE(*(int32_t**) m_parameter); break;
1862  case PT_UINT32:
1863  SG_FREE(*(uint32_t**) m_parameter); break;
1864  case PT_INT64:
1865  SG_FREE(*(int64_t**) m_parameter); break;
1866  case PT_UINT64:
1867  SG_FREE(*(uint64_t**) m_parameter); break;
1868  case PT_FLOAT32:
1869  SG_FREE(*(float32_t**) m_parameter); break;
1870  case PT_FLOAT64:
1871  SG_FREE(*(float64_t**) m_parameter); break;
1872  case PT_FLOATMAX:
1873  SG_FREE(*(floatmax_t**) m_parameter); break;
1874  case PT_COMPLEX128:
1875  SG_FREE(*(complex128_t**) m_parameter); break;
1876  case PT_SGOBJECT:
1877  {
1878  CSGObject** buf = *(CSGObject***) m_parameter;
1879 
1880  for (index_t i=0; i<old_length; i++)
1881  SG_UNREF(buf[i]);
1882 
1883  SG_FREE(buf);
1884  break;
1885  }
1886  case PT_UNDEFINED: default:
1887  SG_SERROR("Implementation error: undefined primitive type\n");
1888  break;
1889  }
1890  break;
1891  case ST_STRING:
1892  {
1893  for (index_t i=0; i<old_length; i++) {
1894  SGString<char>* buf = (SGString<char>*) (*(char**)
1896  if (buf->slen > 0) SG_FREE(buf->string);
1897  break;
1898  }
1899  }
1900 
1901  switch (m_datatype.m_ptype) {
1902  case PT_BOOL:
1903  SG_FREE(*(SGString<bool>**) m_parameter); break;
1904  case PT_CHAR:
1905  SG_FREE(*(SGString<char>**) m_parameter); break;
1906  case PT_INT8:
1907  SG_FREE(*(SGString<int8_t>**) m_parameter); break;
1908  case PT_UINT8:
1909  SG_FREE(*(SGString<uint8_t>**) m_parameter); break;
1910  case PT_INT16:
1911  SG_FREE(*(SGString<int16_t>**) m_parameter); break;
1912  case PT_UINT16:
1913  SG_FREE(*(SGString<uint16_t>**) m_parameter); break;
1914  case PT_INT32:
1915  SG_FREE(*(SGString<int32_t>**) m_parameter); break;
1916  case PT_UINT32:
1917  SG_FREE(*(SGString<uint32_t>**) m_parameter); break;
1918  case PT_INT64:
1919  SG_FREE(*(SGString<int64_t>**) m_parameter); break;
1920  case PT_UINT64:
1921  SG_FREE(*(SGString<uint64_t>**) m_parameter); break;
1922  case PT_FLOAT32:
1923  SG_FREE(*(SGString<float32_t>**) m_parameter); break;
1924  case PT_FLOAT64:
1925  SG_FREE(*(SGString<float64_t>**) m_parameter); break;
1926  case PT_FLOATMAX:
1927  SG_FREE(*(SGString<floatmax_t>**) m_parameter); break;
1928  case PT_COMPLEX128:
1929  SG_SERROR("TParameter::delete_cont(): Parameters of strings"
1930  " of complex128_t are not supported");
1931  break;
1932  case PT_SGOBJECT:
1933  SG_SERROR("TParameter::delete_cont(): Implementation "
1934  "error: Could not delete "
1935  "String<SGSerializable*>");
1936  break;
1937  case PT_UNDEFINED: default:
1938  SG_SERROR("Implementation error: undefined primitive type\n");
1939  break;
1940  }
1941  break;
1942  case ST_SPARSE:
1943  for (index_t i=0; i<old_length; i++) {
1944  SGSparseVector<char>* buf = (SGSparseVector<char>*) (*(char**)
1946  if (buf->num_feat_entries > 0) SG_FREE(buf->features);
1947  }
1948 
1949  switch (m_datatype.m_ptype) {
1950  case PT_BOOL:
1951  SG_FREE(*(SGSparseVector<bool>**) m_parameter); break;
1952  case PT_CHAR:
1953  SG_FREE(*(SGSparseVector<char>**) m_parameter); break;
1954  case PT_INT8:
1955  SG_FREE(*(SGSparseVector<int8_t>**) m_parameter); break;
1956  case PT_UINT8:
1957  SG_FREE(*(SGSparseVector<uint8_t>**) m_parameter); break;
1958  case PT_INT16:
1959  SG_FREE(*(SGSparseVector<int16_t>**) m_parameter); break;
1960  case PT_UINT16:
1961  SG_FREE(*(SGSparseVector<uint16_t>**) m_parameter); break;
1962  case PT_INT32:
1963  SG_FREE(*(SGSparseVector<int32_t>**) m_parameter); break;
1964  case PT_UINT32:
1965  SG_FREE(*(SGSparseVector<uint32_t>**) m_parameter); break;
1966  case PT_INT64:
1967  SG_FREE(*(SGSparseVector<int64_t>**) m_parameter); break;
1968  case PT_UINT64:
1969  SG_FREE(*(SGSparseVector<uint64_t>**) m_parameter); break;
1970  case PT_FLOAT32:
1971  SG_FREE(*(SGSparseVector<float32_t>**) m_parameter); break;
1972  case PT_FLOAT64:
1973  SG_FREE(*(SGSparseVector<float64_t>**) m_parameter); break;
1974  case PT_FLOATMAX:
1975  SG_FREE(*(SGSparseVector<floatmax_t>**) m_parameter); break;
1976  case PT_COMPLEX128:
1977  SG_FREE(*(SGSparseVector<complex128_t>**) m_parameter); break;
1978  case PT_SGOBJECT:
1979  SG_SERROR("TParameter::delete_cont(): Implementation "
1980  "error: Could not delete "
1981  "Sparse<SGSerializable*>");
1982  break;
1983  case PT_UNDEFINED: default:
1984  SG_SERROR("Implementation error: undefined primitive type\n");
1985  break;
1986  }
1987  break;
1988  case ST_UNDEFINED: default:
1989  SG_SERROR("Implementation error: undefined structure type\n");
1990  break;
1991  } /* switch (m_datatype.m_stype) */
1992  } /* if (*(void**) m_parameter != NULL) */
1993 
1994  *(void**) m_parameter = NULL;
1995 }
1996 
1997 void
1998 TParameter::new_cont(SGVector<index_t> dims)
1999 {
2000  char* s=SG_MALLOC(char, 200);
2001  m_datatype.to_string(s, 200);
2002  SG_SDEBUG("entering TParameter::new_cont for \"%s\" of type %s\n",
2003  s, m_name ? m_name : "(nil)");
2004  SG_FREE(s);
2005  delete_cont();
2006 
2007  index_t new_length = dims.product();
2008  if (new_length == 0) return;
2009 
2010  switch (m_datatype.m_stype) {
2011  case ST_NONE:
2012  switch (m_datatype.m_ptype) {
2013  case PT_BOOL:
2014  *(bool**) m_parameter
2015  = SG_MALLOC(bool, new_length); break;
2016  case PT_CHAR:
2017  *(char**) m_parameter
2018  = SG_MALLOC(char, new_length); break;
2019  case PT_INT8:
2020  *(int8_t**) m_parameter
2021  = SG_MALLOC(int8_t, new_length); break;
2022  case PT_UINT8:
2023  *(uint8_t**) m_parameter
2024  = SG_MALLOC(uint8_t, new_length); break;
2025  case PT_INT16:
2026  *(int16_t**) m_parameter
2027  = SG_MALLOC(int16_t, new_length); break;
2028  case PT_UINT16:
2029  *(uint16_t**) m_parameter
2030  = SG_MALLOC(uint16_t, new_length); break;
2031  case PT_INT32:
2032  *(int32_t**) m_parameter
2033  = SG_MALLOC(int32_t, new_length); break;
2034  case PT_UINT32:
2035  *(uint32_t**) m_parameter
2036  = SG_MALLOC(uint32_t, new_length); break;
2037  case PT_INT64:
2038  *(int64_t**) m_parameter
2039  = SG_MALLOC(int64_t, new_length); break;
2040  case PT_UINT64:
2041  *(uint64_t**) m_parameter
2042  = SG_MALLOC(uint64_t, new_length); break;
2043  case PT_FLOAT32:
2044  *(float32_t**) m_parameter
2045  = SG_MALLOC(float32_t, new_length); break;
2046  case PT_FLOAT64:
2047  *(float64_t**) m_parameter
2048  = SG_MALLOC(float64_t, new_length); break;
2049  case PT_FLOATMAX:
2050  *(floatmax_t**) m_parameter
2051  = SG_MALLOC(floatmax_t, new_length); break;
2052  case PT_COMPLEX128:
2054  = SG_MALLOC(complex128_t, new_length); break;
2055  case PT_SGOBJECT:
2056  *(CSGObject***) m_parameter
2057  = SG_CALLOC(CSGObject*, new_length);
2058  break;
2059  case PT_UNDEFINED: default:
2060  SG_SERROR("Implementation error: undefined primitive type\n");
2061  break;
2062  }
2063  break;
2064  case ST_STRING:
2065  switch (m_datatype.m_ptype) {
2066  case PT_BOOL:
2068  = SG_MALLOC(SGString<bool>, new_length); break;
2069  case PT_CHAR:
2071  = SG_MALLOC(SGString<char>, new_length); break;
2072  case PT_INT8:
2074  = SG_MALLOC(SGString<int8_t>, new_length); break;
2075  case PT_UINT8:
2077  = SG_MALLOC(SGString<uint8_t>, new_length); break;
2078  case PT_INT16:
2080  = SG_MALLOC(SGString<int16_t>, new_length); break;
2081  case PT_UINT16:
2083  = SG_MALLOC(SGString<uint16_t>, new_length); break;
2084  case PT_INT32:
2086  = SG_MALLOC(SGString<int32_t>, new_length); break;
2087  case PT_UINT32:
2089  = SG_MALLOC(SGString<uint32_t>, new_length); break;
2090  case PT_INT64:
2092  = SG_MALLOC(SGString<int64_t>, new_length); break;
2093  case PT_UINT64:
2095  = SG_MALLOC(SGString<uint64_t>, new_length); break;
2096  case PT_FLOAT32:
2098  = SG_MALLOC(SGString<float32_t>, new_length); break;
2099  case PT_FLOAT64:
2101  = SG_MALLOC(SGString<float64_t>, new_length); break;
2102  case PT_FLOATMAX:
2104  = SG_MALLOC(SGString<floatmax_t>, new_length); break;
2105  case PT_COMPLEX128:
2106  SG_SERROR("TParameter::new_cont(): Implementation "
2107  "error: Could not allocate "
2108  "String<complex128>");
2109  break;
2110  case PT_SGOBJECT:
2111  SG_SERROR("TParameter::new_cont(): Implementation "
2112  "error: Could not allocate "
2113  "String<SGSerializable*>");
2114  break;
2115  case PT_UNDEFINED: default:
2116  SG_SERROR("Implementation error: undefined primitive type\n");
2117  break;
2118  }
2119  memset(*(void**) m_parameter, 0, new_length
2121  break;
2122  case ST_SPARSE:
2123  switch (m_datatype.m_ptype) {
2124  case PT_BOOL:
2126  = SG_MALLOC(SGSparseVector<bool>, new_length); break;
2127  case PT_CHAR:
2129  = SG_MALLOC(SGSparseVector<char>, new_length); break;
2130  case PT_INT8:
2132  = SG_MALLOC(SGSparseVector<int8_t>, new_length); break;
2133  case PT_UINT8:
2135  = SG_MALLOC(SGSparseVector<uint8_t>, new_length); break;
2136  case PT_INT16:
2138  = SG_MALLOC(SGSparseVector<int16_t>, new_length); break;
2139  case PT_UINT16:
2141  = SG_MALLOC(SGSparseVector<uint16_t>, new_length); break;
2142  case PT_INT32:
2144  = SG_MALLOC(SGSparseVector<int32_t>, new_length);
2145  break;
2146  case PT_UINT32:
2148  = SG_MALLOC(SGSparseVector<uint32_t>, new_length); break;
2149  case PT_INT64:
2151  = SG_MALLOC(SGSparseVector<int64_t>, new_length); break;
2152  case PT_UINT64:
2154  = SG_MALLOC(SGSparseVector<uint64_t>, new_length); break;
2155  case PT_FLOAT32:
2157  = SG_MALLOC(SGSparseVector<float32_t>, new_length); break;
2158  case PT_FLOAT64:
2160  = SG_MALLOC(SGSparseVector<float64_t>, new_length); break;
2161  case PT_FLOATMAX:
2163  = SG_MALLOC(SGSparseVector<floatmax_t>, new_length); break;
2164  case PT_COMPLEX128:
2166  = SG_MALLOC(SGSparseVector<complex128_t>, new_length); break;
2167  case PT_SGOBJECT:
2168  SG_SERROR("TParameter::new_cont(): Implementation "
2169  "error: Could not allocate "
2170  "Sparse<SGSerializable*>");
2171  break;
2172  case PT_UNDEFINED: default:
2173  SG_SERROR("Implementation error: undefined primitive type\n");
2174  break;
2175  }
2176  break;
2177  case ST_UNDEFINED: default:
2178  SG_SERROR("Implementation error: undefined structure type\n");
2179  break;
2180  } /* switch (m_datatype.m_stype) */
2181 
2182  s=SG_MALLOC(char, 200);
2183  m_datatype.to_string(s, 200);
2184  SG_SDEBUG("leaving TParameter::new_cont for \"%s\" of type %s\n",
2185  s, m_name ? m_name : "(nil)");
2186  SG_FREE(s);
2187 }
2188 
2189 bool
2190 TParameter::new_sgserial(CSGObject** param,
2191  EPrimitiveType generic,
2192  const char* sgserializable_name,
2193  const char* prefix)
2194 {
2195  if (*param != NULL)
2196  SG_UNREF(*param);
2197 
2198  *param = new_sgserializable(sgserializable_name, generic);
2199 
2200  if (*param == NULL) {
2201  string_t buf = {'\0'};
2202 
2203  if (generic != PT_NOT_GENERIC) {
2204  buf[0] = '<';
2205  TSGDataType::ptype_to_string(buf+1, generic,
2206  STRING_LEN - 3);
2207  strcat(buf, ">");
2208  }
2209 
2210  SG_SWARNING("TParameter::new_sgserial(): "
2211  "Class `C%s%s' was not listed during compiling Shogun"
2212  " :( ... Can not construct it for `%s%s'!",
2213  sgserializable_name, buf, prefix, m_name);
2214 
2215  return false;
2216  }
2217 
2218  SG_REF(*param);
2219  return true;
2220 }
2221 
2222 bool
2223 TParameter::save_ptype(CSerializableFile* file, const void* param,
2224  const char* prefix)
2225 {
2226  if (m_datatype.m_ptype == PT_SGOBJECT) {
2227  const char* sgserial_name = "";
2228  EPrimitiveType generic = PT_NOT_GENERIC;
2229 
2230  if (*(CSGObject**) param != NULL) {
2231  sgserial_name = (*(CSGObject**) param)->get_name();
2232  (*(CSGObject**) param)->is_generic(&generic);
2233  }
2234 
2235  if (!file->write_sgserializable_begin(
2236  &m_datatype, m_name, prefix, sgserial_name, generic))
2237  return false;
2238  if (*sgserial_name != '\0') {
2239  char* p = new_prefix(prefix, m_name);
2240  bool result = (*(CSGObject**) param)
2241  ->save_serializable(file, p);
2242  SG_FREE(p);
2243  if (!result) return false;
2244  }
2245  if (!file->write_sgserializable_end(
2246  &m_datatype, m_name, prefix, sgserial_name, generic))
2247  return false;
2248  } else
2249  if (!file->write_scalar(&m_datatype, m_name, prefix,
2250  param)) return false;
2251 
2252  return true;
2253 }
2254 
2255 bool
2256 TParameter::load_ptype(CSerializableFile* file, void* param,
2257  const char* prefix)
2258 {
2259  if (m_datatype.m_ptype == PT_SGOBJECT) {
2260  string_t sgserial_name = {'\0'};
2261  EPrimitiveType generic = PT_NOT_GENERIC;
2262 
2263  if (!file->read_sgserializable_begin(
2264  &m_datatype, m_name, prefix, sgserial_name, &generic))
2265  return false;
2266  if (*sgserial_name != '\0') {
2267  if (!new_sgserial((CSGObject**) param, generic,
2268  sgserial_name, prefix))
2269  return false;
2270 
2271  char* p = new_prefix(prefix, m_name);
2272  bool result = (*(CSGObject**) param)
2273  ->load_serializable(file, p);
2274  SG_FREE(p);
2275  if (!result) return false;
2276  }
2277  if (!file->read_sgserializable_end(
2278  &m_datatype, m_name, prefix, sgserial_name, generic))
2279  return false;
2280  } else
2281  if (!file->read_scalar(&m_datatype, m_name, prefix,
2282  param)) return false;
2283 
2284  return true;
2285 }
2286 
2287 bool
2288 TParameter::save_stype(CSerializableFile* file, const void* param,
2289  const char* prefix)
2290 {
2291  SGString<char>* str_ptr = (SGString<char>*) param;
2292  SGSparseVector<char>* spr_ptr = (SGSparseVector<char>*) param;
2293  index_t len_real;
2294 
2295  switch (m_datatype.m_stype) {
2296  case ST_NONE:
2297  if (!save_ptype(file, param, prefix)) return false;
2298  break;
2299  case ST_STRING:
2300  len_real = str_ptr->slen;
2301  if (str_ptr->string == NULL && len_real != 0) {
2302  SG_SWARNING("Inconsistency between data structure and "
2303  "len during saving string `%s%s'! Continuing"
2304  " with len=0.\n",
2305  prefix, m_name);
2306  len_real = 0;
2307  }
2308  if (!file->write_string_begin(
2309  &m_datatype, m_name, prefix, len_real)) return false;
2310  for (index_t i=0; i<len_real; i++) {
2311  if (!file->write_stringentry_begin(
2312  &m_datatype, m_name, prefix, i)) return false;
2313  if (!save_ptype(file, (char*) str_ptr->string
2314  + i *m_datatype.sizeof_ptype(), prefix))
2315  return false;
2316  if (!file->write_stringentry_end(
2317  &m_datatype, m_name, prefix, i)) return false;
2318  }
2319  if (!file->write_string_end(
2320  &m_datatype, m_name, prefix, len_real)) return false;
2321  break;
2322  case ST_SPARSE:
2323  len_real = spr_ptr->num_feat_entries;
2324  if (spr_ptr->features == NULL && len_real != 0) {
2325  SG_SWARNING("Inconsistency between data structure and "
2326  "len during saving sparse `%s%s'! Continuing"
2327  " with len=0.\n",
2328  prefix, m_name);
2329  len_real = 0;
2330  }
2331  if (!file->write_sparse_begin(
2332  &m_datatype, m_name, prefix, len_real)) return false;
2333  for (index_t i=0; i<len_real; i++) {
2335  ((char*) spr_ptr->features + i *TSGDataType
2337  if (!file->write_sparseentry_begin(
2338  &m_datatype, m_name, prefix, spr_ptr->features,
2339  cur->feat_index, i)) return false;
2340  if (!save_ptype(file, (char*) cur + TSGDataType
2341  ::offset_sparseentry(m_datatype.m_ptype),
2342  prefix)) return false;
2343  if (!file->write_sparseentry_end(
2344  &m_datatype, m_name, prefix, spr_ptr->features,
2345  cur->feat_index, i)) return false;
2346  }
2347  if (!file->write_sparse_end(
2348  &m_datatype, m_name, prefix, len_real)) return false;
2349  break;
2350  case ST_UNDEFINED: default:
2351  SG_SERROR("Implementation error: undefined structure type\n");
2352  break;
2353  }
2354 
2355  return true;
2356 }
2357 
2358 bool
2359 TParameter::load_stype(CSerializableFile* file, void* param,
2360  const char* prefix)
2361 {
2362  SGString<char>* str_ptr = (SGString<char>*) param;
2363  SGSparseVector<char>* spr_ptr = (SGSparseVector<char>*) param;
2364  index_t len_real = 0;
2365 
2366  switch (m_datatype.m_stype) {
2367  case ST_NONE:
2368  if (!load_ptype(file, param, prefix)) return false;
2369  break;
2370  case ST_STRING:
2371  if (!file->read_string_begin(
2372  &m_datatype, m_name, prefix, &len_real))
2373  return false;
2374  str_ptr->string = len_real > 0
2375  ? SG_MALLOC(char, len_real*m_datatype.sizeof_ptype()): NULL;
2376  for (index_t i=0; i<len_real; i++) {
2377  if (!file->read_stringentry_begin(
2378  &m_datatype, m_name, prefix, i)) return false;
2379  if (!load_ptype(file, (char*) str_ptr->string
2380  + i *m_datatype.sizeof_ptype(), prefix))
2381  return false;
2382  if (!file->read_stringentry_end(
2383  &m_datatype, m_name, prefix, i)) return false;
2384  }
2385  if (!file->read_string_end(
2386  &m_datatype, m_name, prefix, len_real))
2387  return false;
2388  str_ptr->slen = len_real;
2389  break;
2390  case ST_SPARSE:
2391  if (!file->read_sparse_begin(
2392  &m_datatype, m_name, prefix, &len_real)) return false;
2393  spr_ptr->features = len_real > 0? (SGSparseVectorEntry<char>*)
2394  SG_MALLOC(char, len_real *TSGDataType::sizeof_sparseentry(
2395  m_datatype.m_ptype)): NULL;
2396  for (index_t i=0; i<len_real; i++) {
2398  ((char*) spr_ptr->features + i *TSGDataType
2400  if (!file->read_sparseentry_begin(
2401  &m_datatype, m_name, prefix, spr_ptr->features,
2402  &cur->feat_index, i)) return false;
2403  if (!load_ptype(file, (char*) cur + TSGDataType
2404  ::offset_sparseentry(m_datatype.m_ptype),
2405  prefix)) return false;
2406  if (!file->read_sparseentry_end(
2407  &m_datatype, m_name, prefix, spr_ptr->features,
2408  &cur->feat_index, i)) return false;
2409  }
2410 
2411  if (!file->read_sparse_end(&m_datatype, m_name, prefix, len_real))
2412  return false;
2413 
2414  spr_ptr->num_feat_entries = len_real;
2415  break;
2416  case ST_UNDEFINED: default:
2417  SG_SERROR("Implementation error: undefined structure type\n");
2418  break;
2419  }
2420 
2421  return true;
2422 }
2423 
2425  uint32_t& hash, uint32_t& carry, uint32_t& total_length)
2426 {
2427 
2428  switch (m_datatype.m_ctype)
2429  {
2430  case CT_NDARRAY:
2432  break;
2433  case CT_SCALAR:
2434  {
2435  uint8_t* data = ((uint8_t*) m_parameter);
2436  uint32_t size = m_datatype.sizeof_stype();
2437  total_length += size;
2439  &hash, &carry, data, size);
2440  break;
2441  }
2442  case CT_VECTOR: case CT_MATRIX: case CT_SGVECTOR: case CT_SGMATRIX:
2443  {
2444  index_t len_real_y = 0, len_real_x = 0;
2445 
2446  if (m_datatype.m_length_y)
2447  len_real_y = *m_datatype.m_length_y;
2448 
2449  else
2450  len_real_y = 1;
2451 
2452  if (*(void**) m_parameter == NULL && len_real_y != 0)
2453  {
2454  SG_SWARNING("Inconsistency between data structure and "
2455  "len_y during hashing `%s'! Continuing with "
2456  "len_y=0.\n",
2457  m_name);
2458  len_real_y = 0;
2459  }
2460 
2461  switch (m_datatype.m_ctype)
2462  {
2463  case CT_NDARRAY:
2465  break;
2466  case CT_VECTOR: case CT_SGVECTOR:
2467  len_real_x = 1;
2468  break;
2469  case CT_MATRIX: case CT_SGMATRIX:
2470  len_real_x = *m_datatype.m_length_x;
2471 
2472  if (*(void**) m_parameter == NULL && len_real_x != 0)
2473  {
2474  SG_SWARNING("Inconsistency between data structure and "
2475  "len_x during hashing %s'! Continuing "
2476  "with len_x=0.\n",
2477  m_name);
2478  len_real_x = 0;
2479  }
2480 
2481  if (len_real_x *len_real_y == 0)
2482  len_real_x = len_real_y = 0;
2483 
2484  break;
2485 
2486  case CT_SCALAR: break;
2487  case CT_UNDEFINED: default:
2488  SG_SERROR("Implementation error: undefined container type\n");
2489  break;
2490  }
2491  uint32_t size = (len_real_x*len_real_y)*m_datatype.sizeof_stype();
2492 
2493  total_length += size;
2494 
2495  uint8_t* data = (*(uint8_t**) m_parameter);
2496 
2498  &hash, &carry, data, size);
2499  break;
2500  }
2501  case CT_UNDEFINED: default:
2502  SG_SERROR("Implementation error: undefined container type\n");
2503  break;
2504  }
2505 }
2506 
2507 bool
2509 {
2510  return m_datatype.get_num_elements() > 0;
2511 }
2512 
2513 bool
2514 TParameter::save(CSerializableFile* file, const char* prefix)
2515 {
2516  const int32_t buflen=100;
2517  char* buf=SG_MALLOC(char, buflen);
2518  m_datatype.to_string(buf, buflen);
2519  SG_SINFO("Saving parameter '%s' of type '%s'\n", m_name, buf)
2520  SG_FREE(buf);
2521 
2522  if (!file->write_type_begin(&m_datatype, m_name, prefix))
2523  return false;
2524 
2525  switch (m_datatype.m_ctype) {
2526  case CT_NDARRAY:
2528  break;
2529  case CT_SCALAR:
2530  if (!save_stype(file, m_parameter, prefix)) return false;
2531  break;
2532  case CT_VECTOR: case CT_MATRIX: case CT_SGVECTOR: case CT_SGMATRIX:
2533  {
2534  index_t len_real_y = 0, len_real_x = 0;
2535 
2536  len_real_y = *m_datatype.m_length_y;
2537  if (*(void**) m_parameter == NULL && len_real_y != 0) {
2538  SG_SWARNING("Inconsistency between data structure and "
2539  "len_y during saving `%s%s'! Continuing with "
2540  "len_y=0.\n",
2541  prefix, m_name);
2542  len_real_y = 0;
2543  }
2544 
2545  switch (m_datatype.m_ctype) {
2546  case CT_NDARRAY:
2548  break;
2549  case CT_VECTOR: case CT_SGVECTOR:
2550  len_real_x = 1;
2551  break;
2552  case CT_MATRIX: case CT_SGMATRIX:
2553  len_real_x = *m_datatype.m_length_x;
2554  if (*(void**) m_parameter == NULL && len_real_x != 0) {
2555  SG_SWARNING("Inconsistency between data structure and "
2556  "len_x during saving `%s%s'! Continuing "
2557  "with len_x=0.\n",
2558  prefix, m_name);
2559  len_real_x = 0;
2560  }
2561 
2562  if (len_real_x *len_real_y == 0)
2563  len_real_x = len_real_y = 0;
2564 
2565  break;
2566  case CT_SCALAR: break;
2567  case CT_UNDEFINED: default:
2568  SG_SERROR("Implementation error: undefined container type\n");
2569  break;
2570  }
2571 
2572  if (!file->write_cont_begin(&m_datatype, m_name, prefix,
2573  len_real_y, len_real_x))
2574  return false;
2575 
2576  /* ******************************************************** */
2577 
2578  for (index_t x=0; x<len_real_x; x++)
2579  for (index_t y=0; y<len_real_y; y++) {
2580  if (!file->write_item_begin(
2581  &m_datatype, m_name, prefix, y, x))
2582  return false;
2583 
2584  if (!save_stype(
2585  file, (*(char**) m_parameter)
2586  + (x*len_real_y + y)*m_datatype.sizeof_stype(),
2587  prefix)) return false;
2588  if (!file->write_item_end(
2589  &m_datatype, m_name, prefix, y, x))
2590  return false;
2591  }
2592 
2593  /* ******************************************************** */
2594 
2595  if (!file->write_cont_end(&m_datatype, m_name, prefix,
2596  len_real_y, len_real_x))
2597  return false;
2598 
2599  break;
2600  }
2601  case CT_UNDEFINED: default:
2602  SG_SERROR("Implementation error: undefined container type\n");
2603  break;
2604  }
2605 
2606  if (!file->write_type_end(&m_datatype, m_name, prefix))
2607  return false;
2608 
2609  return true;
2610 }
2611 
2612 bool
2613 TParameter::load(CSerializableFile* file, const char* prefix)
2614 {
2615  REQUIRE(file != NULL, "Serializable file object should be != NULL\n");
2616 
2617  const int32_t buflen=100;
2618  char* buf=SG_MALLOC(char, buflen);
2619  m_datatype.to_string(buf, buflen);
2620  SG_SDEBUG("Loading parameter '%s' of type '%s'\n", m_name, buf)
2621  SG_FREE(buf);
2622 
2623  if (!file->read_type_begin(&m_datatype, m_name, prefix))
2624  return false;
2625 
2626  switch (m_datatype.m_ctype)
2627  {
2628  case CT_NDARRAY:
2630  break;
2631  case CT_SCALAR:
2632  if (!load_stype(file, m_parameter, prefix))
2633  return false;
2634  break;
2635 
2636  case CT_VECTOR: case CT_MATRIX: case CT_SGVECTOR: case CT_SGMATRIX:
2637  {
2638  SGVector<index_t> dims(2);
2639  dims.zero();
2640 
2641  if (!file->read_cont_begin(&m_datatype, m_name, prefix,
2642  &dims.vector[1], &dims.vector[0]))
2643  return false;
2644 
2645  switch (m_datatype.m_ctype)
2646  {
2647  case CT_NDARRAY:
2649  break;
2650  case CT_VECTOR: case CT_SGVECTOR:
2651  dims[0]=1;
2652  new_cont(dims);
2653  break;
2654  case CT_MATRIX: case CT_SGMATRIX:
2655  new_cont(dims);
2656  break;
2657  case CT_SCALAR:
2658  break;
2659  case CT_UNDEFINED: default:
2660  SG_SERROR("Implementation error: undefined container type\n");
2661  break;
2662  }
2663 
2664  for (index_t x=0; x<dims[0]; x++)
2665  {
2666  for (index_t y=0; y<dims[1]; y++)
2667  {
2668  if (!file->read_item_begin(
2669  &m_datatype, m_name, prefix, y, x))
2670  return false;
2671 
2672  if (!load_stype(
2673  file, (*(char**) m_parameter)
2674  + (x*dims[1] + y)*m_datatype.sizeof_stype(),
2675  prefix)) return false;
2676  if (!file->read_item_end(
2677  &m_datatype, m_name, prefix, y, x))
2678  return false;
2679  }
2680  }
2681 
2682  switch (m_datatype.m_ctype)
2683  {
2684  case CT_NDARRAY:
2686  break;
2687  case CT_VECTOR: case CT_SGVECTOR:
2688  *m_datatype.m_length_y = dims[1];
2689  break;
2690  case CT_MATRIX: case CT_SGMATRIX:
2691  *m_datatype.m_length_y = dims[1];
2692  *m_datatype.m_length_x = dims[0];
2693  break;
2694  case CT_SCALAR:
2695  break;
2696  case CT_UNDEFINED: default:
2697  SG_SERROR("Implementation error: undefined container type\n");
2698  break;
2699  }
2700 
2701  if (!file->read_cont_end(&m_datatype, m_name, prefix,
2702  dims[1], dims[0]))
2703  return false;
2704 
2705  break;
2706  }
2707  case CT_UNDEFINED: default:
2708  SG_SERROR("Implementation error: undefined container type\n");
2709  break;
2710  }
2711 
2712  if (!file->read_type_end(&m_datatype, m_name, prefix))
2713  return false;
2714 
2715  return true;
2716 }
2717 
2718 /*
2719  Initializing m_params(1) with small preallocation-size, because Parameter
2720  will be constructed several times for EACH SGObject instance.
2721  */
2722 Parameter::Parameter() : m_params(1)
2723 {
2724  SG_REF(sg_io);
2725 }
2726 
2728 {
2729  for (int32_t i=0; i<get_num_parameters(); i++)
2730  delete m_params.get_element(i);
2731 
2732  SG_UNREF(sg_io);
2733 }
2734 
2735 void
2736 Parameter::add_type(const TSGDataType* type, void* param,
2737  const char* name, const char* description)
2738 {
2739  if (name == NULL || *name == '\0')
2740  SG_SERROR("FATAL: Parameter::add_type(): `name' is empty!\n")
2741 
2742  for (size_t i=0; i<strlen(name); ++i)
2743  {
2744  if (!std::isalnum(name[i]) && name[i]!='_' && name[i]!='.')
2745  {
2746  SG_SERROR("Character %d of parameter with name \"%s\" is illegal "
2747  "(only alnum or underscore is allowed)\n",
2748  i, name);
2749  }
2750  }
2751 
2752  for (int32_t i=0; i<get_num_parameters(); i++)
2753  if (strcmp(m_params.get_element(i)->m_name, name) == 0)
2754  SG_SERROR("FATAL: Parameter::add_type(): "
2755  "Double parameter `%s'!\n", name);
2756 
2757  m_params.append_element(
2758  new TParameter(type, param, name, description)
2759  );
2760 }
2761 
2762 void
2763 Parameter::print(const char* prefix)
2764 {
2765  for (int32_t i=0; i<get_num_parameters(); i++)
2766  m_params.get_element(i)->print(prefix);
2767 }
2768 
2769 bool
2770 Parameter::save(CSerializableFile* file, const char* prefix)
2771 {
2772  for (int32_t i=0; i<get_num_parameters(); i++)
2773  {
2774  if (!m_params.get_element(i)->save(file, prefix))
2775  return false;
2776  }
2777 
2778  return true;
2779 }
2780 
2781 bool
2782 Parameter::load(CSerializableFile* file, const char* prefix)
2783 {
2784  for (int32_t i=0; i<get_num_parameters(); i++)
2785  if (!m_params.get_element(i)->load(file, prefix))
2786  return false;
2787 
2788  return true;
2789 }
2790 
2792 {
2793  /* iterate over parameters in the given list */
2794  for (index_t i=0; i<params->get_num_parameters(); ++i)
2795  {
2796  TParameter* current=params->get_parameter(i);
2797  TSGDataType current_type=current->m_datatype;
2798 
2799  ASSERT(m_params.get_num_elements())
2800 
2801  /* search for own parameter with same name and check types if found */
2802  TParameter* own=NULL;
2803  for (index_t j=0; j<m_params.get_num_elements(); ++j)
2804  {
2805  own=m_params.get_element(j);
2806  if (!strcmp(own->m_name, current->m_name))
2807  {
2808  if (own->m_datatype==current_type)
2809  {
2810  own=m_params.get_element(j);
2811  break;
2812  }
2813  else
2814  {
2815  index_t l=200;
2816  char* given_type=SG_MALLOC(char, l);
2817  char* own_type=SG_MALLOC(char, l);
2818  current->m_datatype.to_string(given_type, l);
2819  own->m_datatype.to_string(own_type, l);
2820  SG_SERROR("given parameter \"%s\" has a different type (%s)"
2821  " than existing one (%s)\n", current->m_name,
2822  given_type, own_type);
2823  SG_FREE(given_type);
2824  SG_FREE(own_type);
2825  }
2826  }
2827  else
2828  own=NULL;
2829  }
2830 
2831  if (!own)
2832  {
2833  SG_SERROR("parameter with name %s does not exist\n",
2834  current->m_name);
2835  }
2836 
2837  /* check if parameter contained CSGobjects (update reference counts) */
2838  if (current_type.m_ptype==PT_SGOBJECT)
2839  {
2840  /* PT_SGOBJECT only occurs for ST_NONE */
2841  if (own->m_datatype.m_stype==ST_NONE)
2842  {
2843  if (own->m_datatype.m_ctype==CT_SCALAR)
2844  {
2845  CSGObject** to_unref=(CSGObject**) own->m_parameter;
2846  CSGObject** to_ref=(CSGObject**) current->m_parameter;
2847 
2848  if ((*to_ref)!=(*to_unref))
2849  {
2850  SG_REF((*to_ref));
2851  SG_UNREF((*to_unref));
2852  }
2853 
2854  }
2855  else
2856  {
2857  /* unref all SGObjects and reference the new ones */
2858  CSGObject*** to_unref=(CSGObject***) own->m_parameter;
2859  CSGObject*** to_ref=(CSGObject***) current->m_parameter;
2860 
2861  for (index_t j=0; j<own->m_datatype.get_num_elements(); ++j)
2862  {
2863  if ((*to_ref)[j]!=(*to_unref)[j])
2864  {
2865  SG_REF(((*to_ref)[j]));
2866  SG_UNREF(((*to_unref)[j]));
2867  }
2868  }
2869  }
2870  }
2871  else
2872  SG_SERROR("primitive type PT_SGOBJECT occurred with structure "
2873  "type other than ST_NONE");
2874  }
2875 
2876  /* construct pointers to the to be copied parameter data */
2877  void* dest=NULL;
2878  void* source=NULL;
2879  if (current_type.m_ctype==CT_SCALAR)
2880  {
2881  /* for scalar values, just copy content the pointer points to */
2882  dest=own->m_parameter;
2883  source=current->m_parameter;
2884 
2885  /* in case of CSGObject, pointers are not equal if CSGObjects are
2886  * equal, so check. For other values, the pointers are equal and
2887  * the not-copying is handled below before the memcpy call */
2888  if (own->m_datatype.m_ptype==PT_SGOBJECT)
2889  {
2890  if (*((CSGObject**)dest) == *((CSGObject**)source))
2891  {
2892  dest=NULL;
2893  source=NULL;
2894  }
2895  }
2896  }
2897  else
2898  {
2899  /* for matrices and vectors, sadly m_parameter has to be
2900  * de-referenced once, because a pointer to the array address is
2901  * saved, but the array address itself has to be copied.
2902  * consequently, for dereferencing, a type distinction is needed */
2903  switch (own->m_datatype.m_ptype)
2904  {
2905  case PT_FLOAT64:
2906  dest=*((float64_t**) own->m_parameter);
2907  source=*((float64_t**) current->m_parameter);
2908  break;
2909  case PT_SGOBJECT:
2910  dest=*((CSGObject**) own->m_parameter);
2911  source=*((CSGObject**) current->m_parameter);
2912  break;
2913  default:
2915  break;
2916  }
2917  }
2918 
2919  /* copy parameter data, size in memory is equal because of same type */
2920  if (dest!=source)
2921  sg_memcpy(dest, source, own->m_datatype.get_size());
2922  }
2923 }
2924 
2926 {
2927  for (index_t i=0; i<params->get_num_parameters(); ++i)
2928  {
2929  TParameter* current=params->get_parameter(i);
2930  add_type(&(current->m_datatype), current->m_parameter, current->m_name,
2931  current->m_description);
2932  }
2933 }
2934 
2935 bool Parameter::contains_parameter(const char* name)
2936 {
2937  for (index_t i=0; i<m_params.get_num_elements(); ++i)
2938  {
2939  if (!strcmp(name, m_params[i]->m_name))
2940  return true;
2941  }
2942 
2943  return false;
2944 }
2945 
2946 bool TParameter::operator==(const TParameter& other) const
2947 {
2948  bool result=true;
2949  result&=!strcmp(m_name, other.m_name);
2950  return result;
2951 }
2952 
2953 bool TParameter::operator<(const TParameter& other) const
2954 {
2955  return strcmp(m_name, other.m_name)<0;
2956 }
2957 
2958 bool TParameter::operator>(const TParameter& other) const
2959 {
2960  return strcmp(m_name, other.m_name)>0;
2961 }
2962 
2963 bool TParameter::equals(TParameter* other, float64_t accuracy, bool tolerant)
2964 {
2965  SG_SDEBUG("entering TParameter::equals()\n");
2966 
2967  if (!other)
2968  {
2969  SG_SDEBUG("leaving TParameter::equals(): other parameter is NULL\n");
2970  return false;
2971  }
2972 
2973  if (strcmp(m_name, other->m_name))
2974  {
2975  SG_SDEBUG("leaving TParameter::equals(): name \"%s\" is different from"
2976  " other parameter's name \"%s\"\n", m_name, other->m_name);
2977  return false;
2978  }
2979 
2980  SG_SDEBUG("Comparing datatypes\n");
2981  if (!(m_datatype.equals(other->m_datatype)))
2982  {
2983  SG_SDEBUG("leaving TParameter::equals(): type of \"%s\" is different "
2984  "from other parameter's \"%s\" type\n", m_name, other->m_name);
2985  return false;
2986  }
2987 
2988  /* avoid comparing NULL */
2989  if (!m_parameter && !other->m_parameter)
2990  {
2991  SG_SDEBUG("leaving TParameter::equals(): both parameters are NULL\n");
2992  return true;
2993  }
2994 
2995  if ((!m_parameter && other->m_parameter) || (m_parameter && !other->m_parameter))
2996  {
2997  SG_SDEBUG("leaving TParameter::equals(): param1 is at %p while "
2998  "param2 is at %p\n", m_parameter, other->m_parameter);
2999  return false;
3000  }
3001 
3002  SG_SDEBUG("Comparing ctype\n");
3003  switch (m_datatype.m_ctype)
3004  {
3005  case CT_SCALAR:
3006  {
3007  SG_SDEBUG("CT_SCALAR\n");
3010  other->m_parameter,
3011  accuracy, tolerant))
3012  {
3013  SG_SDEBUG("leaving TParameter::equals(): scalar data differs\n");
3014  return false;
3015  }
3016  break;
3017  }
3018  case CT_VECTOR: case CT_SGVECTOR:
3019  {
3020  SG_SDEBUG("CT_VECTOR or CT_SGVECTOR\n");
3021 
3022  /* x is number of processed bytes */
3023  index_t x=0;
3024  SG_SDEBUG("length_y: %d\n", *m_datatype.m_length_y)
3025  for (index_t i=0; i<*m_datatype.m_length_y; ++i)
3026  {
3027  SG_SDEBUG("comparing element %d which is %d bytes from start\n",
3028  i, x);
3029 
3030  void* pointer_a=&((*(char**)m_parameter)[x]);
3031  void* pointer_b=&((*(char**)other->m_parameter)[x]);
3032 
3034  m_datatype.m_ptype, pointer_a, pointer_b,
3035  accuracy, tolerant))
3036  {
3037  SG_SDEBUG("leaving TParameter::equals(): vector element "
3038  "differs\n");
3039  return false;
3040  }
3041 
3042  x=x+(m_datatype.sizeof_stype());
3043  }
3044 
3045  break;
3046  }
3047  case CT_MATRIX: case CT_SGMATRIX:
3048  {
3049  SG_SDEBUG("CT_MATRIX or CT_SGMATRIX\n");
3050 
3051  /* x is number of processed bytes */
3052  index_t x=0;
3053  SG_SDEBUG("length_y: %d\n", *m_datatype.m_length_y)
3054  SG_SDEBUG("length_x: %d\n", *m_datatype.m_length_x)
3055  int64_t length=0;
3056 
3057  /* For ST_SPARSE, we just need to loop over the rows and compare_stype
3058  * does the comparison for one whole row vector at once. For ST_NONE,
3059  * however, we need to loop over all elements.
3060  */
3061  if (m_datatype.m_stype==ST_SPARSE)
3062  length=(*m_datatype.m_length_y);
3063  else
3064  length=(*m_datatype.m_length_y) * (*m_datatype.m_length_x);
3065 
3066  for (index_t i=0; i<length; ++i)
3067  {
3068  SG_SDEBUG("comparing element %d which is %d bytes from start\n",
3069  i, x);
3070 
3071  void* pointer_a=&((*(char**)m_parameter)[x]);
3072  void* pointer_b=&((*(char**)other->m_parameter)[x]);
3073 
3075  m_datatype.m_ptype, pointer_a, pointer_b,
3076  accuracy, tolerant))
3077  {
3078  SG_SDEBUG("leaving TParameter::equals(): vector element "
3079  "differs\n");
3080  return false;
3081  }
3082 
3083  /* For ST_SPARSE, the iteration is on the pointer of SGSparseVectors */
3084  if (m_datatype.m_stype==ST_SPARSE)
3085  x=x+(m_datatype.sizeof_stype());
3086  else
3087  x=x+(m_datatype.sizeof_stype());
3088  }
3089 
3090  break;
3091  }
3092  case CT_NDARRAY:
3093  {
3094  SG_SDEBUG("CT_NDARRAY\n");
3095  SG_SERROR("TParameter::equals(): Not yet implemented for "
3096  "CT_NDARRAY!\n");
3097  break;
3098  }
3099  case CT_UNDEFINED: default:
3100  SG_SERROR("Implementation error: undefined container type\n");
3101  break;
3102  }
3103 
3104  SG_SDEBUG("leaving TParameter::equals(): Parameters are equal\n");
3105  return true;
3106 }
3107 
3108 bool TParameter::compare_ptype(EPrimitiveType ptype, void* data1, void* data2,
3109  float64_t accuracy, bool tolerant)
3110 {
3111  SG_SDEBUG("entering TParameter::compare_ptype()\n");
3112 
3113  if ((data1 && !data2) || (!data1 && data2))
3114  {
3115  SG_SINFO("leaving TParameter::compare_ptype(): data1 is at %p while "
3116  "data2 is at %p\n", data1, data2);
3117  return false;
3118  }
3119 
3121  if (!data1 && !data2)
3122  {
3123  SG_SDEBUG("leaving TParameter::compare_ptype(): both data are NULL\n");
3124  return true;
3125  }
3126 
3127  switch (ptype)
3128  {
3129  case PT_BOOL:
3130  {
3131  bool casted1=*((bool*)data1);
3132  bool casted2=*((bool*)data2);
3133 
3134  if (CMath::abs(casted1-casted2)>accuracy)
3135  {
3136  SG_SINFO("leaving TParameter::compare_ptype(): PT_BOOL: "
3137  "data1=%d, data2=%d\n", casted1, casted2);
3138  return false;
3139  }
3140  break;
3141  }
3142  case PT_CHAR:
3143  {
3144  char casted1=*((char*)data1);
3145  char casted2=*((char*)data2);
3146 
3147  if (CMath::abs(casted1-casted2)>accuracy)
3148  {
3149  SG_SINFO("leaving TParameter::compare_ptype(): PT_CHAR: "
3150  "data1=%c, data2=%c\n", casted1, casted2);
3151  return false;
3152  }
3153  break;
3154  }
3155  case PT_INT8:
3156  {
3157  int8_t casted1=*((int8_t*)data1);
3158  int8_t casted2=*((int8_t*)data2);
3159 
3160  if (CMath::abs(casted1-casted2)>accuracy)
3161  {
3162  SG_SINFO("leaving TParameter::compare_ptype(): PT_INT8: "
3163  "data1=%d, data2=%d\n", casted1, casted2);
3164  return false;
3165  }
3166  break;
3167  }
3168  case PT_UINT8:
3169  {
3170  uint8_t casted1=*((uint8_t*)data1);
3171  uint8_t casted2=*((uint8_t*)data2);
3172 
3173  if (CMath::abs(casted1-casted2)>accuracy)
3174  {
3175  SG_SINFO("leaving TParameter::compare_ptype(): PT_UINT8: "
3176  "data1=%d, data2=%d\n", casted1, casted2);
3177  return false;
3178  }
3179  break;
3180  }
3181  case PT_INT16:
3182  {
3183  int16_t casted1=*((int16_t*)data1);
3184  int16_t casted2=*((int16_t*)data2);
3185 
3186  if (CMath::abs(casted1-casted2)>accuracy)
3187  {
3188  SG_SINFO("leaving TParameter::compare_ptype(): PT_INT16: "
3189  "data1=%d, data2=%d\n", casted1, casted2);
3190  return false;
3191  }
3192  break;
3193  }
3194  case PT_UINT16:
3195  {
3196  uint16_t casted1=*((uint16_t*)data1);
3197  uint16_t casted2=*((uint16_t*)data2);
3198 
3199  if (CMath::abs(casted1-casted2)>accuracy)
3200  {
3201  SG_SINFO("leaving TParameter::compare_ptype(): PT_UINT16: "
3202  "data1=%d, data2=%d\n", casted1, casted2);
3203  return false;
3204  }
3205  break;
3206  }
3207  case PT_INT32:
3208  {
3209  int32_t casted1=*((int32_t*)data1);
3210  int32_t casted2=*((int32_t*)data2);
3211 
3212  if (CMath::abs(casted1-casted2)>accuracy)
3213  {
3214  SG_SINFO("leaving TParameter::compare_ptype(): PT_INT32: "
3215  "data1=%d, data2=%d\n", casted1, casted2);
3216  return false;
3217  }
3218  break;
3219  }
3220  case PT_UINT32:
3221  {
3222  uint32_t casted1=*((uint32_t*)data1);
3223  uint32_t casted2=*((uint32_t*)data2);
3224 
3225  if (CMath::abs(casted1-casted2)>accuracy)
3226  {
3227  SG_SINFO("leaving TParameter::compare_ptype(): PT_UINT32: "
3228  "data1=%d, data2=%d\n", casted1, casted2);
3229  return false;
3230  }
3231  break;
3232  }
3233  case PT_INT64:
3234  {
3235  int64_t casted1=*((int64_t*)data1);
3236  int64_t casted2=*((int64_t*)data2);
3237 
3238  if (CMath::abs(casted1-casted2)>accuracy)
3239  {
3240  SG_SINFO("leaving TParameter::compare_ptype(): PT_INT64: "
3241  "data1=%d, data2=%d\n", casted1, casted2);
3242  return false;
3243  }
3244  break;
3245  }
3246  case PT_UINT64:
3247  {
3248  uint64_t casted1=*((uint64_t*)data1);
3249  uint64_t casted2=*((uint64_t*)data2);
3250 
3251  if (CMath::abs(casted1-casted2)>accuracy)
3252  {
3253  SG_SINFO("leaving TParameter::compare_ptype(): PT_UINT64: "
3254  "data1=%d, data2=%d\n", casted1, casted2);
3255  return false;
3256  }
3257  break;
3258  }
3259  case PT_FLOAT32:
3260  {
3261  float32_t casted1=*((float32_t*)data1);
3262  float32_t casted2=*((float32_t*)data2);
3263 
3264  SG_SINFO("leaving TParameter::compare_ptype(): PT_FLOAT32: "
3265  "data1=%f, data2=%f\n", casted1, casted2);
3266 
3267  return CMath::fequals<float32_t>(casted1, casted2, accuracy, tolerant);
3268  break;
3269  }
3270  case PT_FLOAT64:
3271  {
3272  float64_t casted1=*((float64_t*)data1);
3273  float64_t casted2=*((float64_t*)data2);
3274 
3275  SG_SINFO("leaving TParameter::compare_ptype(): PT_FLOAT64: "
3276  "data1=%f, data2=%f\n", casted1, casted2);
3277 
3278  return CMath::fequals<float64_t>(casted1, casted2, accuracy, tolerant);
3279  break;
3280  }
3281  case PT_FLOATMAX:
3282  {
3283  floatmax_t casted1=*((floatmax_t*)data1);
3284  floatmax_t casted2=*((floatmax_t*)data2);
3285 
3286  SG_SINFO("leaving TParameter::compare_ptype(): PT_FLOATMAX: "
3287  "data1=%f, data2=%f\n", casted1, casted2);
3288 
3289  return CMath::fequals<floatmax_t>(casted1, casted2, accuracy, tolerant);
3290  break;
3291  }
3292  case PT_COMPLEX128:
3293  {
3294  float64_t casted1_real=((complex128_t*)data1)->real();
3295  float64_t casted1_imag=((complex128_t*)data1)->imag();
3296  float64_t casted2_real=((complex128_t*)data2)->real();
3297  float64_t casted2_imag=((complex128_t*)data2)->imag();
3298  if (CMath::abs(casted1_real-casted2_real)>accuracy ||
3299  CMath::abs(casted1_imag-casted2_imag)>accuracy)
3300  {
3301  SG_SINFO("leaving TParameter::compare_ptype(): PT_COMPLEX128: "
3302  "data1=%f+i%f, data2=%f+i%f\n",
3303  casted1_real, casted1_imag,
3304  casted2_real, casted2_imag);
3305  return false;
3306  }
3307  break;
3308  }
3309  case PT_SGOBJECT:
3310  {
3311  CSGObject* casted1=*((CSGObject**)data1);
3312  CSGObject* casted2=*((CSGObject**)data2);
3313 
3314  /* important not to call methods on NULL */
3315  if (!casted1 && ! casted2)
3316  {
3317  SG_SDEBUG("leaving TParameter::compare_ptype(): SGObjects are equal\n");
3318  return true;
3319  }
3320 
3321  /* make sure to not call NULL methods */
3322  if (casted1)
3323  {
3324  if (!(casted1->equals(casted2, accuracy)))
3325  {
3326  SG_SINFO("leaving TParameter::compare_ptype(): PT_SGOBJECT "
3327  "equals returned false\n");
3328  return false;
3329  }
3330  }
3331  else
3332  {
3333  if (!(casted2->equals(casted1, accuracy)))
3334  {
3335  SG_SINFO("leaving TParameter::compare_ptype(): PT_SGOBJECT "
3336  "equals returned false\n");
3337  return false;
3338  }
3339 
3340  }
3341  break;
3342  }
3343  default:
3344  SG_SERROR("TParameter::compare_ptype(): Encountered unknown primitive"
3345  "-type: %d\n", ptype);
3346  break;
3347  }
3348 
3349  SG_SDEBUG("leaving TParameter::compare_ptype(): Data are equal\n");
3350  return true;
3351 }
3352 
3353 bool TParameter::copy_ptype(EPrimitiveType ptype, void* source, void* target)
3354 {
3355  SG_SDEBUG("entering TParameter::copy_ptype()\n");
3356 
3357  /* rather than using sg_memcpy, use the cumbersome way here and cast all types.
3358  * This makes it so much easier to debug code.
3359  * Copy full stype if this is too slow */
3360  switch (ptype)
3361  {
3362  case PT_BOOL:
3363  {
3364  *((bool*)target)=*((bool*)source);
3365  SG_SDEBUG("after copy of ptype PT_BOOL: source %d, target %d\n",
3366  *((bool*)source), *((bool*)target));
3367  break;
3368  }
3369  case PT_CHAR:
3370  {
3371  *((char*)target)=*((char*)source);
3372  SG_SDEBUG("after copy of ptype PT_CHAR: source %c, target %c\n",
3373  *((char*)source), *((char*)target));
3374  break;
3375  }
3376  case PT_INT8:
3377  {
3378  *((int8_t*)target)=*((int8_t*)source);
3379  SG_SDEBUG("after copy of ptype PT_INT8: source %d, target %d\n",
3380  *((int8_t*)source), *((int8_t*)target));
3381  break;
3382  }
3383  case PT_UINT8:
3384  {
3385  *((uint8_t*)target)=*((uint8_t*)source);
3386  SG_SDEBUG("after copy of ptype PT_UINT8: source %d, target %d\n",
3387  *((uint8_t*)source), *((uint8_t*)target));
3388  break;
3389  }
3390  case PT_INT16:
3391  {
3392  *((int16_t*)target)=*((int16_t*)source);
3393  SG_SDEBUG("after copy of ptype PT_INT16: source %d, target %d\n",
3394  *((int16_t*)source), *((int16_t*)target));
3395  break;
3396  }
3397  case PT_UINT16:
3398  {
3399  *((uint16_t*)target)=*((uint16_t*)source);
3400  SG_SDEBUG("after copy of ptype PT_UINT16: source %d, target %d\n",
3401  *((uint16_t*)source), *((uint16_t*)target));
3402  break;
3403  }
3404  case PT_INT32:
3405  {
3406  *((int32_t*)target)=*((int32_t*)source);
3407  SG_SDEBUG("after copy of ptype PT_INT32: source %d, target %d\n",
3408  *((int32_t*)source), *((int32_t*)target));
3409  break;
3410  }
3411  case PT_UINT32:
3412  {
3413  *((uint32_t*)target)=*((uint32_t*)source);
3414  SG_SDEBUG("after copy of ptype PT_UINT32: source %d, target %d\n",
3415  *((uint32_t*)source), *((uint32_t*)target));
3416  break;
3417  }
3418  case PT_INT64:
3419  {
3420  *((int64_t*)target)=*((int64_t*)source);
3421  SG_SDEBUG("after copy of ptype PT_INT64: source %d, target %d\n",
3422  *((int64_t*)source), *((int64_t*)target));
3423  break;
3424  }
3425  case PT_UINT64:
3426  {
3427  *((uint64_t*)target)=*((uint64_t*)source);
3428  SG_SDEBUG("after copy of ptype PT_UINT64: source %d, target %d\n",
3429  *((uint64_t*)source), *((uint64_t*)target));
3430  break;
3431  }
3432  case PT_FLOAT32:
3433  {
3434  *((float32_t*)target)=*((float32_t*)source);
3435  SG_SDEBUG("after copy of ptype PT_FLOAT32: source %f, target %f\n",
3436  *((float32_t*)source), *((float32_t*)target));
3437  break;
3438  }
3439  case PT_FLOAT64:
3440  {
3441  *((float64_t*)target)=*((float64_t*)source);
3442  SG_SDEBUG("after copy of ptype PT_FLOAT64: source %f, target %f\n",
3443  *((float64_t*)source), *((float64_t*)target));
3444  break;
3445  }
3446  case PT_FLOATMAX:
3447  {
3448  *((floatmax_t*)target)=*((floatmax_t*)source);
3449  SG_SDEBUG("after copy of ptype PT_FLOATMAX: source %Lf, target %Lf\n",
3450  *((floatmax_t*)source), *((floatmax_t*)target));
3451  break;
3452  }
3453  case PT_COMPLEX128:
3454  {
3455  *((complex128_t*)target)=*((complex128_t*)source);
3456  SG_SDEBUG("after copy of ptype PT_COMPLEX128: "
3457  "source real %f, target real %f,"
3458  "source imag %f, target imag %f,"
3459  "\n",
3460  ((complex128_t*)source)->real(), ((complex128_t*)target)->real(),
3461  ((complex128_t*)source)->imag(), ((complex128_t*)target)->imag());
3462  break;
3463  }
3464  case PT_SGOBJECT:
3465  {
3466  CSGObject* casted1=*((CSGObject**)source);
3467  CSGObject* casted2=*((CSGObject**)target);
3468 
3469  /* important not to call methods on NULL */
3470  if (!casted1 && ! casted2)
3471  {
3472  SG_SDEBUG("leaving TParameter::copy_ptype(): Both SGObjects are NULL\n");
3473  return true;
3474  }
3475 
3476  /* make sure to not call NULL methods */
3477  if (casted1)
3478  {
3479  /* in case of overwriting old objects */
3480  SG_UNREF(*((CSGObject**)target));
3481  *((CSGObject**)target) = casted1->clone();
3482  }
3483 
3484  break;
3485  }
3486  default:
3487  SG_SERROR("TParameter::compare_ptype(): Encountered unknown primitive"
3488  "-type: %d\n", ptype);
3489  return false;
3490  break;
3491  }
3492 
3493  SG_SDEBUG("leaving TParameter::copy_ptype(): Copy successful\n");
3494  return true;
3495 }
3496 
3497 bool TParameter::compare_stype(EStructType stype, EPrimitiveType ptype,
3498  void* data1, void* data2, float64_t accuracy, bool tolerant)
3499 {
3500  SG_SDEBUG("entering TParameter::compare_stype()\n");
3501 
3502  size_t size_ptype=TSGDataType::sizeof_ptype(ptype);
3503 
3504  /* Avoid comparing NULL */
3505  if (!data1 && !data2)
3506  {
3507  SG_SDEBUG("leaving TParameter::compare_stype(): both data are NULL\n");
3508  return true;
3509  }
3510 
3511  /* If one is NULL, data are not equal */
3512  if ((data1 && !data2) || (!data1 && data2))
3513  {
3514  SG_SINFO("leaving TParameter::compare_stype(): data1 is at %p while "
3515  "data2 is at %p\n", data1, data2);
3516  return false;
3517  }
3518 
3519  switch (stype)
3520  {
3521  case ST_NONE:
3522  {
3523  SG_SDEBUG("ST_NONE\n");
3524  return TParameter::compare_ptype(ptype, data1, data2, accuracy, tolerant);
3525  break;
3526  }
3527  case ST_SPARSE:
3528  {
3529  SG_SDEBUG("ST_SPARSE\n");
3530  SGSparseVector<char>* spr_ptr1 = (SGSparseVector<char>*) data1;
3531  SGSparseVector<char>* spr_ptr2 = (SGSparseVector<char>*) data2;
3532 
3533  if (spr_ptr1->num_feat_entries != spr_ptr2->num_feat_entries)
3534  {
3535  SG_SINFO("leaving TParameter::compare_stype(): Length of "
3536  "sparse vector1 (%d) is different of vector 2 (%d)\n",
3537  spr_ptr1->num_feat_entries, spr_ptr2->num_feat_entries);
3538  return false;
3539  }
3540 
3541  SG_SDEBUG("Comparing sparse vectors\n");
3542  for (index_t i=0; i<spr_ptr1->num_feat_entries; ++i)
3543  {
3544  SG_SDEBUG("Comparing sparse entry %d at offset %d\n", i,
3546 
3548  ((char*) spr_ptr1->features + i*TSGDataType
3549  ::sizeof_sparseentry(ptype));
3551  ((char*) spr_ptr2->features + i*TSGDataType
3552  ::sizeof_sparseentry(ptype));
3553 
3554  /* sparse entries have an offset of the enty pointer depending
3555  * on type. Since I cast everything down to char, I need to remove
3556  * the char offset and add the offset of the ptype */
3557  index_t char_offset=TSGDataType::offset_sparseentry(PT_CHAR);
3558  index_t ptype_offset=TSGDataType::offset_sparseentry(ptype);
3559  void* pointer1=&(cur1->entry)-char_offset+ptype_offset;
3560  void* pointer2=&(cur2->entry)-char_offset+ptype_offset;
3561 
3562  if (!TParameter::compare_ptype(ptype, pointer1,
3563  pointer2, accuracy, tolerant))
3564  {
3565  SG_SINFO("leaving TParameter::compare_stype(): Data of"
3566  " sparse vector element is different\n");
3567  return false;
3568  }
3569 
3570  /* also compare feature indices */
3571  if (cur2->feat_index!=cur1->feat_index)
3572  {
3573  SG_SINFO("leaving TParameter::compare_stype(): Feature "
3574  "index of sparse vector element is different. "
3575  "source: %d, target: %d\n",
3576  cur1->feat_index, cur2->feat_index);
3577  return false;
3578  }
3579  }
3580  break;
3581  }
3582  case ST_STRING:
3583  {
3584  SG_SDEBUG("ST_STRING\n");
3585  SGString<char>* str_ptr1 = (SGString<char>*) data1;
3586  SGString<char>* str_ptr2 = (SGString<char>*) data2;
3587 
3588  if (str_ptr1->slen != str_ptr2->slen)
3589  {
3590  SG_SINFO("leaving TParameter::compare_stype(): Length of "
3591  "string1 (%d) is different of string2 (%d)\n",
3592  str_ptr1->slen, str_ptr2->slen);
3593  return false;
3594  }
3595 
3596  SG_SDEBUG("Comparing strings\n");
3597  for (index_t i=0; i<str_ptr1->slen; ++i)
3598  {
3599  SG_SDEBUG("Comparing string element %d at offset %d\n", i,
3600  i*size_ptype);
3601  void* pointer1=str_ptr1->string+i*size_ptype;
3602  void* pointer2=str_ptr2->string+i*size_ptype;
3603 
3604  if (!TParameter::compare_ptype(ptype, pointer1,
3605  pointer2, accuracy, tolerant))
3606  {
3607  SG_SINFO("leaving TParameter::compare_stype(): Data of"
3608  " string element is different\n");
3609  return false;
3610  }
3611  }
3612  break;
3613  }
3614  default:
3615  {
3616  SG_SERROR("TParameter::compare_stype(): Undefined struct type\n");
3617  break;
3618  }
3619  }
3620 
3621  SG_SDEBUG("leaving TParameter::compare_stype(): Data were equal\n");
3622  return true;
3623 }
3624 
3625 bool TParameter::copy_stype(EStructType stype, EPrimitiveType ptype,
3626  void* source, void* target)
3627 {
3628  SG_SDEBUG("entering TParameter::copy_stype()\n");
3629  size_t size_ptype=TSGDataType::sizeof_ptype(ptype);
3630 
3631  /* Heiko Strathmann: While I know that copying the stypes string and sparse
3632  * element wise is slower than doing the full things, it is way easier to
3633  * program and to debug since I already made sure that copy_ptype works as
3634  * intended. In addition, strings and vectors of SGObjects can be treated
3635  * recursively this way (we dont have cases for this currently, June 2013,
3636  * but they can be added without having to modify this code)
3637  *
3638  * Therefore, this code is very close to the the equals code for
3639  * stypes. If it turns out to be too slow (which I doubt), stypes can be
3640  * copied with sg_memcpy over the full memory blocks */
3641 
3642  switch (stype)
3643  {
3644  case ST_NONE:
3645  {
3646  SG_SDEBUG("ST_NONE\n");
3647  return TParameter::copy_ptype(ptype, source, target);
3648  break;
3649  }
3650  case ST_STRING:
3651  {
3652  SG_SDEBUG("ST_STRING\n");
3653  SGString<char>* source_ptr = (SGString<char>*) source;
3654  SGString<char>* target_ptr = (SGString<char>*) target;
3655 
3656  if (source_ptr->slen != target_ptr->slen)
3657  {
3658  SG_SDEBUG("string lengths different (source: %d vs target: %d),"
3659  " freeing memory.\n", source_ptr->slen, target_ptr->slen);
3660 
3661  /* if string have different lengths, free data and make equal */
3662  SG_FREE(target_ptr->string);
3663  target_ptr->string=NULL;
3664  target_ptr->slen=0;
3665  }
3666 
3667  if (!target_ptr->string)
3668  {
3669  /* allocate memory if data is NULL */
3670  size_t num_bytes=source_ptr->slen * size_ptype;
3671 
3672  SG_SDEBUG("target string data NULL, allocating %d bytes.\n",
3673  num_bytes);
3674  target_ptr->string=SG_MALLOC(char, num_bytes);
3675  target_ptr->slen=source_ptr->slen;
3676  }
3677 
3678  SG_SDEBUG("Copying strings\n");
3679  for (index_t i=0; i<source_ptr->slen; ++i)
3680  {
3681  SG_SDEBUG("Copying string element %d at offset %d\n", i,
3682  i*size_ptype);
3683  void* pointer1=source_ptr->string+i*size_ptype;
3684  void* pointer2=target_ptr->string+i*size_ptype;
3685 
3686  if (!TParameter::copy_ptype(ptype, pointer1, pointer2))
3687  {
3688  SG_SDEBUG("leaving TParameter::copy_stype(): Copy of string"
3689  " element failed.\n");
3690  return false;
3691  }
3692  }
3693  break;
3694  }
3695  case ST_SPARSE:
3696  {
3697  SG_SDEBUG("ST_SPARSE\n");
3698  SGSparseVector<char>* source_ptr = (SGSparseVector<char>*) source;
3699  SGSparseVector<char>* target_ptr = (SGSparseVector<char>*) target;
3700 
3701  if (source_ptr->num_feat_entries != target_ptr->num_feat_entries)
3702  {
3703  SG_SDEBUG("sparse vector lengths different (source: %d vs target: %d),"
3704  " freeing memory.\n",
3705  source_ptr->num_feat_entries, target_ptr->num_feat_entries);
3706 
3707  /* if string have different lengths, free data and make equal */
3708  SG_FREE(target_ptr->features);
3709  target_ptr->features=NULL;
3710  target_ptr->num_feat_entries=0;
3711  }
3712 
3713  if (!target_ptr->features)
3714  {
3715  /* allocate memory if data is NULL */
3716  size_t num_bytes=source_ptr->num_feat_entries *
3718 
3719  SG_SDEBUG("target sparse data NULL, allocating %d bytes.\n",
3720  num_bytes);
3721  target_ptr->features=(SGSparseVectorEntry<char>*)SG_MALLOC(char, num_bytes);
3722  target_ptr->num_feat_entries=source_ptr->num_feat_entries;
3723  }
3724 
3725  SG_SDEBUG("Copying sparse vectors\n");
3726  for (index_t i=0; i<source_ptr->num_feat_entries; ++i)
3727  {
3728  SG_SDEBUG("Copying sparse entry %d at offset %d\n", i,
3730 
3732  ((char*) source_ptr->features + i*TSGDataType
3733  ::sizeof_sparseentry(ptype));
3735  ((char*) target_ptr->features + i*TSGDataType
3736  ::sizeof_sparseentry(ptype));
3737 
3738  /* sparse entries have an offset of the enty pointer depending
3739  * on type. Since I cast everything down to char, I need to remove
3740  * the char offset and add the offset of the ptype */
3741  index_t char_offset=TSGDataType::offset_sparseentry(PT_CHAR);
3742  index_t ptype_offset=TSGDataType::offset_sparseentry(ptype);
3743  void* pointer1=&(cur1->entry)-char_offset+ptype_offset;
3744  void* pointer2=&(cur2->entry)-char_offset+ptype_offset;
3745 
3746  if (!TParameter::copy_ptype(ptype, pointer1, pointer2))
3747  {
3748  SG_SDEBUG("leaving TParameter::copy_stype(): Copy of sparse"
3749  " vector element failed\n");
3750  return false;
3751  }
3752 
3753  /* afterwards, copy feature indices, wich are the data before
3754  * the avove offeet */
3755  cur2->feat_index=cur1->feat_index;
3756  }
3757  break;
3758  }
3759  default:
3760  {
3761  SG_SERROR("TParameter::copy_stype(): Undefined struct type\n");
3762  return false;
3763  break;
3764  }
3765  }
3766 
3767  SG_SDEBUG("leaving TParameter::copy_stype(): Copy successful\n");
3768  return true;
3769 }
3770 
3772 {
3773  SG_SDEBUG("entering TParameter::copy()\n");
3774 
3775  if (!target)
3776  {
3777  SG_SDEBUG("leaving TParameter::copy(): other parameter is NULL\n");
3778  return false;
3779  }
3780 
3781  if (!m_parameter)
3782  {
3783  SG_SDEBUG("leaving TParameter::copy(): m_parameter of source is NULL\n");
3784  return false;
3785  }
3786 
3787  if (!target->m_parameter)
3788  {
3789  SG_SDEBUG("leaving TParameter::copy(): m_parameter of target is NULL\n");
3790  return false;
3791  }
3792 
3793  if (strcmp(m_name, target->m_name))
3794  {
3795  SG_SDEBUG("leaving TParameter::copy(): name \"%s\" is different from"
3796  " target parameter's "
3797  "name \"%s\"\n", m_name, target->m_name);
3798  return false;
3799  }
3800 
3801  SG_SDEBUG("Comparing datatypes without length\n");
3803  {
3804  SG_SDEBUG("leaving TParameter::copy(): type of \"%s\" is different "
3805  "from target parameter's \"%s\" type\n", m_name, target->m_name);
3806  return false;
3807  }
3808 
3809  switch (m_datatype.m_ctype)
3810  {
3811  case CT_SCALAR:
3812  {
3813  SG_SDEBUG("CT_SCALAR\n");
3816  target->m_parameter))
3817  {
3818  SG_SDEBUG("leaving TParameter::copy(): scalar data copy error\n");
3819  return false;
3820  }
3821  break;
3822  }
3823  case CT_VECTOR: case CT_SGVECTOR:
3824  {
3825  SG_SDEBUG("CT_VECTOR or CT_SGVECTOR\n");
3826 
3827  /* if sizes are different or memory is not allocated, do that */
3828  if (!m_datatype.equals(target->m_datatype))
3829  {
3830  SG_SDEBUG("changing size of target vector and freeing memory\n");
3831  /* first case: different sizes, free target memory */
3832  SG_FREE(*(char**)target->m_parameter);
3833  *(char**)target->m_parameter=NULL;
3834 
3835  }
3836 
3837  /* check whether target m_parameter data contains NULL, if yes
3838  * create if the length is non-zero */
3839  if (*(char**)target->m_parameter==NULL && *m_datatype.m_length_y>0)
3840  {
3841  size_t num_bytes=*m_datatype.m_length_y * m_datatype.sizeof_stype();
3842  SG_SDEBUG("allocating %d bytes memory for target vector\n", num_bytes);
3843 
3844  *(char**)target->m_parameter=SG_MALLOC(char, num_bytes);
3845  /* check whether ptype is SGOBJECT, if yes we need to initialize
3846  the memory with NULL for the way copy_ptype handles it */
3847  if (m_datatype.m_ptype==PT_SGOBJECT || m_datatype.m_stype==ST_STRING)
3848  memset(*(void**)target->m_parameter, 0, num_bytes);
3849 
3850  /* use length of source */
3852  }
3853 
3854  /* now start actual copying, assume that sizes are equal and memory
3855  * is there */
3856  ASSERT(m_datatype.equals(target->m_datatype));
3857 
3858  /* x is number of processed bytes */
3859  index_t x=0;
3860  SG_SDEBUG("length_y: %d\n", *m_datatype.m_length_y)
3861  for (index_t i=0; i<*m_datatype.m_length_y; ++i)
3862  {
3863  SG_SDEBUG("copying element %d which is %d bytes from start\n",
3864  i, x);
3865 
3866  void* pointer_a=&((*(char**)m_parameter)[x]);
3867  void* pointer_b=&((*(char**)target->m_parameter)[x]);
3868 
3870  m_datatype.m_ptype, pointer_a, pointer_b))
3871  {
3872  SG_SDEBUG("leaving TParameter::copy(): vector element "
3873  "copy error\n");
3874  return false;
3875  }
3876 
3877  x=x+(m_datatype.sizeof_stype());
3878  }
3879 
3880  break;
3881  }
3882  case CT_MATRIX: case CT_SGMATRIX:
3883  {
3884  SG_SDEBUG("CT_MATRIX or CT_SGMATRIX\n");
3885 
3886  /* if sizes are different or memory is not allocated, do that */
3887  if (!m_datatype.equals(target->m_datatype))
3888  {
3889  SG_SDEBUG("changing size of target vector and freeing memory\n");
3890  /* first case: different sizes, free target memory */
3891  SG_FREE(*(char**)target->m_parameter);
3892  *(char**)target->m_parameter=NULL;
3893  }
3894 
3895  /* check whether target m_parameter data contains NULL, if yes, create */
3896  if (*(char**)target->m_parameter==NULL)
3897  {
3898  SG_SDEBUG("allocating memory for target vector\n");
3899  size_t num_bytes=0;
3900  /* for ST_SPARSE allocate only for a vector of m_length_y */
3901  if (m_datatype.m_stype==ST_SPARSE)
3903  else
3904  num_bytes=*m_datatype.m_length_y *
3906 
3907  *(char**)target->m_parameter=SG_MALLOC(char, num_bytes);
3908 
3909  /* check whether ptype is SGOBJECT, if yes we need to initialize
3910  the memory with NULL for the way copy_ptype handles it */
3911  if (m_datatype.m_ptype==PT_SGOBJECT)
3912  memset(*(void**)target->m_parameter, 0, num_bytes);
3913 
3914  /* use length of source */
3917 
3918  SG_SDEBUG("%d bytes are allocated\n", num_bytes);
3919  }
3920 
3921  /* now start actual copying, assume that sizes are equal and memory
3922  * is there */
3923  ASSERT(m_datatype.equals(target->m_datatype));
3924 
3925  /* x is number of processed bytes */
3926  index_t x=0;
3927  SG_SDEBUG("length_y: %d\n", *m_datatype.m_length_y)
3928  SG_SDEBUG("length_x: %d\n", *m_datatype.m_length_x)
3929  int64_t length=0;
3930  /* for ST_SPARSE allocate iterate over a vector of m_length_y */
3931  if (m_datatype.m_stype==ST_SPARSE)
3932  length=(*m_datatype.m_length_y);
3933  else
3934  length=(*m_datatype.m_length_y) * (*m_datatype.m_length_x);
3935  for (index_t i=0; i<length; ++i)
3936  {
3937  SG_SDEBUG("copying element %d which is %d byes from start\n",
3938  i, x);
3939 
3940  void* pointer_a=&((*(char**)m_parameter)[x]);
3941  void* pointer_b=&((*(char**)target->m_parameter)[x]);
3942 
3944  m_datatype.m_ptype, pointer_a, pointer_b))
3945  {
3946  SG_SDEBUG("leaving TParameter::copy(): vector element "
3947  "differs\n");
3948  return false;
3949  }
3950 
3951  /* For ST_SPARSE, the iteration is on the pointer of SGSparseVectors */
3952  if (m_datatype.m_stype==ST_SPARSE)
3953  x=x+(m_datatype.sizeof_stype());
3954  else
3955  x=x+(m_datatype.sizeof_ptype());
3956  }
3957 
3958  break;
3959  }
3960  case CT_NDARRAY:
3961  {
3962  SG_SDEBUG("CT_NDARRAY\n");
3963  SG_SERROR("TParameter::copy(): Not yet implemented for "
3964  "CT_NDARRAY!\n");
3965  break;
3966  }
3967  case CT_UNDEFINED: default:
3968  SG_SERROR("Implementation error: undefined container type\n");
3969  break;
3970  }
3971 
3972  SG_SDEBUG("leaving TParameter::copy(): Copy successful\n");
3973  return true;
3974 }
template class SGSparseMatrix
std::complex< float64_t > complex128_t
Definition: common.h:77
EStructType m_stype
Definition: DataType.h:73
int32_t index_t
Definition: common.h:72
virtual int32_t get_num_parameters()
virtual CSGObject * clone()
Definition: SGObject.cpp:729
static size_t offset_sparseentry(EPrimitiveType ptype)
Definition: DataType.cpp:308
#define SG_SWARNING(...)
Definition: SGIO.h:177
bool operator==(const TParameter &other) const
Definition: Parameter.cpp:2946
TParameter * get_parameter(int32_t idx)
index_t * m_length_x
Definition: DataType.h:80
parameter struct
#define REQUIRE(x,...)
Definition: SGIO.h:205
size_t sizeof_ptype() const
Definition: DataType.cpp:183
int64_t get_num_elements()
Definition: DataType.cpp:464
static bool compare_stype(EStructType stype, EPrimitiveType ptype, void *data1, void *data2, float64_t accuracy=0.0, bool tolerant=false)
Definition: Parameter.cpp:3497
virtual void print(const char *prefix="")
Definition: Parameter.cpp:2763
index_t num_cols
Definition: SGMatrix.h:465
#define SG_SNOTIMPLEMENTED
Definition: SGIO.h:197
static void ptype_to_string(char *dest, EPrimitiveType ptype, size_t n)
Definition: DataType.cpp:365
#define SG_REF(x)
Definition: SGObject.h:52
Datatypes that shogun supports.
Definition: DataType.h:68
index_t num_rows
Definition: SGMatrix.h:463
virtual bool load(CSerializableFile *file, const char *prefix="")
Definition: Parameter.cpp:2782
bool operator<(const TParameter &other) const
Definition: Parameter.cpp:2953
bool equals_without_length(TSGDataType other)
Definition: DataType.cpp:67
bool equals(TParameter *other, float64_t accuracy=0.0, bool tolerant=false)
Definition: Parameter.cpp:2963
shogun string
virtual void add_type(const TSGDataType *type, void *param, const char *name, const char *description)
Definition: Parameter.cpp:2736
bool save(CSerializableFile *file, const char *prefix="")
Definition: Parameter.cpp:2514
TParameter(const TSGDataType *datatype, void *parameter, const char *name, const char *description)
Definition: Parameter.cpp:1783
void add(bool *param, const char *name, const char *description="")
Definition: Parameter.cpp:38
TSGDataType m_datatype
index_t vlen
Definition: SGVector.h:545
CSGObject * new_sgserializable(const char *sgserializable_name, EPrimitiveType generic)
static T product(T *vec, int32_t len)
Return the product of the vectors elements.
Definition: SGVector.h:408
#define SG_SPRINT(...)
Definition: SGIO.h:179
DynArray< TParameter * > m_params
static bool compare_ptype(EPrimitiveType ptype, void *data1, void *data2, float64_t accuracy=0.0, bool tolerant=false)
Definition: Parameter.cpp:3108
Parameter class.
#define ASSERT(x)
Definition: SGIO.h:200
index_t num_features
total number of features
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:125
SGIO * sg_io
Definition: init.cpp:38
double float64_t
Definition: common.h:60
long double floatmax_t
Definition: common.h:61
#define STRING_LEN
Definition: common.h:65
virtual bool save(CSerializableFile *file, const char *prefix="")
Definition: Parameter.cpp:2770
size_t sizeof_stype() const
Definition: DataType.cpp:177
SGSparseVector< T > * sparse_matrix
array of sparse vectors of size num_vectors
void print(const char *prefix)
Definition: Parameter.cpp:1809
SGSparseVectorEntry< T > * features
static bool copy_ptype(EPrimitiveType ptype, void *source, void *target)
Definition: Parameter.cpp:3353
void get_incremental_hash(uint32_t &hash, uint32_t &carry, uint32_t &total_length)
Definition: Parameter.cpp:2424
virtual bool equals(CSGObject *other, float64_t accuracy=0.0, bool tolerant=false)
Definition: SGObject.cpp:651
index_t * m_length_y
Definition: DataType.h:78
void set_from_parameters(Parameter *params)
Definition: Parameter.cpp:2791
float float32_t
Definition: common.h:59
void to_string(char *dest, size_t n) const
Definition: DataType.cpp:145
EContainerType m_ctype
Definition: DataType.h:71
#define SG_UNREF(x)
Definition: SGObject.h:53
bool contains_parameter(const char *name)
Definition: Parameter.cpp:2935
void add_vector(bool **param, index_t *length, const char *name, const char *description="")
Definition: Parameter.cpp:335
virtual ~Parameter()
Definition: Parameter.cpp:2727
static void IncrementalMurmurHash3(uint32_t *hash, uint32_t *carry, uint8_t *data, int32_t len)
Definition: Hash.cpp:371
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
bool load(CSerializableFile *file, const char *prefix="")
Definition: Parameter.cpp:2613
#define SG_SDEBUG(...)
Definition: SGIO.h:167
template class SGSparseVectorEntry
Definition: File.h:23
#define PT_NOT_GENERIC
Definition: DataType.h:21
#define SG_SERROR(...)
Definition: SGIO.h:178
void add_parameters(Parameter *params)
Definition: Parameter.cpp:2925
#define SG_SINFO(...)
Definition: SGIO.h:172
bool copy(TParameter *target)
Definition: Parameter.cpp:3771
bool equals(TSGDataType other)
Definition: DataType.cpp:95
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry* vector is orde...
index_t slen
Definition: SGString.h:79
char string_t[STRING_LEN]
Definition: common.h:67
EPrimitiveType m_ptype
Definition: DataType.h:75
index_t num_vectors
total number of vectors
void add_matrix(bool **param, index_t *length_y, index_t *length_x, const char *name, const char *description="")
Definition: Parameter.cpp:944
static size_t sizeof_sparseentry(EPrimitiveType ptype)
Definition: DataType.cpp:279
static T abs(T a)
Definition: Math.h:175
static bool copy_stype(EStructType stype, EPrimitiveType ptype, void *source, void *target)
Definition: Parameter.cpp:3625
bool operator>(const TParameter &other) const
Definition: Parameter.cpp:2958

SHOGUN Machine Learning Toolbox - Documentation