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

SHOGUN Machine Learning Toolbox - Documentation