SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Parameter.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2010 Soeren Sonnenburg
8  * Written (W) 2011 Heiko Strathmann
9  * Copyright (C) 2010 Berlin Institute of Technology
10  */
11 
12 #include <shogun/base/Parameter.h>
13 #include <shogun/base/class_list.h>
14 
15 using namespace shogun;
16 
17 extern IO* sg_io;
18 
19 /* **************************************************************** */
20 /* Scalar wrappers */
21 
22 void
23 Parameter::add(bool* param, const char* name,
24  const char* description) {
25  TSGDataType type(CT_SCALAR, ST_NONE, PT_BOOL);
26  add_type(&type, param, name, description);
27 }
28 
29 void
30 Parameter::add(char* param, const char* name,
31  const char* description) {
32  TSGDataType type(CT_SCALAR, ST_NONE, PT_CHAR);
33  add_type(&type, param, name, description);
34 }
35 
36 void
37 Parameter::add(int8_t* param, const char* name,
38  const char* description) {
39  TSGDataType type(CT_SCALAR, ST_NONE, PT_INT8);
40  add_type(&type, param, name, description);
41 }
42 
43 void
44 Parameter::add(uint8_t* param, const char* name,
45  const char* description) {
46  TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT8);
47  add_type(&type, param, name, description);
48 }
49 
50 void
51 Parameter::add(int16_t* param, const char* name,
52  const char* description) {
53  TSGDataType type(CT_SCALAR, ST_NONE, PT_INT16);
54  add_type(&type, param, name, description);
55 }
56 
57 void
58 Parameter::add(uint16_t* param, const char* name,
59  const char* description) {
60  TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT16);
61  add_type(&type, param, name, description);
62 }
63 
64 void
65 Parameter::add(int32_t* param, const char* name,
66  const char* description) {
67  TSGDataType type(CT_SCALAR, ST_NONE, PT_INT32);
68  add_type(&type, param, name, description);
69 }
70 
71 void
72 Parameter::add(uint32_t* param, const char* name,
73  const char* description) {
74  TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT32);
75  add_type(&type, param, name, description);
76 }
77 
78 void
79 Parameter::add(int64_t* param, const char* name,
80  const char* description) {
81  TSGDataType type(CT_SCALAR, ST_NONE, PT_INT64);
82  add_type(&type, param, name, description);
83 }
84 
85 void
86 Parameter::add(uint64_t* param, const char* name,
87  const char* description) {
88  TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT64);
89  add_type(&type, param, name, description);
90 }
91 
92 void
93 Parameter::add(float32_t* param, const char* name,
94  const char* description) {
95  TSGDataType type(CT_SCALAR, ST_NONE, PT_FLOAT32);
96  add_type(&type, param, name, description);
97 }
98 
99 void
100 Parameter::add(float64_t* param, const char* name,
101  const char* description) {
102  TSGDataType type(CT_SCALAR, ST_NONE, PT_FLOAT64);
103  add_type(&type, param, name, description);
104 }
105 
106 void
107 Parameter::add(floatmax_t* param, const char* name,
108  const char* description) {
109  TSGDataType type(CT_SCALAR, ST_NONE, PT_FLOATMAX);
110  add_type(&type, param, name, description);
111 }
112 
113 void
115  const char* name, const char* description) {
116  TSGDataType type(CT_SCALAR, ST_NONE, PT_SGOBJECT);
117  add_type(&type, param, name, description);
118 }
119 
120 void
121 Parameter::add(SGString<bool>* param, const char* name,
122  const char* description) {
123  TSGDataType type(CT_SCALAR, ST_STRING, PT_BOOL);
124  add_type(&type, param, name, description);
125 }
126 
127 void
128 Parameter::add(SGString<char>* param, const char* name,
129  const char* description) {
130  TSGDataType type(CT_SCALAR, ST_STRING, PT_CHAR);
131  add_type(&type, param, name, description);
132 }
133 
134 void
135 Parameter::add(SGString<int8_t>* param, const char* name,
136  const char* description) {
137  TSGDataType type(CT_SCALAR, ST_STRING, PT_INT8);
138  add_type(&type, param, name, description);
139 }
140 
141 void
142 Parameter::add(SGString<uint8_t>* param, const char* name,
143  const char* description) {
144  TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT8);
145  add_type(&type, param, name, description);
146 }
147 
148 void
149 Parameter::add(SGString<int16_t>* param, const char* name,
150  const char* description) {
151  TSGDataType type(CT_SCALAR, ST_STRING, PT_INT16);
152  add_type(&type, param, name, description);
153 }
154 
155 void
156 Parameter::add(SGString<uint16_t>* param, const char* name,
157  const char* description) {
158  TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT16);
159  add_type(&type, param, name, description);
160 }
161 
162 void
163 Parameter::add(SGString<int32_t>* param, const char* name,
164  const char* description) {
165  TSGDataType type(CT_SCALAR, ST_STRING, PT_INT32);
166  add_type(&type, param, name, description);
167 }
168 
169 void
170 Parameter::add(SGString<uint32_t>* param, const char* name,
171  const char* description) {
172  TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT32);
173  add_type(&type, param, name, description);
174 }
175 
176 void
177 Parameter::add(SGString<int64_t>* param, const char* name,
178  const char* description) {
179  TSGDataType type(CT_SCALAR, ST_STRING, PT_INT64);
180  add_type(&type, param, name, description);
181 }
182 
183 void
184 Parameter::add(SGString<uint64_t>* param, const char* name,
185  const char* description) {
186  TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT64);
187  add_type(&type, param, name, description);
188 }
189 
190 void
191 Parameter::add(SGString<float32_t>* param, const char* name,
192  const char* description) {
193  TSGDataType type(CT_SCALAR, ST_STRING, PT_FLOAT32);
194  add_type(&type, param, name, description);
195 }
196 
197 void
198 Parameter::add(SGString<float64_t>* param, const char* name,
199  const char* description) {
200  TSGDataType type(CT_SCALAR, ST_STRING, PT_FLOAT64);
201  add_type(&type, param, name, description);
202 }
203 
204 void
205 Parameter::add(SGString<floatmax_t>* param, const char* name,
206  const char* description) {
207  TSGDataType type(CT_SCALAR, ST_STRING, PT_FLOATMAX);
208  add_type(&type, param, name, description);
209 }
210 
211 void
212 Parameter::add(SGSparseVector<bool>* param, const char* name,
213  const char* description) {
214  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_BOOL);
215  add_type(&type, param, name, description);
216 }
217 
218 void
219 Parameter::add(SGSparseVector<char>* param, const char* name,
220  const char* description) {
221  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_CHAR);
222  add_type(&type, param, name, description);
223 }
224 
225 void
226 Parameter::add(SGSparseVector<int8_t>* param, const char* name,
227  const char* description) {
228  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT8);
229  add_type(&type, param, name, description);
230 }
231 
232 void
233 Parameter::add(SGSparseVector<uint8_t>* param, const char* name,
234  const char* description) {
235  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT8);
236  add_type(&type, param, name, description);
237 }
238 
239 void
240 Parameter::add(SGSparseVector<int16_t>* param, const char* name,
241  const char* description) {
242  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT16);
243  add_type(&type, param, name, description);
244 }
245 
246 void
247 Parameter::add(SGSparseVector<uint16_t>* param, const char* name,
248  const char* description) {
249  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT16);
250  add_type(&type, param, name, description);
251 }
252 
253 void
254 Parameter::add(SGSparseVector<int32_t>* param, const char* name,
255  const char* description) {
256  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT32);
257  add_type(&type, param, name, description);
258 }
259 
260 void
261 Parameter::add(SGSparseVector<uint32_t>* param, const char* name,
262  const char* description) {
263  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT32);
264  add_type(&type, param, name, description);
265 }
266 
267 void
268 Parameter::add(SGSparseVector<int64_t>* param, const char* name,
269  const char* description) {
270  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT64);
271  add_type(&type, param, name, description);
272 }
273 
274 void
275 Parameter::add(SGSparseVector<uint64_t>* param, const char* name,
276  const char* description) {
277  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT64);
278  add_type(&type, param, name, description);
279 }
280 
281 void
282 Parameter::add(SGSparseVector<float32_t>* param, const char* name,
283  const char* description) {
284  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_FLOAT32);
285  add_type(&type, param, name, description);
286 }
287 
288 void
289 Parameter::add(SGSparseVector<float64_t>* param, const char* name,
290  const char* description) {
291  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_FLOAT64);
292  add_type(&type, param, name, description);
293 }
294 
295 void
297  const char* description) {
298  TSGDataType type(CT_SCALAR, ST_SPARSE, PT_FLOATMAX);
299  add_type(&type, param, name, description);
300 }
301 
302 /* **************************************************************** */
303 /* Vector wrappers */
304 
305 void
307  bool** param, index_t* length, const char* name,
308  const char* description) {
309  TSGDataType type(CT_VECTOR, ST_NONE, PT_BOOL, length);
310  add_type(&type, param, name, description);
311 }
312 
313 void
315  char** param, index_t* length, const char* name,
316  const char* description) {
317  TSGDataType type(CT_VECTOR, ST_NONE, PT_CHAR, length);
318  add_type(&type, param, name, description);
319 }
320 
321 void
323  int8_t** param, index_t* length, const char* name,
324  const char* description) {
325  TSGDataType type(CT_VECTOR, ST_NONE, PT_INT8, length);
326  add_type(&type, param, name, description);
327 }
328 
329 void
331  uint8_t** param, index_t* length, const char* name,
332  const char* description) {
333  TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT8, length);
334  add_type(&type, param, name, description);
335 }
336 
337 void
339  int16_t** param, index_t* length, const char* name,
340  const char* description) {
341  TSGDataType type(CT_VECTOR, ST_NONE, PT_INT16, length);
342  add_type(&type, param, name, description);
343 }
344 
345 void
347  uint16_t** param, index_t* length, const char* name,
348  const char* description) {
349  TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT16, length);
350  add_type(&type, param, name, description);
351 }
352 
353 void
355  int32_t** param, index_t* length, const char* name,
356  const char* description) {
357  TSGDataType type(CT_VECTOR, ST_NONE, PT_INT32, length);
358  add_type(&type, param, name, description);
359 }
360 
361 void
363  uint32_t** param, index_t* length, const char* name,
364  const char* description) {
365  TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT32, length);
366  add_type(&type, param, name, description);
367 }
368 
369 void
371  int64_t** param, index_t* length, const char* name,
372  const char* description) {
373  TSGDataType type(CT_VECTOR, ST_NONE, PT_INT64, length);
374  add_type(&type, param, name, description);
375 }
376 
377 void
379  uint64_t** param, index_t* length, const char* name,
380  const char* description) {
381  TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT64, length);
382  add_type(&type, param, name, description);
383 }
384 
385 void
387  float32_t** param, index_t* length, const char* name,
388  const char* description) {
389  TSGDataType type(CT_VECTOR, ST_NONE, PT_FLOAT32, length);
390  add_type(&type, param, name, description);
391 }
392 
393 void
395  float64_t** param, index_t* length, const char* name,
396  const char* description) {
397  TSGDataType type(CT_VECTOR, ST_NONE, PT_FLOAT64, length);
398  add_type(&type, param, name, description);
399 }
400 
401 void
403  floatmax_t** param, index_t* length, const char* name,
404  const char* description) {
405  TSGDataType type(CT_VECTOR, ST_NONE, PT_FLOATMAX, length);
406  add_type(&type, param, name, description);
407 }
408 
409 void
411  const char* name, const char* description) {
412  TSGDataType type(CT_VECTOR, ST_NONE, PT_SGOBJECT,
413  length);
414  add_type(&type, param, name, description);
415 }
416 
417 void
419  const char* name, const char* description) {
420  TSGDataType type(CT_VECTOR, ST_STRING, PT_BOOL, length);
421  add_type(&type, param, name, description);
422 }
423 
424 void
426  const char* name, const char* description) {
427  TSGDataType type(CT_VECTOR, ST_STRING, PT_CHAR, length);
428  add_type(&type, param, name, description);
429 }
430 
431 void
433  const char* name, const char* description) {
434  TSGDataType type(CT_VECTOR, ST_STRING, PT_INT8, length);
435  add_type(&type, param, name, description);
436 }
437 
438 void
440  const char* name, const char* description) {
441  TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT8, length);
442  add_type(&type, param, name, description);
443 }
444 
445 void
447  const char* name, const char* description) {
448  TSGDataType type(CT_VECTOR, ST_STRING, PT_INT16, length);
449  add_type(&type, param, name, description);
450 }
451 
452 void
454  const char* name, const char* description) {
455  TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT16, length);
456  add_type(&type, param, name, description);
457 }
458 
459 void
461  const char* name, const char* description) {
462  TSGDataType type(CT_VECTOR, ST_STRING, PT_INT32, length);
463  add_type(&type, param, name, description);
464 }
465 
466 void
468  const char* name, const char* description) {
469  TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT32, length);
470  add_type(&type, param, name, description);
471 }
472 
473 void
475  const char* name, const char* description) {
476  TSGDataType type(CT_VECTOR, ST_STRING, PT_INT64, length);
477  add_type(&type, param, name, description);
478 }
479 
480 void
482  const char* name, const char* description) {
483  TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT64, length);
484  add_type(&type, param, name, description);
485 }
486 
487 void
489  const char* name, const char* description) {
490  TSGDataType type(CT_VECTOR, ST_STRING, PT_FLOAT32, length);
491  add_type(&type, param, name, description);
492 }
493 
494 void
496  const char* name, const char* description) {
497  TSGDataType type(CT_VECTOR, ST_STRING, PT_FLOAT64, length);
498  add_type(&type, param, name, description);
499 }
500 
501 void
503  const char* name, const char* description) {
504  TSGDataType type(CT_VECTOR, ST_STRING, PT_FLOATMAX, length);
505  add_type(&type, param, name, description);
506 }
507 
508 void
510  const char* name, const char* description) {
511  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_BOOL, length);
512  add_type(&type, param, name, description);
513 }
514 
515 void
517  const char* name, const char* description) {
518  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_CHAR, length);
519  add_type(&type, param, name, description);
520 }
521 
522 void
524  const char* name, const char* description) {
525  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT8, length);
526  add_type(&type, param, name, description);
527 }
528 
529 void
531  const char* name, const char* description) {
532  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT8, length);
533  add_type(&type, param, name, description);
534 }
535 
536 void
538  const char* name, const char* description) {
539  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT16, length);
540  add_type(&type, param, name, description);
541 }
542 
543 void
545  const char* name, const char* description) {
546  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT16, length);
547  add_type(&type, param, name, description);
548 }
549 
550 void
552  const char* name, const char* description) {
553  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT32, length);
554  add_type(&type, param, name, description);
555 }
556 
557 void
559  const char* name, const char* description) {
560  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT32, length);
561  add_type(&type, param, name, description);
562 }
563 
564 void
566  const char* name, const char* description) {
567  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT64, length);
568  add_type(&type, param, name, description);
569 }
570 
571 void
573  const char* name, const char* description) {
574  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT64, length);
575  add_type(&type, param, name, description);
576 }
577 
578 void
580  const char* name, const char* description) {
581  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_FLOAT32, length);
582  add_type(&type, param, name, description);
583 }
584 
585 void
587  const char* name, const char* description) {
588  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_FLOAT64, length);
589  add_type(&type, param, name, description);
590 }
591 
592 void
594  const char* name, const char* description) {
595  TSGDataType type(CT_VECTOR, ST_SPARSE, PT_FLOATMAX, length);
596  add_type(&type, param, name, description);
597 }
598 
599 
600 
601 
602 void Parameter::add(SGVector<bool>* param, const char* name,
603  const char* description)
604 {
605  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_BOOL, &param->vlen);
606  add_type(&type, param, name, description);
607 }
608 
609 void Parameter::add(SGVector<char>* param, const char* name,
610  const char* description)
611 {
612  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_CHAR, &param->vlen);
613  add_type(&type, param, name, description);
614 }
615 
616 void Parameter::add(SGVector<int8_t>* param, const char* name,
617  const char* description)
618 {
619  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_INT8, &param->vlen);
620  add_type(&type, param, name, description);
621 }
622 
623 void Parameter::add(SGVector<uint8_t>* param, const char* name,
624  const char* description)
625 {
626  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_UINT8, &param->vlen);
627  add_type(&type, param, name, description);
628 }
629 
630 void Parameter::add(SGVector<int16_t>* param, const char* name,
631  const char* description)
632 {
633  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_INT16, &param->vlen);
634  add_type(&type, param, name, description);
635 }
636 
637 void Parameter::add(SGVector<uint16_t>* param, const char* name,
638  const char* description)
639 {
640  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_UINT16, &param->vlen);
641  add_type(&type, param, name, description);
642 }
643 
644 void Parameter::add(SGVector<int32_t>* param, const char* name,
645  const char* description)
646 {
647  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_INT32, &param->vlen);
648  add_type(&type, param, name, description);
649 }
650 
651 void Parameter::add(SGVector<uint32_t>* param, const char* name,
652  const char* description)
653 {
654  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_UINT32, &param->vlen);
655  add_type(&type, param, name, description);
656 }
657 
658 void Parameter::add(SGVector<int64_t>* param, const char* name,
659  const char* description)
660 {
661  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_INT64, &param->vlen);
662  add_type(&type, param, name, description);
663 }
664 
665 void Parameter::add(SGVector<uint64_t>* param, const char* name,
666  const char* description)
667 {
668  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_UINT64, &param->vlen);
669  add_type(&type, param, name, description);
670 }
671 
672 void Parameter::add(SGVector<float32_t>* param, const char* name,
673  const char* description)
674 {
675  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_FLOAT32, &param->vlen);
676  add_type(&type, param, name, description);
677 }
678 
679 void Parameter::add(SGVector<float64_t>* param, const char* name,
680  const char* description)
681 {
682  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_FLOAT64, &param->vlen);
683  add_type(&type, param, name, description);
684 }
685 
686 void Parameter::add(SGVector<floatmax_t>* param, const char* name,
687  const char* description)
688 {
689  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_FLOATMAX, &param->vlen);
690  add_type(&type, param, name, description);
691 }
692 
693 void Parameter::add(SGVector<CSGObject*>* param, const char* name,
694  const char* description)
695 {
696  TSGDataType type(CT_SGVECTOR, ST_NONE, PT_SGOBJECT, &param->vlen);
697  add_type(&type, param, name, description);
698 }
699 
700 void Parameter::add(SGVector<SGString<bool> >* param, const char* name,
701  const char* description)
702 {
703  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_BOOL, &param->vlen);
704  add_type(&type, param, name, description);
705 }
706 
707 void Parameter::add(SGVector<SGString<char> >* param, const char* name,
708  const char* description)
709 {
710  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_CHAR, &param->vlen);
711  add_type(&type, param, name, description);
712 }
713 
715  const char* name, const char* description)
716 {
717  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_INT8, &param->vlen);
718  add_type(&type, param, name, description);
719 }
720 
722  const char* name, const char* description)
723 {
724  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_UINT8, &param->vlen);
725  add_type(&type, param, name, description);
726 }
727 
729  const char* name, const char* description)
730 {
731  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_INT16, &param->vlen);
732  add_type(&type, param, name, description);
733 }
734 
736  const char* name, const char* description)
737 {
738  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_UINT16, &param->vlen);
739  add_type(&type, param, name, description);
740 }
741 
743  const char* name, const char* description)
744 {
745  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_INT32, &param->vlen);
746  add_type(&type, param, name, description);
747 }
748 
750  const char* name, const char* description)
751 {
752  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_UINT32, &param->vlen);
753  add_type(&type, param, name, description);
754 }
755 
757  const char* name, const char* description)
758 {
759  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_INT64, &param->vlen);
760  add_type(&type, param, name, description);
761 }
762 
764  const char* name, const char* description)
765 {
766  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_UINT64, &param->vlen);
767  add_type(&type, param, name, description);
768 }
769 
771  const char* name, const char* description)
772 {
773  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_FLOAT32, &param->vlen);
774  add_type(&type, param, name, description);
775 }
776 
778  const char* name, const char* description)
779 {
780  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_FLOAT64, &param->vlen);
781  add_type(&type, param, name, description);
782 }
783 
785  const char* name, const char* description)
786 {
787  TSGDataType type(CT_SGVECTOR, ST_STRING, PT_FLOATMAX, &param->vlen);
788  add_type(&type, param, name, description);
789 }
790 
792  const char* name, const char* description)
793 {
794  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_BOOL, &param->vlen);
795  add_type(&type, param, name, description);
796 }
797 
799  const char* name, const char* description)
800 {
801  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_CHAR, &param->vlen);
802  add_type(&type, param, name, description);
803 }
804 
806  const char* name, const char* description)
807 {
808  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_INT8, &param->vlen);
809  add_type(&type, param, name, description);
810 }
811 
813  const char* name, const char* description)
814 {
815  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_UINT8, &param->vlen);
816  add_type(&type, param, name, description);
817 }
818 
820  const char* name, const char* description)
821 {
822  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_INT16, &param->vlen);
823  add_type(&type, param, name, description);
824 }
825 
827  const char* name, const char* description)
828 {
829  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_UINT16, &param->vlen);
830  add_type(&type, param, name, description);
831 }
832 
834  const char* name, const char* description)
835 {
836  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_INT32, &param->vlen);
837  add_type(&type, param, name, description);
838 }
839 
841  const char* name, const char* description)
842 {
843  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_UINT32, &param->vlen);
844  add_type(&type, param, name, description);
845 }
846 
848  const char* name, const char* description)
849 {
850  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_INT64, &param->vlen);
851  add_type(&type, param, name, description);
852 }
853 
855  const char* name, const char* description)
856 {
857  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_UINT64, &param->vlen);
858  add_type(&type, param, name, description);
859 }
860 
862  const char* name, const char* description)
863 {
864  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_FLOAT32, &param->vlen);
865  add_type(&type, param, name, description);
866 }
867 
869  const char* name, const char* description)
870 {
871  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_FLOAT64, &param->vlen);
872  add_type(&type, param, name, description);
873 }
874 
876  const char* name, const char* description)
877 {
878  TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_FLOATMAX, &param->vlen);
879  add_type(&type, param, name, description);
880 }
881 
882 /* **************************************************************** */
883 /* Matrix wrappers */
884 
885 void
887  bool** param, index_t* length_y, index_t* length_x,
888  const char* name, const char* description) {
889  TSGDataType type(CT_MATRIX, ST_NONE, PT_BOOL, length_y,
890  length_x);
891  add_type(&type, param, name, description);
892 }
893 
894 void
896  char** param, index_t* length_y, index_t* length_x,
897  const char* name, const char* description) {
898  TSGDataType type(CT_MATRIX, ST_NONE, PT_CHAR, length_y,
899  length_x);
900  add_type(&type, param, name, description);
901 }
902 
903 void
905  int8_t** param, index_t* length_y, index_t* length_x,
906  const char* name, const char* description) {
907  TSGDataType type(CT_MATRIX, ST_NONE, PT_INT8, length_y,
908  length_x);
909  add_type(&type, param, name, description);
910 }
911 
912 void
914  uint8_t** param, index_t* length_y, index_t* length_x,
915  const char* name, const char* description) {
916  TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT8, length_y,
917  length_x);
918  add_type(&type, param, name, description);
919 }
920 
921 void
923  int16_t** param, index_t* length_y, index_t* length_x,
924  const char* name, const char* description) {
925  TSGDataType type(CT_MATRIX, ST_NONE, PT_INT16, length_y,
926  length_x);
927  add_type(&type, param, name, description);
928 }
929 
930 void
932  uint16_t** param, index_t* length_y, index_t* length_x,
933  const char* name, const char* description) {
934  TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT16, length_y,
935  length_x);
936  add_type(&type, param, name, description);
937 }
938 
939 void
941  int32_t** param, index_t* length_y, index_t* length_x,
942  const char* name, const char* description) {
943  TSGDataType type(CT_MATRIX, ST_NONE, PT_INT32, length_y,
944  length_x);
945  add_type(&type, param, name, description);
946 }
947 
948 void
950  uint32_t** param, index_t* length_y, index_t* length_x,
951  const char* name, const char* description) {
952  TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT32, length_y,
953  length_x);
954  add_type(&type, param, name, description);
955 }
956 
957 void
959  int64_t** param, index_t* length_y, index_t* length_x,
960  const char* name, const char* description) {
961  TSGDataType type(CT_MATRIX, ST_NONE, PT_INT64, length_y,
962  length_x);
963  add_type(&type, param, name, description);
964 }
965 
966 void
968  uint64_t** param, index_t* length_y, index_t* length_x,
969  const char* name, const char* description) {
970  TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT64, length_y,
971  length_x);
972  add_type(&type, param, name, description);
973 }
974 
975 void
977  float32_t** param, index_t* length_y, index_t* length_x,
978  const char* name, const char* description) {
979  TSGDataType type(CT_MATRIX, ST_NONE, PT_FLOAT32, length_y,
980  length_x);
981  add_type(&type, param, name, description);
982 }
983 
984 void
986  float64_t** param, index_t* length_y, index_t* length_x,
987  const char* name, const char* description) {
988  TSGDataType type(CT_MATRIX, ST_NONE, PT_FLOAT64, length_y,
989  length_x);
990  add_type(&type, param, name, description);
991 }
992 
993 void
995  floatmax_t** param, index_t* length_y, index_t* length_x,
996  const char* name, const char* description) {
997  TSGDataType type(CT_MATRIX, ST_NONE, PT_FLOATMAX, length_y,
998  length_x);
999  add_type(&type, param, name, description);
1000 }
1001 
1002 void
1004  CSGObject*** param, index_t* length_y, index_t* length_x,
1005  const char* name, const char* description) {
1006  TSGDataType type(CT_MATRIX, ST_NONE, PT_SGOBJECT,
1007  length_y, length_x);
1008  add_type(&type, param, name, description);
1009 }
1010 
1011 void
1013  index_t* length_y, index_t* length_x,
1014  const char* name, const char* description) {
1015  TSGDataType type(CT_MATRIX, ST_STRING, PT_BOOL, length_y,
1016  length_x);
1017  add_type(&type, param, name, description);
1018 }
1019 
1020 void
1022  index_t* length_y, index_t* length_x,
1023  const char* name, const char* description) {
1024  TSGDataType type(CT_MATRIX, ST_STRING, PT_CHAR, length_y,
1025  length_x);
1026  add_type(&type, param, name, description);
1027 }
1028 
1029 void
1031  index_t* length_y, index_t* length_x,
1032  const char* name, const char* description) {
1033  TSGDataType type(CT_MATRIX, ST_STRING, PT_INT8, length_y,
1034  length_x);
1035  add_type(&type, param, name, description);
1036 }
1037 
1038 void
1040  index_t* length_y, index_t* length_x,
1041  const char* name, const char* description) {
1042  TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT8, length_y,
1043  length_x);
1044  add_type(&type, param, name, description);
1045 }
1046 
1047 void
1049  index_t* length_y, index_t* length_x,
1050  const char* name, const char* description) {
1051  TSGDataType type(CT_MATRIX, ST_STRING, PT_INT16, length_y,
1052  length_x);
1053  add_type(&type, param, name, description);
1054 }
1055 
1056 void
1058  index_t* length_y, index_t* length_x,
1059  const char* name, const char* description) {
1060  TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT16, length_y,
1061  length_x);
1062  add_type(&type, param, name, description);
1063 }
1064 
1065 void
1067  index_t* length_y, index_t* length_x,
1068  const char* name, const char* description) {
1069  TSGDataType type(CT_MATRIX, ST_STRING, PT_INT32, length_y,
1070  length_x);
1071  add_type(&type, param, name, description);
1072 }
1073 
1074 void
1076  index_t* length_y, index_t* length_x,
1077  const char* name, const char* description) {
1078  TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT32, length_y,
1079  length_x);
1080  add_type(&type, param, name, description);
1081 }
1082 
1083 void
1085  index_t* length_y, index_t* length_x,
1086  const char* name, const char* description) {
1087  TSGDataType type(CT_MATRIX, ST_STRING, PT_INT64, length_y,
1088  length_x);
1089  add_type(&type, param, name, description);
1090 }
1091 
1092 void
1094  index_t* length_y, index_t* length_x,
1095  const char* name, const char* description) {
1096  TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT64, length_y,
1097  length_x);
1098  add_type(&type, param, name, description);
1099 }
1100 
1101 void
1103  index_t* length_y, index_t* length_x,
1104  const char* name, const char* description) {
1105  TSGDataType type(CT_MATRIX, ST_STRING, PT_FLOAT32, length_y,
1106  length_x);
1107  add_type(&type, param, name, description);
1108 }
1109 
1110 void
1112  index_t* length_y, index_t* length_x,
1113  const char* name, const char* description) {
1114  TSGDataType type(CT_MATRIX, ST_STRING, PT_FLOAT64, length_y,
1115  length_x);
1116  add_type(&type, param, name, description);
1117 }
1118 
1119 void
1121  index_t* length_y, index_t* length_x,
1122  const char* name, const char* description) {
1123  TSGDataType type(CT_MATRIX, ST_STRING, PT_FLOATMAX, length_y,
1124  length_x);
1125  add_type(&type, param, name, description);
1126 }
1127 
1128 void
1130  index_t* length_y, index_t* length_x,
1131  const char* name, const char* description) {
1132  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_BOOL, length_y,
1133  length_x);
1134  add_type(&type, param, name, description);
1135 }
1136 
1137 void
1139  index_t* length_y, index_t* length_x,
1140  const char* name, const char* description) {
1141  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_CHAR, length_y,
1142  length_x);
1143  add_type(&type, param, name, description);
1144 }
1145 
1146 void
1148  index_t* length_y, index_t* length_x,
1149  const char* name, const char* description) {
1150  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT8, length_y,
1151  length_x);
1152  add_type(&type, param, name, description);
1153 }
1154 
1155 void
1157  index_t* length_y, index_t* length_x,
1158  const char* name, const char* description) {
1159  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT8, length_y,
1160  length_x);
1161  add_type(&type, param, name, description);
1162 }
1163 
1164 void
1166  index_t* length_y, index_t* length_x,
1167  const char* name, const char* description) {
1168  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT16, length_y,
1169  length_x);
1170  add_type(&type, param, name, description);
1171 }
1172 
1173 void
1175  index_t* length_y, index_t* length_x,
1176  const char* name, const char* description) {
1177  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT16, length_y,
1178  length_x);
1179  add_type(&type, param, name, description);
1180 }
1181 
1182 void
1184  index_t* length_y, index_t* length_x,
1185  const char* name, const char* description) {
1186  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT32, length_y,
1187  length_x);
1188  add_type(&type, param, name, description);
1189 }
1190 
1191 void
1193  index_t* length_y, index_t* length_x,
1194  const char* name, const char* description) {
1195  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT32, length_y,
1196  length_x);
1197  add_type(&type, param, name, description);
1198 }
1199 
1200 void
1202  index_t* length_y, index_t* length_x,
1203  const char* name, const char* description) {
1204  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT64, length_y,
1205  length_x);
1206  add_type(&type, param, name, description);
1207 }
1208 
1209 void
1211  index_t* length_y, index_t* length_x,
1212  const char* name, const char* description) {
1213  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT64, length_y,
1214  length_x);
1215  add_type(&type, param, name, description);
1216 }
1217 
1218 void
1220  index_t* length_y, index_t* length_x,
1221  const char* name, const char* description) {
1222  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_FLOAT32, length_y,
1223  length_x);
1224  add_type(&type, param, name, description);
1225 }
1226 
1227 void
1229  index_t* length_y, index_t* length_x,
1230  const char* name, const char* description) {
1231  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_FLOAT64, length_y,
1232  length_x);
1233  add_type(&type, param, name, description);
1234 }
1235 
1236 void
1238  index_t* length_y, index_t* length_x,
1239  const char* name, const char* description) {
1240  TSGDataType type(CT_MATRIX, ST_SPARSE, PT_FLOATMAX, length_y,
1241  length_x);
1242  add_type(&type, param, name, description);
1243 }
1244 
1245 
1246 
1247 
1248 void Parameter::add(SGMatrix<bool>* param, const char* name,
1249  const char* description)
1250 {
1251  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_BOOL, &param->num_rows,
1252  &param->num_cols);
1253  add_type(&type, param, name, description);
1254 }
1255 
1256 void Parameter::add(SGMatrix<char>* param, const char* name,
1257  const char* description)
1258 {
1259  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_CHAR, &param->num_rows,
1260  &param->num_cols);
1261  add_type(&type, param, name, description);
1262 }
1263 
1264 void Parameter::add(SGMatrix<int8_t>* param, const char* name,
1265  const char* description)
1266 {
1267  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_INT8, &param->num_rows,
1268  &param->num_cols);
1269  add_type(&type, param, name, description);
1270 }
1271 
1272 void Parameter::add(SGMatrix<uint8_t>* param, const char* name,
1273  const char* description)
1274 {
1275  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_UINT8, &param->num_rows,
1276  &param->num_cols);
1277  add_type(&type, param, name, description);
1278 }
1279 
1280 void Parameter::add(SGMatrix<int16_t>* param, const char* name,
1281  const char* description)
1282 {
1283  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_INT16, &param->num_rows,
1284  &param->num_cols);
1285  add_type(&type, param, name, description);
1286 }
1287 
1288 void Parameter::add(SGMatrix<uint16_t>* param, const char* name,
1289  const char* description)
1290 {
1291  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_UINT16, &param->num_rows,
1292  &param->num_cols);
1293  add_type(&type, param, name, description);
1294 }
1295 
1296 void Parameter::add(SGMatrix<int32_t>* param, const char* name,
1297  const char* description)
1298 {
1299  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_INT32, &param->num_rows,
1300  &param->num_cols);
1301  add_type(&type, param, name, description);
1302 }
1303 
1304 void Parameter::add(SGMatrix<uint32_t>* param, const char* name,
1305  const char* description)
1306 {
1307  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_UINT32, &param->num_rows,
1308  &param->num_cols);
1309  add_type(&type, param, name, description);
1310 }
1311 
1312 void Parameter::add(SGMatrix<int64_t>* param, const char* name,
1313  const char* description)
1314 {
1315  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_INT64, &param->num_rows,
1316  &param->num_cols);
1317  add_type(&type, param, name, description);
1318 }
1319 
1320 void Parameter::add(SGMatrix<uint64_t>* param, const char* name,
1321  const char* description)
1322 {
1323  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_UINT64, &param->num_rows,
1324  &param->num_cols);
1325  add_type(&type, param, name, description);
1326 }
1327 
1328 void Parameter::add(SGMatrix<float32_t>* param, const char* name,
1329  const char* description)
1330 {
1331  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_FLOAT32, &param->num_rows,
1332  &param->num_cols);
1333  add_type(&type, param, name, description);
1334 }
1335 
1336 void Parameter::add(SGMatrix<float64_t>* param, const char* name,
1337  const char* description)
1338 {
1339  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_FLOAT64, &param->num_rows,
1340  &param->num_cols);
1341  add_type(&type, param, name, description);
1342 }
1343 
1344 void Parameter::add(SGMatrix<floatmax_t>* param, const char* name,
1345  const char* description)
1346 {
1347  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_FLOATMAX, &param->num_rows,
1348  &param->num_cols);
1349  add_type(&type, param, name, description);
1350 }
1351 
1352 void Parameter::add(SGMatrix<CSGObject*>* param, const char* name,
1353  const char* description)
1354 {
1355  TSGDataType type(CT_SGMATRIX, ST_NONE, PT_SGOBJECT, &param->num_rows,
1356  &param->num_cols);
1357  add_type(&type, param, name, description);
1358 }
1359 
1360 void Parameter::add(SGMatrix<SGString<bool> >* param, const char* name,
1361  const char* description)
1362 {
1363  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_BOOL, &param->num_rows,
1364  &param->num_cols);
1365  add_type(&type, param, name, description);
1366 }
1367 
1368 void Parameter::add(SGMatrix<SGString<char> >* param, const char* name,
1369  const char* description)
1370 {
1371  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_CHAR, &param->num_rows,
1372  &param->num_cols);
1373  add_type(&type, param, name, description);
1374 }
1375 
1377  const char* name, const char* description)
1378 {
1379  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_INT8, &param->num_rows,
1380  &param->num_cols);
1381  add_type(&type, param, name, description);
1382 }
1383 
1385  const char* name, const char* description)
1386 {
1387  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_UINT8, &param->num_rows,
1388  &param->num_cols);
1389  add_type(&type, param, name, description);
1390 }
1391 
1393  const char* name, const char* description)
1394 {
1395  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_INT16, &param->num_rows,
1396  &param->num_cols);
1397  add_type(&type, param, name, description);
1398 }
1399 
1401  const char* name, const char* description)
1402 {
1403  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_UINT16, &param->num_rows,
1404  &param->num_cols);
1405  add_type(&type, param, name, description);
1406 }
1407 
1409  const char* name, const char* description)
1410 {
1411  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_INT32, &param->num_rows,
1412  &param->num_cols);
1413  add_type(&type, param, name, description);
1414 }
1415 
1417  const char* name, const char* description)
1418 {
1419  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_UINT32, &param->num_rows,
1420  &param->num_cols);
1421  add_type(&type, param, name, description);
1422 }
1423 
1425  const char* name, const char* description)
1426 {
1427  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_INT64, &param->num_rows,
1428  &param->num_cols);
1429  add_type(&type, param, name, description);
1430 }
1431 
1433  const char* name, const char* description)
1434 {
1435  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_UINT64, &param->num_rows,
1436  &param->num_cols);
1437  add_type(&type, param, name, description);
1438 }
1439 
1441  const char* name, const char* description)
1442 {
1443  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_FLOAT32, &param->num_rows,
1444  &param->num_cols);
1445  add_type(&type, param, name, description);
1446 }
1447 
1449  const char* name, const char* description)
1450 {
1451  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_FLOAT64, &param->num_rows,
1452  &param->num_cols);
1453  add_type(&type, param, name, description);
1454 }
1455 
1457  const char* name, const char* description)
1458 {
1459  TSGDataType type(CT_SGMATRIX, ST_STRING, PT_FLOATMAX, &param->num_rows,
1460  &param->num_cols);
1461  add_type(&type, param, name, description);
1462 }
1463 
1465  const char* name, const char* description)
1466 {
1467  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_BOOL, &param->num_rows,
1468  &param->num_cols);
1469  add_type(&type, param, name, description);
1470 }
1471 
1473  const char* name, const char* description)
1474 {
1475  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_CHAR, &param->num_rows,
1476  &param->num_cols);
1477  add_type(&type, param, name, description);
1478 }
1479 
1481  const char* name, const char* description)
1482 {
1483  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT8, &param->num_rows,
1484  &param->num_cols);
1485  add_type(&type, param, name, description);
1486 }
1487 
1489  const char* name, const char* description)
1490 {
1491  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT8, &param->num_rows,
1492  &param->num_cols);
1493  add_type(&type, param, name, description);
1494 }
1495 
1497  const char* name, const char* description)
1498 {
1499  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT16, &param->num_rows,
1500  &param->num_cols);
1501  add_type(&type, param, name, description);
1502 }
1503 
1505  const char* name, const char* description)
1506 {
1507  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT16, &param->num_rows,
1508  &param->num_cols);
1509  add_type(&type, param, name, description);
1510 }
1511 
1513  const char* name, const char* description)
1514 {
1515  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT32, &param->num_rows,
1516  &param->num_cols);
1517  add_type(&type, param, name, description);
1518 }
1519 
1521  const char* name, const char* description)
1522 {
1523  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT32, &param->num_rows,
1524  &param->num_cols);
1525  add_type(&type, param, name, description);
1526 }
1527 
1529  const char* name, const char* description)
1530 {
1531  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT64, &param->num_rows,
1532  &param->num_cols);
1533  add_type(&type, param, name, description);
1534 }
1535 
1537  const char* name, const char* description)
1538 {
1539  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT64, &param->num_rows,
1540  &param->num_cols);
1541  add_type(&type, param, name, description);
1542 }
1543 
1545  const char* name, const char* description)
1546 {
1547  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOAT32, &param->num_rows,
1548  &param->num_cols);
1549  add_type(&type, param, name, description);
1550 }
1551 
1553  const char* name, const char* description)
1554 {
1555  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOAT64, &param->num_rows,
1556  &param->num_cols);
1557  add_type(&type, param, name, description);
1558 }
1559 
1561  const char* name, const char* description)
1562 {
1563  TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOATMAX, &param->num_rows,
1564  &param->num_cols);
1565  add_type(&type, param, name, description);
1566 }
1567 /* **************************************************************** */
1568 /* End of wrappers */
1569 
1570 TParameter::TParameter(const TSGDataType* datatype, void* parameter,
1571  const char* name, const char* description)
1572  :m_datatype(*datatype)
1573 {
1574  m_parameter = parameter;
1575  m_name = strdup(name);
1576  m_description = strdup(description);
1577 }
1578 
1580 {
1582  SG_FREE(m_name);
1583 }
1584 
1585 char*
1586 TParameter::new_prefix(const char* s1, const char* s2)
1587 {
1588  char* tmp = SG_MALLOC(char, strlen(s1)+strlen(s2)+2);
1589 
1590  sprintf(tmp, "%s%s/", s1, s2);
1591 
1592  return tmp;
1593 }
1594 
1595 void
1596 TParameter::print(const char* prefix)
1597 {
1598  string_t buf;
1600 
1601  SG_SPRINT("\n%s\n%35s %24s :%s\n", prefix, m_description == NULL
1602  || *m_description == '\0' ? "(Parameter)": m_description,
1603  m_name, buf);
1604 
1605  if (m_datatype.m_ptype == PT_SGOBJECT
1606  && m_datatype.m_stype == ST_NONE
1607  && m_datatype.m_ctype == CT_SCALAR
1608  && *(CSGObject**) m_parameter != NULL) {
1609  char* p = new_prefix(prefix, m_name);
1610  (*(CSGObject**) m_parameter)->print_serializable(p);
1611  delete p;
1612  }
1613 }
1614 
1615 void
1616 TParameter::delete_cont()
1617 {
1618  /* In the case, ctype is a struct (not array of a basic type)
1619  * data does not start at m_parameter, since the latter may have
1620  * methods so move start pointer to array of struct */
1621  void* data_start=m_parameter;
1622  switch(m_datatype.m_ctype)
1623  {
1624  case CT_SGVECTOR:
1625  data_start=&(((SGVector<char>*)m_parameter)->vector);
1626  break;
1627  case CT_SGMATRIX:
1628  data_start=&(((SGMatrix<char>*)m_parameter)->matrix);
1629  break;
1630  default:
1631  break;
1632  }
1633 
1634  if (*(void**) data_start != NULL) {
1635  index_t old_length = *m_datatype.m_length_y;
1636  switch (m_datatype.m_ctype) {
1637  case CT_NDARRAY:
1639  case CT_MATRIX: case CT_SGMATRIX:
1640  old_length *= *m_datatype.m_length_x; break;
1641  case CT_SCALAR: case CT_VECTOR: case CT_SGVECTOR: break;
1642  }
1643 
1644 
1645  switch (m_datatype.m_stype) {
1646  case ST_NONE:
1647  switch (m_datatype.m_ptype) {
1648  case PT_BOOL:
1649  SG_FREE(*(bool**) data_start); break;
1650  case PT_CHAR:
1651  SG_FREE(*(char**) data_start); break;
1652  case PT_INT8:
1653  SG_FREE(*(int8_t**) data_start); break;
1654  case PT_UINT8:
1655  SG_FREE(*(uint8_t**) data_start); break;
1656  case PT_INT16:
1657  SG_FREE(*(int16_t**) data_start); break;
1658  case PT_UINT16:
1659  SG_FREE(*(uint16_t**) data_start); break;
1660  case PT_INT32:
1661  SG_FREE(*(int32_t**) data_start); break;
1662  case PT_UINT32:
1663  SG_FREE(*(uint32_t**) data_start); break;
1664  case PT_INT64:
1665  SG_FREE(*(int64_t**) data_start); break;
1666  case PT_UINT64:
1667  SG_FREE(*(uint64_t**) data_start); break;
1668  case PT_FLOAT32:
1669  SG_FREE(*(float32_t**) data_start); break;
1670  case PT_FLOAT64:
1671  SG_FREE(*(float64_t**) data_start); break;
1672  case PT_FLOATMAX:
1673  SG_FREE(*(floatmax_t**) data_start); break;
1674  case PT_SGOBJECT:
1675  CSGObject** buf =
1676  *(CSGObject***) data_start;
1677  for (index_t i=0; i<old_length; i++)
1678  if (buf[i] != NULL) SG_UNREF(buf[i]);
1679  delete buf;
1680  break;
1681  }
1682  break;
1683  case ST_STRING:
1684  for (index_t i=0; i<old_length; i++) {
1685  SGString<char>* buf = (SGString<char>*) (*(char**)
1686  data_start + i *m_datatype.sizeof_stype());
1687  if (buf->slen > 0) SG_FREE(buf->string);
1688  }
1689 
1690  switch (m_datatype.m_ptype) {
1691  case PT_BOOL:
1692  SG_FREE(*(SGString<bool>**) data_start); break;
1693  case PT_CHAR:
1694  SG_FREE(*(SGString<char>**) data_start); break;
1695  case PT_INT8:
1696  SG_FREE(*(SGString<int8_t>**) data_start); break;
1697  case PT_UINT8:
1698  SG_FREE(*(SGString<uint8_t>**) data_start); break;
1699  case PT_INT16:
1700  SG_FREE(*(SGString<int16_t>**) data_start); break;
1701  case PT_UINT16:
1702  SG_FREE(*(SGString<uint16_t>**) data_start); break;
1703  case PT_INT32:
1704  SG_FREE(*(SGString<int32_t>**) data_start); break;
1705  case PT_UINT32:
1706  SG_FREE(*(SGString<uint32_t>**) data_start); break;
1707  case PT_INT64:
1708  SG_FREE(*(SGString<int64_t>**) data_start); break;
1709  case PT_UINT64:
1710  SG_FREE(*(SGString<uint64_t>**) data_start); break;
1711  case PT_FLOAT32:
1712  SG_FREE(*(SGString<float32_t>**) data_start); break;
1713  case PT_FLOAT64:
1714  SG_FREE(*(SGString<float64_t>**) data_start); break;
1715  case PT_FLOATMAX:
1716  SG_FREE(*(SGString<floatmax_t>**) data_start); break;
1717  case PT_SGOBJECT:
1718  SG_SERROR("TParameter::delete_cont(): Implementation "
1719  "error: Could not delete "
1720  "String<SGSerializable*>");
1721  break;
1722  }
1723  break;
1724  case ST_SPARSE:
1725  for (index_t i=0; i<old_length; i++) {
1726  SGSparseVector<char>* buf = (SGSparseVector<char>*) (*(char**)
1727  data_start + i *m_datatype.sizeof_stype());
1728  if (buf->num_feat_entries > 0) SG_FREE(buf->features);
1729  }
1730 
1731  switch (m_datatype.m_ptype) {
1732  case PT_BOOL:
1733  SG_FREE(*(SGSparseVector<bool>**) data_start); break;
1734  case PT_CHAR:
1735  SG_FREE(*(SGSparseVector<char>**) data_start); break;
1736  case PT_INT8:
1737  SG_FREE(*(SGSparseVector<int8_t>**) data_start); break;
1738  case PT_UINT8:
1739  SG_FREE(*(SGSparseVector<uint8_t>**) data_start); break;
1740  case PT_INT16:
1741  SG_FREE(*(SGSparseVector<int16_t>**) data_start); break;
1742  case PT_UINT16:
1743  SG_FREE(*(SGSparseVector<uint16_t>**) data_start); break;
1744  case PT_INT32:
1745  SG_FREE(*(SGSparseVector<int32_t>**) data_start); break;
1746  case PT_UINT32:
1747  SG_FREE(*(SGSparseVector<uint32_t>**) data_start); break;
1748  case PT_INT64:
1749  SG_FREE(*(SGSparseVector<int64_t>**) data_start); break;
1750  case PT_UINT64:
1751  SG_FREE(*(SGSparseVector<uint64_t>**) data_start); break;
1752  case PT_FLOAT32:
1753  SG_FREE(*(SGSparseVector<float32_t>**) data_start); break;
1754  case PT_FLOAT64:
1755  SG_FREE(*(SGSparseVector<float64_t>**) data_start); break;
1756  case PT_FLOATMAX:
1757  SG_FREE(*(SGSparseVector<floatmax_t>**) data_start); break;
1758  case PT_SGOBJECT:
1759  SG_SERROR("TParameter::delete_cont(): Implementation "
1760  "error: Could not delete "
1761  "Sparse<SGSerializable*>");
1762  break;
1763  }
1764  break;
1765  } /* switch (m_datatype.m_stype) */
1766  } /* if (*(void**) data_start != NULL) */
1767 
1768  *(void**) data_start = NULL;
1769 }
1770 
1771 void
1772 TParameter::new_cont(index_t new_len_y, index_t new_len_x)
1773 {
1774  delete_cont();
1775 
1776  index_t new_length = new_len_y*new_len_x;
1777  if (new_length == 0) return;
1778 
1779  /* In the case, ctype is a struct (not array of a basic type)
1780  * data does not start at m_parameter, since the latter may have
1781  * methods so move start pointer to array of struct */
1782  void* data_start=m_parameter;
1783  switch(m_datatype.m_ctype)
1784  {
1785  case CT_SGVECTOR:
1786  data_start=&(((SGVector<char>*)m_parameter)->vector);
1787  break;
1788  case CT_SGMATRIX:
1789  data_start=&(((SGMatrix<char>*)m_parameter)->matrix);
1790  break;
1791  default:
1792  break;
1793  }
1794 
1795  switch (m_datatype.m_stype) {
1796  case ST_NONE:
1797  switch (m_datatype.m_ptype) {
1798  case PT_BOOL:
1799  *(bool**) data_start
1800  = SG_MALLOC(bool, new_length); break;
1801  case PT_CHAR:
1802  *(char**) data_start
1803  = SG_MALLOC(char, new_length); break;
1804  case PT_INT8:
1805  *(int8_t**) data_start
1806  = SG_MALLOC(int8_t, new_length); break;
1807  case PT_UINT8:
1808  *(uint8_t**) data_start
1809  = SG_MALLOC(uint8_t, new_length); break;
1810  case PT_INT16:
1811  *(int16_t**) data_start
1812  = SG_MALLOC(int16_t, new_length); break;
1813  case PT_UINT16:
1814  *(uint16_t**) data_start
1815  = SG_MALLOC(uint16_t, new_length); break;
1816  case PT_INT32:
1817  *(int32_t**) data_start
1818  = SG_MALLOC(int32_t, new_length); break;
1819  case PT_UINT32:
1820  *(uint32_t**) data_start
1821  = SG_MALLOC(uint32_t, new_length); break;
1822  case PT_INT64:
1823  *(int64_t**) data_start
1824  = SG_MALLOC(int64_t, new_length); break;
1825  case PT_UINT64:
1826  *(uint64_t**) data_start
1827  = SG_MALLOC(uint64_t, new_length); break;
1828  case PT_FLOAT32:
1829  *(float32_t**) data_start
1830  = SG_MALLOC(float32_t, new_length); break;
1831  case PT_FLOAT64:
1832  *(float64_t**) data_start
1833  = SG_MALLOC(float64_t, new_length); break;
1834  case PT_FLOATMAX:
1835  *(floatmax_t**) data_start
1836  = SG_MALLOC(floatmax_t, new_length); break;
1837  case PT_SGOBJECT:
1838  *(CSGObject***) data_start
1839  = SG_CALLOC(CSGObject*, new_length);
1840  break;
1841  }
1842  break;
1843  case ST_STRING:
1844  switch (m_datatype.m_ptype) {
1845  case PT_BOOL:
1846  *(SGString<bool>**) data_start
1847  = SG_MALLOC(SGString<bool>, new_length); break;
1848  case PT_CHAR:
1849  *(SGString<char>**) data_start
1850  = SG_MALLOC(SGString<char>, new_length); break;
1851  case PT_INT8:
1852  *(SGString<int8_t>**) data_start
1853  = SG_MALLOC(SGString<int8_t>, new_length); break;
1854  case PT_UINT8:
1855  *(SGString<uint8_t>**) data_start
1856  = SG_MALLOC(SGString<uint8_t>, new_length); break;
1857  case PT_INT16:
1858  *(SGString<int16_t>**) data_start
1859  = SG_MALLOC(SGString<int16_t>, new_length); break;
1860  case PT_UINT16:
1861  *(SGString<uint16_t>**) data_start
1862  = SG_MALLOC(SGString<uint16_t>, new_length); break;
1863  case PT_INT32:
1864  *(SGString<int32_t>**) data_start
1865  = SG_MALLOC(SGString<int32_t>, new_length); break;
1866  case PT_UINT32:
1867  *(SGString<uint32_t>**) data_start
1868  = SG_MALLOC(SGString<uint32_t>, new_length); break;
1869  case PT_INT64:
1870  *(SGString<int64_t>**) data_start
1871  = SG_MALLOC(SGString<int64_t>, new_length); break;
1872  case PT_UINT64:
1873  *(SGString<uint64_t>**) data_start
1874  = SG_MALLOC(SGString<uint64_t>, new_length); break;
1875  case PT_FLOAT32:
1876  *(SGString<float32_t>**) data_start
1877  = SG_MALLOC(SGString<float32_t>, new_length); break;
1878  case PT_FLOAT64:
1879  *(SGString<float64_t>**) data_start
1880  = SG_MALLOC(SGString<float64_t>, new_length); break;
1881  case PT_FLOATMAX:
1882  *(SGString<floatmax_t>**) data_start
1883  = SG_MALLOC(SGString<floatmax_t>, new_length); break;
1884  case PT_SGOBJECT:
1885  SG_SERROR("TParameter::new_cont(): Implementation "
1886  "error: Could not allocate "
1887  "String<SGSerializable*>");
1888  break;
1889  }
1890  memset(*(void**) data_start, 0, new_length
1892  break;
1893  case ST_SPARSE:
1894  switch (m_datatype.m_ptype) {
1895  case PT_BOOL:
1896  *(SGSparseVector<bool>**) data_start
1897  = SG_MALLOC(SGSparseVector<bool>, new_length); break;
1898  case PT_CHAR:
1899  *(SGSparseVector<char>**) data_start
1900  = SG_MALLOC(SGSparseVector<char>, new_length); break;
1901  case PT_INT8:
1902  *(SGSparseVector<int8_t>**) data_start
1903  = SG_MALLOC(SGSparseVector<int8_t>, new_length); break;
1904  case PT_UINT8:
1905  *(SGSparseVector<uint8_t>**) data_start
1906  = SG_MALLOC(SGSparseVector<uint8_t>, new_length); break;
1907  case PT_INT16:
1908  *(SGSparseVector<int16_t>**) data_start
1909  = SG_MALLOC(SGSparseVector<int16_t>, new_length); break;
1910  case PT_UINT16:
1911  *(SGSparseVector<uint16_t>**) data_start
1912  = SG_MALLOC(SGSparseVector<uint16_t>, new_length); break;
1913  case PT_INT32:
1914  *(SGSparseVector<int32_t>**) data_start
1915  = SG_MALLOC(SGSparseVector<int32_t>, new_length); break;
1916  case PT_UINT32:
1917  *(SGSparseVector<uint32_t>**) data_start
1918  = SG_MALLOC(SGSparseVector<uint32_t>, new_length); break;
1919  case PT_INT64:
1920  *(SGSparseVector<int64_t>**) data_start
1921  = SG_MALLOC(SGSparseVector<int64_t>, new_length); break;
1922  case PT_UINT64:
1923  *(SGSparseVector<uint64_t>**) data_start
1924  = SG_MALLOC(SGSparseVector<uint64_t>, new_length); break;
1925  case PT_FLOAT32:
1926  *(SGSparseVector<float32_t>**) data_start
1927  = SG_MALLOC(SGSparseVector<float32_t>, new_length); break;
1928  case PT_FLOAT64:
1929  *(SGSparseVector<float64_t>**) data_start
1930  = SG_MALLOC(SGSparseVector<float64_t>, new_length); break;
1931  case PT_FLOATMAX:
1932  *(SGSparseVector<floatmax_t>**) data_start
1933  = SG_MALLOC(SGSparseVector<floatmax_t>, new_length); break;
1934  case PT_SGOBJECT:
1935  SG_SERROR("TParameter::new_cont(): Implementation "
1936  "error: Could not allocate "
1937  "Sparse<SGSerializable*>");
1938  break;
1939  }
1940  memset(*(void**) data_start, 0, new_length
1942  break;
1943  } /* switch (m_datatype.m_stype) */
1944 }
1945 
1946 bool
1947 TParameter::new_sgserial(CSGObject** param,
1948  EPrimitiveType generic,
1949  const char* sgserializable_name,
1950  const char* prefix)
1951 {
1952  if (*param != NULL)
1953  SG_UNREF(*param);
1954 
1955  *param = new_sgserializable(sgserializable_name, generic);
1956 
1957  if (*param == NULL) {
1958  string_t buf = {'\0'};
1959 
1960  if (generic != PT_NOT_GENERIC) {
1961  buf[0] = '<';
1962  TSGDataType::ptype_to_string(buf+1, generic,
1963  STRING_LEN - 3);
1964  strcat(buf, ">");
1965  }
1966 
1967  SG_SWARNING("TParameter::new_sgserial(): "
1968  "Class `C%s%s' was not listed during compiling Shogun"
1969  " :( ... Can not construct it for `%s%s'!",
1970  sgserializable_name, buf, prefix, m_name);
1971 
1972  return false;
1973  }
1974 
1975  SG_REF(*param);
1976  return true;
1977 }
1978 
1979 bool
1980 TParameter::save_ptype(CSerializableFile* file, const void* param,
1981  const char* prefix)
1982 {
1983  if (m_datatype.m_ptype == PT_SGOBJECT) {
1984  const char* sgserial_name = "";
1985  EPrimitiveType generic = PT_NOT_GENERIC;
1986 
1987  if (*(CSGObject**) param != NULL) {
1988  sgserial_name = (*(CSGObject**) param)->get_name();
1989  (*(CSGObject**) param)->is_generic(&generic);
1990  }
1991 
1992  if (!file->write_sgserializable_begin(
1993  &m_datatype, m_name, prefix, sgserial_name, generic))
1994  return false;
1995  if (*sgserial_name != '\0') {
1996  char* p = new_prefix(prefix, m_name);
1997  bool result = (*(CSGObject**) param)
1998  ->save_serializable(file, p);
1999  delete p;
2000  if (!result) return false;
2001  }
2002  if (!file->write_sgserializable_end(
2003  &m_datatype, m_name, prefix, sgserial_name, generic))
2004  return false;
2005  } else
2006  if (!file->write_scalar(&m_datatype, m_name, prefix,
2007  param)) return false;
2008 
2009  return true;
2010 }
2011 
2012 bool
2013 TParameter::load_ptype(CSerializableFile* file, void* param,
2014  const char* prefix)
2015 {
2016  if (m_datatype.m_ptype == PT_SGOBJECT) {
2017  string_t sgserial_name = {'\0'};
2018  EPrimitiveType generic = PT_NOT_GENERIC;
2019 
2020  if (!file->read_sgserializable_begin(
2021  &m_datatype, m_name, prefix, sgserial_name, &generic))
2022  return false;
2023  if (*sgserial_name != '\0') {
2024  if (!new_sgserial((CSGObject**) param, generic,
2025  sgserial_name, prefix))
2026  return false;
2027 
2028  char* p = new_prefix(prefix, m_name);
2029  bool result = (*(CSGObject**) param)
2030  ->load_serializable(file, p);
2031  delete p;
2032  if (!result) return false;
2033  }
2034  if (!file->read_sgserializable_end(
2035  &m_datatype, m_name, prefix, sgserial_name, generic))
2036  return false;
2037  } else
2038  if (!file->read_scalar(&m_datatype, m_name, prefix,
2039  param)) return false;
2040 
2041  return true;
2042 }
2043 
2044 bool
2045 TParameter::save_stype(CSerializableFile* file, const void* param,
2046  const char* prefix)
2047 {
2048  SGString<char>* str_ptr = (SGString<char>*) param;
2049  SGSparseVector<char>* spr_ptr = (SGSparseVector<char>*) param;
2050  index_t len_real;
2051 
2052  switch (m_datatype.m_stype) {
2053  case ST_NONE:
2054  if (!save_ptype(file, param, prefix)) return false;
2055  break;
2056  case ST_STRING:
2057  len_real = str_ptr->slen;
2058  if (str_ptr->string == NULL && len_real != 0) {
2059  SG_SWARNING("Inconsistency between data structure and "
2060  "len during saving string `%s%s'! Continuing"
2061  " with len=0.\n",
2062  prefix, m_name);
2063  len_real = 0;
2064  }
2065  if (!file->write_string_begin(
2066  &m_datatype, m_name, prefix, len_real)) return false;
2067  for (index_t i=0; i<len_real; i++) {
2068  if (!file->write_stringentry_begin(
2069  &m_datatype, m_name, prefix, i)) return false;
2070  if (!save_ptype(file, (char*) str_ptr->string
2071  + i *m_datatype.sizeof_ptype(), prefix))
2072  return false;
2073  if (!file->write_stringentry_end(
2074  &m_datatype, m_name, prefix, i)) return false;
2075  }
2076  if (!file->write_string_end(
2077  &m_datatype, m_name, prefix, len_real)) return false;
2078  break;
2079  case ST_SPARSE:
2080  len_real = spr_ptr->num_feat_entries;
2081  if (spr_ptr->features == NULL && len_real != 0) {
2082  SG_SWARNING("Inconsistency between data structure and "
2083  "len during saving sparse `%s%s'! Continuing"
2084  " with len=0.\n",
2085  prefix, m_name);
2086  len_real = 0;
2087  }
2088  if (!file->write_sparse_begin(
2089  &m_datatype, m_name, prefix, spr_ptr->vec_index,
2090  len_real)) return false;
2091  for (index_t i=0; i<len_real; i++) {
2093  ((char*) spr_ptr->features + i *TSGDataType
2095  if (!file->write_sparseentry_begin(
2096  &m_datatype, m_name, prefix, spr_ptr->features,
2097  cur->feat_index, i)) return false;
2098  if (!save_ptype(file, (char*) cur + TSGDataType
2099  ::offset_sparseentry(m_datatype.m_ptype),
2100  prefix)) return false;
2101  if (!file->write_sparseentry_end(
2102  &m_datatype, m_name, prefix, spr_ptr->features,
2103  cur->feat_index, i)) return false;
2104  }
2105  if (!file->write_sparse_end(
2106  &m_datatype, m_name, prefix, spr_ptr->vec_index,
2107  len_real)) return false;
2108  break;
2109  }
2110 
2111  return true;
2112 }
2113 
2114 bool
2115 TParameter::load_stype(CSerializableFile* file, void* param,
2116  const char* prefix)
2117 {
2118  SGString<char>* str_ptr = (SGString<char>*) param;
2119  SGSparseVector<char>* spr_ptr = (SGSparseVector<char>*) param;
2120  index_t len_real = 0;
2121 
2122  switch (m_datatype.m_stype) {
2123  case ST_NONE:
2124  if (!load_ptype(file, param, prefix)) return false;
2125  break;
2126  case ST_STRING:
2127  if (!file->read_string_begin(
2128  &m_datatype, m_name, prefix, &len_real))
2129  return false;
2130  str_ptr->string = len_real > 0
2131  ? SG_MALLOC(char, len_real*m_datatype.sizeof_ptype()): NULL;
2132  for (index_t i=0; i<len_real; i++) {
2133  if (!file->read_stringentry_begin(
2134  &m_datatype, m_name, prefix, i)) return false;
2135  if (!load_ptype(file, (char*) str_ptr->string
2136  + i *m_datatype.sizeof_ptype(), prefix))
2137  return false;
2138  if (!file->read_stringentry_end(
2139  &m_datatype, m_name, prefix, i)) return false;
2140  }
2141  if (!file->read_string_end(
2142  &m_datatype, m_name, prefix, len_real))
2143  return false;
2144  str_ptr->slen = len_real;
2145  break;
2146  case ST_SPARSE:
2147  if (!file->read_sparse_begin(
2148  &m_datatype, m_name, prefix, &spr_ptr->vec_index,
2149  &len_real)) return false;
2150  spr_ptr->features = len_real > 0? (SGSparseVectorEntry<char>*)
2152  m_datatype.m_ptype)): NULL;
2153  for (index_t i=0; i<len_real; i++) {
2155  ((char*) spr_ptr->features + i *TSGDataType
2157  if (!file->read_sparseentry_begin(
2158  &m_datatype, m_name, prefix, spr_ptr->features,
2159  &cur->feat_index, i)) return false;
2160  if (!load_ptype(file, (char*) cur + TSGDataType
2161  ::offset_sparseentry(m_datatype.m_ptype),
2162  prefix)) return false;
2163  if (!file->read_sparseentry_end(
2164  &m_datatype, m_name, prefix, spr_ptr->features,
2165  &cur->feat_index, i)) return false;
2166  }
2167  if (!file->read_sparse_end(
2168  &m_datatype, m_name, prefix, &spr_ptr->vec_index,
2169  len_real)) return false;
2170  spr_ptr->num_feat_entries = len_real;
2171  break;
2172  }
2173 
2174  return true;
2175 }
2176 
2177 bool
2178 TParameter::save(CSerializableFile* file, const char* prefix)
2179 {
2180  const int32_t buflen=100;
2181  char* buf=SG_MALLOC(char, buflen);
2182  m_datatype.to_string(buf, buflen);
2183  SG_SDEBUG("Saving parameter '%s' of type '%s'\n", m_name, buf);
2184  SG_FREE(buf);
2185 
2186  if (!file->write_type_begin(&m_datatype, m_name, prefix))
2187  return false;
2188 
2189  switch (m_datatype.m_ctype) {
2190  case CT_NDARRAY:
2192  case CT_SCALAR:
2193  if (!save_stype(file, m_parameter, prefix)) return false;
2194  break;
2195  case CT_VECTOR: case CT_MATRIX: case CT_SGVECTOR: case CT_SGMATRIX:
2196  index_t len_real_y = 0, len_real_x = 0;
2197 
2198  len_real_y = *m_datatype.m_length_y;
2199  if (*(void**) m_parameter == NULL && len_real_y != 0) {
2200  SG_SWARNING("Inconsistency between data structure and "
2201  "len_y during saving `%s%s'! Continuing with "
2202  "len_y=0.\n",
2203  prefix, m_name);
2204  len_real_y = 0;
2205  }
2206 
2207  switch (m_datatype.m_ctype) {
2208  case CT_NDARRAY:
2210  break;
2211  case CT_VECTOR: case CT_SGVECTOR:
2212  len_real_x = 1;
2213  break;
2214  case CT_MATRIX: case CT_SGMATRIX:
2215  len_real_x = *m_datatype.m_length_x;
2216  if (*(void**) m_parameter == NULL && len_real_x != 0) {
2217  SG_SWARNING("Inconsistency between data structure and "
2218  "len_x during saving `%s%s'! Continuing "
2219  "with len_x=0.\n",
2220  prefix, m_name);
2221  len_real_x = 0;
2222  }
2223 
2224  if (len_real_x *len_real_y == 0)
2225  len_real_x = len_real_y = 0;
2226 
2227  break;
2228  case CT_SCALAR: break;
2229  }
2230 
2231  if (!file->write_cont_begin(&m_datatype, m_name, prefix,
2232  len_real_y, len_real_x))
2233  return false;
2234 
2235  /* ******************************************************** */
2236 
2237  for (index_t x=0; x<len_real_x; x++)
2238  for (index_t y=0; y<len_real_y; y++) {
2239  if (!file->write_item_begin(
2240  &m_datatype, m_name, prefix, y, x))
2241  return false;
2242 
2243  /* In the case, ctype is a struct (not array of a basic type)
2244  * data does not start at m_parameter, since the latter may have
2245  * methods so move start pointer to array of struct */
2246  void* data_start=m_parameter;
2247  switch(m_datatype.m_ctype)
2248  {
2249  case CT_SGVECTOR:
2250  data_start=&(((SGVector<char>*)m_parameter)->vector);
2251  break;
2252  case CT_SGMATRIX:
2253  data_start=&(((SGMatrix<char>*)m_parameter)->matrix);
2254  break;
2255  default:
2256  break;
2257  }
2258 
2259  if (!save_stype(
2260  file, (*(char**) data_start)
2261  + (x*len_real_y + y)*m_datatype.sizeof_stype(),
2262  prefix)) return false;
2263  if (!file->write_item_end(
2264  &m_datatype, m_name, prefix, y, x))
2265  return false;
2266  }
2267 
2268  /* ******************************************************** */
2269 
2270  if (!file->write_cont_end(&m_datatype, m_name, prefix,
2271  len_real_y, len_real_x))
2272  return false;
2273 
2274  break;
2275  }
2276 
2277  if (!file->write_type_end(&m_datatype, m_name, prefix))
2278  return false;
2279 
2280  return true;
2281 }
2282 
2283 bool
2284 TParameter::load(CSerializableFile* file, const char* prefix)
2285 {
2286  const int32_t buflen=100;
2287  char* buf=SG_MALLOC(char, buflen);
2288  m_datatype.to_string(buf, buflen);
2289  SG_SDEBUG("Loading parameter '%s' of type '%s'\n", m_name, buf);
2290  SG_FREE(buf);
2291 
2292  if (!file->read_type_begin(&m_datatype, m_name, prefix))
2293  return false;
2294 
2295  switch (m_datatype.m_ctype)
2296  {
2297  case CT_NDARRAY:
2299  case CT_SCALAR:
2300  if (!load_stype(file, m_parameter, prefix))
2301  return false;
2302  break;
2303 
2304  case CT_VECTOR: case CT_MATRIX: case CT_SGVECTOR: case CT_SGMATRIX:
2305  index_t len_read_y = 0, len_read_x = 0;
2306 
2307  if (!file->read_cont_begin(&m_datatype, m_name, prefix,
2308  &len_read_y, &len_read_x))
2309  return false;
2310 
2311  switch (m_datatype.m_ctype)
2312  {
2313  case CT_NDARRAY:
2315  case CT_VECTOR: case CT_SGVECTOR:
2316  len_read_x = 1;
2317  new_cont(len_read_y, len_read_x);
2318  break;
2319  case CT_MATRIX: case CT_SGMATRIX:
2320  new_cont(len_read_y, len_read_x);
2321  break;
2322  case CT_SCALAR:
2323  break;
2324  }
2325 
2326  for (index_t x=0; x<len_read_x; x++)
2327  {
2328  for (index_t y=0; y<len_read_y; y++)
2329  {
2330  if (!file->read_item_begin(
2331  &m_datatype, m_name, prefix, y, x))
2332  return false;
2333 
2334  /* In the case, ctype is a struct (not array of a basic type)
2335  * data does not start at m_parameter, since the latter may
2336  * have methods so move start pointer to array of struct */
2337  void* data_start=m_parameter;
2338  switch(m_datatype.m_ctype)
2339  {
2340  case CT_SGVECTOR:
2341  data_start=&(((SGVector<char>*)m_parameter)->vector);
2342  break;
2343  case CT_SGMATRIX:
2344  data_start=&(((SGMatrix<char>*)m_parameter)->matrix);
2345  break;
2346  default:
2347  break;
2348  }
2349 
2350  if (!load_stype(
2351  file, (*(char**) data_start)
2352  + (x*len_read_y + y)*m_datatype.sizeof_stype(),
2353  prefix)) return false;
2354  if (!file->read_item_end(
2355  &m_datatype, m_name, prefix, y, x))
2356  return false;
2357  }
2358  }
2359 
2360  switch (m_datatype.m_ctype)
2361  {
2362  case CT_NDARRAY:
2364  case CT_VECTOR: case CT_SGVECTOR:
2365  *m_datatype.m_length_y = len_read_y;
2366  break;
2367  case CT_MATRIX: case CT_SGMATRIX:
2368  *m_datatype.m_length_y = len_read_y;
2369  *m_datatype.m_length_x = len_read_x;
2370  break;
2371  case CT_SCALAR:
2372  break;
2373  }
2374 
2375  if (!file->read_cont_end(&m_datatype, m_name, prefix,
2376  len_read_y, len_read_x))
2377  return false;
2378 
2379  break;
2380  }
2381 
2382  if (!file->read_type_end(&m_datatype, m_name, prefix))
2383  return false;
2384 
2385  return true;
2386 }
2387 
2389 {
2390  SG_REF(sg_io);
2391 }
2392 
2394 {
2395  for (int32_t i=0; i<get_num_parameters(); i++)
2396  delete m_params.get_element(i);
2397 
2398  SG_UNREF(sg_io);
2399 }
2400 
2401 void
2402 Parameter::add_type(const TSGDataType* type, void* param,
2403  const char* name, const char* description)
2404 {
2405  if (name == NULL || *name == '\0')
2406  SG_SERROR("FATAL: Parameter::add_type(): `name' is empty!");
2407 
2408  for (int32_t i=0; i<get_num_parameters(); i++)
2409  if (strcmp(m_params.get_element(i)->m_name, name) == 0)
2410  SG_SERROR("FATAL: Parameter::add_type(): "
2411  "Double parameter `%s'!", name);
2412 
2414  new TParameter(type, param, name, description)
2415  );
2416 }
2417 
2418 void
2419 Parameter::print(const char* prefix)
2420 {
2421  for (int32_t i=0; i<get_num_parameters(); i++)
2422  m_params.get_element(i)->print(prefix);
2423 }
2424 
2425 bool
2426 Parameter::save(CSerializableFile* file, const char* prefix)
2427 {
2428  for (int32_t i=0; i<get_num_parameters(); i++)
2429  {
2430  if (!m_params.get_element(i)->save(file, prefix))
2431  return false;
2432  }
2433 
2434  return true;
2435 }
2436 
2437 bool
2438 Parameter::load(CSerializableFile* file, const char* prefix)
2439 {
2440  for (int32_t i=0; i<get_num_parameters(); i++)
2441  if (!m_params.get_element(i)->load(file, prefix))
2442  return false;
2443 
2444  return true;
2445 }
2446 
2448 {
2449  /* iterate over parameters in the given list */
2450  for (index_t i=0; i<params->get_num_parameters(); ++i)
2451  {
2452  TParameter* current=params->get_parameter(i);
2453  TSGDataType current_type=current->m_datatype;
2454 
2456 
2457  /* search for own parameter with same name and check types if found */
2458  TParameter* own=NULL;
2459  for (index_t j=0; j<m_params.get_num_elements(); ++j)
2460  {
2461  own=m_params.get_element(j);
2462  if (!strcmp(own->m_name, current->m_name))
2463  {
2464  if (own->m_datatype==current_type)
2465  {
2466  own=m_params.get_element(j);
2467  break;
2468  }
2469  else
2470  {
2471  SG_SERROR("given parameter name %s has a different type"
2472  " than existing one\n", current->m_name);
2473  }
2474  }
2475  else
2476  own=NULL;
2477  }
2478 
2479  if (!own)
2480  {
2481  SG_SERROR("parameter with name %s does not exist\n",
2482  current->m_name);
2483  }
2484 
2485  /* check if parameter contained CSGobjects (update reference counts) */
2486  if (current_type.m_ptype==PT_SGOBJECT)
2487  {
2488  /* PT_SGOBJECT only occurs for ST_NONE */
2489  if (own->m_datatype.m_stype==ST_NONE)
2490  {
2491  if (own->m_datatype.m_ctype==CT_SCALAR)
2492  {
2493  CSGObject** to_unref=(CSGObject**) own->m_parameter;
2494  CSGObject** to_ref=(CSGObject**) current->m_parameter;
2495 
2496  if ((*to_ref)!=(*to_unref))
2497  {
2498  SG_REF((*to_ref));
2499  SG_UNREF((*to_unref));
2500  }
2501 
2502  }
2503  else
2504  {
2505  /* unref all SGObjects and reference the new ones */
2506  CSGObject*** to_unref=(CSGObject***) own->m_parameter;
2507  CSGObject*** to_ref=(CSGObject***) current->m_parameter;
2508 
2509  for (index_t j=0; j<own->m_datatype.get_num_elements(); ++j)
2510  {
2511  if ((*to_ref)[j]!=(*to_unref)[j])
2512  {
2513  SG_REF(((*to_ref)[j]));
2514  SG_UNREF(((*to_unref)[j]));
2515  }
2516  }
2517  }
2518  }
2519  else
2520  SG_SERROR("primitive type PT_SGOBJECT occurred with structure "
2521  "type other than ST_NONE");
2522  }
2523 
2524  /* construct pointers to the to be copied parameter data */
2525  void* dest=NULL;
2526  void* source=NULL;
2527  if (current_type.m_ctype==CT_SCALAR)
2528  {
2529  /* for scalar values, just copy content the pointer points to */
2530  dest=own->m_parameter;
2531  source=current->m_parameter;
2532 
2533  /* in case of CSGObject, pointers are not equal if CSGObjects are
2534  * equal, so check. For other values, the pointers are equal and
2535  * the not-copying is handled below before the memcpy call */
2536  if (own->m_datatype.m_ptype==PT_SGOBJECT)
2537  {
2538  if (*((CSGObject**)dest) == *((CSGObject**)source))
2539  {
2540  dest=NULL;
2541  source=NULL;
2542  }
2543  }
2544  }
2545  else
2546  {
2547  /* for matrices and vectors, sadly m_parameter has to be
2548  * de-referenced once, because a pointer to the array address is
2549  * saved, but the array address itself has to be copied.
2550  * consequently, for dereferencing, a type distinction is needed */
2551  switch (own->m_datatype.m_ptype)
2552  {
2553  case PT_FLOAT64:
2554  dest=*((float64_t**) own->m_parameter);
2555  source=*((float64_t**) current->m_parameter);
2556  break;
2557  case PT_SGOBJECT:
2558  dest=*((CSGObject**) own->m_parameter);
2559  source=*((CSGObject**) current->m_parameter);
2560  break;
2561  default:
2563  break;
2564  }
2565  }
2566 
2567  /* copy parameter data, size in memory is equal because of same type */
2568  if (dest!=source)
2569  memcpy(dest, source, own->m_datatype.get_size());
2570  }
2571 }
2572 
2574 {
2575  for (index_t i=0; i<params->get_num_parameters(); ++i)
2576  {
2577  TParameter* current=params->get_parameter(i);
2578  add_type(&(current->m_datatype), current->m_parameter, current->m_name,
2579  current->m_description);
2580  }
2581 }
2582 
2583 bool Parameter::contains_parameter(const char* name)
2584 {
2585  for (index_t i=0; i<m_params.get_num_elements(); ++i)
2586  {
2587  if (!strcmp(name, m_params[i]->m_name))
2588  return true;
2589  }
2590 
2591  return false;
2592 }

SHOGUN Machine Learning Toolbox - Documentation