SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parameter.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2010 Soeren Sonnenburg
8  * Written (W) 2011-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  m_delete_data=false;
1791 }
1792 
1794 {
1795 // SG_SDEBUG("entering ~TParameter for \"%s\"\n", m_name)
1796  SG_FREE(m_description);
1797  SG_FREE(m_name);
1798 
1799  /* possibly delete content, m_parameter variable */
1801  {
1802  SG_SDEBUG("deleting from scratch data\n")
1803 
1804  if (m_delete_data)
1805  {
1806  /* for non-scalar data, delete_cont does the job, rest is handled
1807  * below */
1808  SG_SDEBUG("deleting pure data\n")
1809  if (m_datatype.m_ctype!=CT_SCALAR)
1810  delete_cont();
1811 
1812  if (m_datatype.m_ctype==CT_SCALAR && m_datatype.m_ptype==PT_SGOBJECT)
1814  }
1815 
1816  /* free pointer/data */
1817  if (m_parameter)
1818  {
1819  SG_SDEBUG("freeing m_parameter pointer/data at %p\n", m_parameter)
1820  SG_FREE(m_parameter);
1821  }
1822 
1823  /* free lengths */
1824  if (m_datatype.m_length_x)
1825  SG_FREE(m_datatype.m_length_x);
1826 
1827  if (m_datatype.m_length_y)
1828  SG_FREE(m_datatype.m_length_y);
1829  }
1830 
1831 // SG_SDEBUG("leaving ~TParameter\n")
1832 }
1833 
1834 char*
1835 TParameter::new_prefix(const char* s1, const char* s2)
1836 {
1837  char* tmp = SG_MALLOC(char, strlen(s1)+strlen(s2)+2);
1838 
1839  sprintf(tmp, "%s%s/", s1, s2);
1840 
1841  return tmp;
1842 }
1843 
1844 void
1845 TParameter::print(const char* prefix)
1846 {
1847  string_t buf;
1849 
1850  SG_SPRINT("\n%s\n%35s %24s :%s\n", prefix, m_description == NULL
1851  || *m_description == '\0' ? "(Parameter)": m_description,
1852  m_name, buf);
1853 
1854  if (m_datatype.m_ptype == PT_SGOBJECT
1855  && m_datatype.m_stype == ST_NONE
1856  && m_datatype.m_ctype == CT_SCALAR
1857  && *(CSGObject**) m_parameter != NULL) {
1858  char* p = new_prefix(prefix, m_name);
1859  (*(CSGObject**) m_parameter)->print_serializable(p);
1860  delete p;
1861  }
1862 }
1863 
1864 void
1865 TParameter::delete_cont()
1866 {
1867  if (*(void**) m_parameter != NULL) {
1868  index_t old_length = m_datatype.m_length_y ? *m_datatype.m_length_y : 0;
1869  switch (m_datatype.m_ctype) {
1870  case CT_NDARRAY:
1872  break;
1873  case CT_MATRIX: case CT_SGMATRIX:
1874  old_length *= *m_datatype.m_length_x; break;
1875  case CT_SCALAR: case CT_VECTOR: case CT_SGVECTOR: break;
1876  case CT_UNDEFINED: default:
1877  SG_SERROR("Implementation error: undefined container type\n");
1878  break;
1879  }
1880 
1881  switch (m_datatype.m_stype) {
1882  case ST_NONE:
1883  switch (m_datatype.m_ptype) {
1884  case PT_BOOL:
1885  SG_FREE(*(bool**) m_parameter); break;
1886  case PT_CHAR:
1887  SG_FREE(*(char**) m_parameter); break;
1888  case PT_INT8:
1889  SG_FREE(*(int8_t**) m_parameter); break;
1890  case PT_UINT8:
1891  SG_FREE(*(uint8_t**) m_parameter); break;
1892  case PT_INT16:
1893  SG_FREE(*(int16_t**) m_parameter); break;
1894  case PT_UINT16:
1895  SG_FREE(*(uint16_t**) m_parameter); break;
1896  case PT_INT32:
1897  SG_FREE(*(int32_t**) m_parameter); break;
1898  case PT_UINT32:
1899  SG_FREE(*(uint32_t**) m_parameter); break;
1900  case PT_INT64:
1901  SG_FREE(*(int64_t**) m_parameter); break;
1902  case PT_UINT64:
1903  SG_FREE(*(uint64_t**) m_parameter); break;
1904  case PT_FLOAT32:
1905  SG_FREE(*(float32_t**) m_parameter); break;
1906  case PT_FLOAT64:
1907  SG_FREE(*(float64_t**) m_parameter); break;
1908  case PT_FLOATMAX:
1909  SG_FREE(*(floatmax_t**) m_parameter); break;
1910  case PT_COMPLEX128:
1911  SG_FREE(*(complex128_t**) m_parameter); break;
1912  case PT_SGOBJECT:
1913  {
1914  CSGObject** buf = *(CSGObject***) m_parameter;
1915 
1916  for (index_t i=0; i<old_length; i++)
1917  SG_UNREF(buf[i]);
1918 
1919  SG_FREE(buf);
1920  break;
1921  }
1922  case PT_UNDEFINED: default:
1923  SG_SERROR("Implementation error: undefined primitive type\n");
1924  break;
1925  }
1926  break;
1927  case ST_STRING:
1928  {
1929  for (index_t i=0; i<old_length; i++) {
1930  SGString<char>* buf = (SGString<char>*) (*(char**)
1932  if (buf->slen > 0) SG_FREE(buf->string);
1933  break;
1934  }
1935  }
1936 
1937  switch (m_datatype.m_ptype) {
1938  case PT_BOOL:
1939  SG_FREE(*(SGString<bool>**) m_parameter); break;
1940  case PT_CHAR:
1941  SG_FREE(*(SGString<char>**) m_parameter); break;
1942  case PT_INT8:
1943  SG_FREE(*(SGString<int8_t>**) m_parameter); break;
1944  case PT_UINT8:
1945  SG_FREE(*(SGString<uint8_t>**) m_parameter); break;
1946  case PT_INT16:
1947  SG_FREE(*(SGString<int16_t>**) m_parameter); break;
1948  case PT_UINT16:
1949  SG_FREE(*(SGString<uint16_t>**) m_parameter); break;
1950  case PT_INT32:
1951  SG_FREE(*(SGString<int32_t>**) m_parameter); break;
1952  case PT_UINT32:
1953  SG_FREE(*(SGString<uint32_t>**) m_parameter); break;
1954  case PT_INT64:
1955  SG_FREE(*(SGString<int64_t>**) m_parameter); break;
1956  case PT_UINT64:
1957  SG_FREE(*(SGString<uint64_t>**) m_parameter); break;
1958  case PT_FLOAT32:
1959  SG_FREE(*(SGString<float32_t>**) m_parameter); break;
1960  case PT_FLOAT64:
1961  SG_FREE(*(SGString<float64_t>**) m_parameter); break;
1962  case PT_FLOATMAX:
1963  SG_FREE(*(SGString<floatmax_t>**) m_parameter); break;
1964  case PT_COMPLEX128:
1965  SG_SERROR("TParameter::delete_cont(): Parameters of strings"
1966  " of complex128_t are not supported");
1967  break;
1968  case PT_SGOBJECT:
1969  SG_SERROR("TParameter::delete_cont(): Implementation "
1970  "error: Could not delete "
1971  "String<SGSerializable*>");
1972  break;
1973  case PT_UNDEFINED: default:
1974  SG_SERROR("Implementation error: undefined primitive type\n");
1975  break;
1976  }
1977  break;
1978  case ST_SPARSE:
1979  for (index_t i=0; i<old_length; i++) {
1980  SGSparseVector<char>* buf = (SGSparseVector<char>*) (*(char**)
1982  if (buf->num_feat_entries > 0) SG_FREE(buf->features);
1983  }
1984 
1985  switch (m_datatype.m_ptype) {
1986  case PT_BOOL:
1987  SG_FREE(*(SGSparseVector<bool>**) m_parameter); break;
1988  case PT_CHAR:
1989  SG_FREE(*(SGSparseVector<char>**) m_parameter); break;
1990  case PT_INT8:
1991  SG_FREE(*(SGSparseVector<int8_t>**) m_parameter); break;
1992  case PT_UINT8:
1993  SG_FREE(*(SGSparseVector<uint8_t>**) m_parameter); break;
1994  case PT_INT16:
1995  SG_FREE(*(SGSparseVector<int16_t>**) m_parameter); break;
1996  case PT_UINT16:
1997  SG_FREE(*(SGSparseVector<uint16_t>**) m_parameter); break;
1998  case PT_INT32:
1999  SG_FREE(*(SGSparseVector<int32_t>**) m_parameter); break;
2000  case PT_UINT32:
2001  SG_FREE(*(SGSparseVector<uint32_t>**) m_parameter); break;
2002  case PT_INT64:
2003  SG_FREE(*(SGSparseVector<int64_t>**) m_parameter); break;
2004  case PT_UINT64:
2005  SG_FREE(*(SGSparseVector<uint64_t>**) m_parameter); break;
2006  case PT_FLOAT32:
2007  SG_FREE(*(SGSparseVector<float32_t>**) m_parameter); break;
2008  case PT_FLOAT64:
2009  SG_FREE(*(SGSparseVector<float64_t>**) m_parameter); break;
2010  case PT_FLOATMAX:
2011  SG_FREE(*(SGSparseVector<floatmax_t>**) m_parameter); break;
2012  case PT_COMPLEX128:
2013  SG_FREE(*(SGSparseVector<complex128_t>**) m_parameter); break;
2014  case PT_SGOBJECT:
2015  SG_SERROR("TParameter::delete_cont(): Implementation "
2016  "error: Could not delete "
2017  "Sparse<SGSerializable*>");
2018  break;
2019  case PT_UNDEFINED: default:
2020  SG_SERROR("Implementation error: undefined primitive type\n");
2021  break;
2022  }
2023  break;
2024  case ST_UNDEFINED: default:
2025  SG_SERROR("Implementation error: undefined structure type\n");
2026  break;
2027  } /* switch (m_datatype.m_stype) */
2028  } /* if (*(void**) m_parameter != NULL) */
2029 
2030  *(void**) m_parameter = NULL;
2031 }
2032 
2033 void
2034 TParameter::new_cont(SGVector<index_t> dims)
2035 {
2036  char* s=SG_MALLOC(char, 200);
2037  m_datatype.to_string(s, 200);
2038  SG_SDEBUG("entering TParameter::new_cont for \"%s\" of type %s\n",
2039  s, m_name ? m_name : "(nil)");
2040  SG_FREE(s);
2041  delete_cont();
2042 
2043  index_t new_length = dims.product();
2044  if (new_length == 0) return;
2045 
2046  switch (m_datatype.m_stype) {
2047  case ST_NONE:
2048  switch (m_datatype.m_ptype) {
2049  case PT_BOOL:
2050  *(bool**) m_parameter
2051  = SG_MALLOC(bool, new_length); break;
2052  case PT_CHAR:
2053  *(char**) m_parameter
2054  = SG_MALLOC(char, new_length); break;
2055  case PT_INT8:
2056  *(int8_t**) m_parameter
2057  = SG_MALLOC(int8_t, new_length); break;
2058  case PT_UINT8:
2059  *(uint8_t**) m_parameter
2060  = SG_MALLOC(uint8_t, new_length); break;
2061  case PT_INT16:
2062  *(int16_t**) m_parameter
2063  = SG_MALLOC(int16_t, new_length); break;
2064  case PT_UINT16:
2065  *(uint16_t**) m_parameter
2066  = SG_MALLOC(uint16_t, new_length); break;
2067  case PT_INT32:
2068  *(int32_t**) m_parameter
2069  = SG_MALLOC(int32_t, new_length); break;
2070  case PT_UINT32:
2071  *(uint32_t**) m_parameter
2072  = SG_MALLOC(uint32_t, new_length); break;
2073  case PT_INT64:
2074  *(int64_t**) m_parameter
2075  = SG_MALLOC(int64_t, new_length); break;
2076  case PT_UINT64:
2077  *(uint64_t**) m_parameter
2078  = SG_MALLOC(uint64_t, new_length); break;
2079  case PT_FLOAT32:
2080  *(float32_t**) m_parameter
2081  = SG_MALLOC(float32_t, new_length); break;
2082  case PT_FLOAT64:
2083  *(float64_t**) m_parameter
2084  = SG_MALLOC(float64_t, new_length); break;
2085  case PT_FLOATMAX:
2086  *(floatmax_t**) m_parameter
2087  = SG_MALLOC(floatmax_t, new_length); break;
2088  case PT_COMPLEX128:
2090  = SG_MALLOC(complex128_t, new_length); break;
2091  case PT_SGOBJECT:
2092  *(CSGObject***) m_parameter
2093  = SG_CALLOC(CSGObject*, new_length);
2094  break;
2095  case PT_UNDEFINED: default:
2096  SG_SERROR("Implementation error: undefined primitive type\n");
2097  break;
2098  }
2099  break;
2100  case ST_STRING:
2101  switch (m_datatype.m_ptype) {
2102  case PT_BOOL:
2104  = SG_MALLOC(SGString<bool>, new_length); break;
2105  case PT_CHAR:
2107  = SG_MALLOC(SGString<char>, new_length); break;
2108  case PT_INT8:
2110  = SG_MALLOC(SGString<int8_t>, new_length); break;
2111  case PT_UINT8:
2113  = SG_MALLOC(SGString<uint8_t>, new_length); break;
2114  case PT_INT16:
2116  = SG_MALLOC(SGString<int16_t>, new_length); break;
2117  case PT_UINT16:
2119  = SG_MALLOC(SGString<uint16_t>, new_length); break;
2120  case PT_INT32:
2122  = SG_MALLOC(SGString<int32_t>, new_length); break;
2123  case PT_UINT32:
2125  = SG_MALLOC(SGString<uint32_t>, new_length); break;
2126  case PT_INT64:
2128  = SG_MALLOC(SGString<int64_t>, new_length); break;
2129  case PT_UINT64:
2131  = SG_MALLOC(SGString<uint64_t>, new_length); break;
2132  case PT_FLOAT32:
2134  = SG_MALLOC(SGString<float32_t>, new_length); break;
2135  case PT_FLOAT64:
2137  = SG_MALLOC(SGString<float64_t>, new_length); break;
2138  case PT_FLOATMAX:
2140  = SG_MALLOC(SGString<floatmax_t>, new_length); break;
2141  case PT_COMPLEX128:
2142  SG_SERROR("TParameter::new_cont(): Implementation "
2143  "error: Could not allocate "
2144  "String<complex128>");
2145  break;
2146  case PT_SGOBJECT:
2147  SG_SERROR("TParameter::new_cont(): Implementation "
2148  "error: Could not allocate "
2149  "String<SGSerializable*>");
2150  break;
2151  case PT_UNDEFINED: default:
2152  SG_SERROR("Implementation error: undefined primitive type\n");
2153  break;
2154  }
2155  memset(*(void**) m_parameter, 0, new_length
2157  break;
2158  case ST_SPARSE:
2159  switch (m_datatype.m_ptype) {
2160  case PT_BOOL:
2162  = SG_MALLOC(SGSparseVector<bool>, new_length); break;
2163  case PT_CHAR:
2165  = SG_MALLOC(SGSparseVector<char>, new_length); break;
2166  case PT_INT8:
2168  = SG_MALLOC(SGSparseVector<int8_t>, new_length); break;
2169  case PT_UINT8:
2171  = SG_MALLOC(SGSparseVector<uint8_t>, new_length); break;
2172  case PT_INT16:
2174  = SG_MALLOC(SGSparseVector<int16_t>, new_length); break;
2175  case PT_UINT16:
2177  = SG_MALLOC(SGSparseVector<uint16_t>, new_length); break;
2178  case PT_INT32:
2180  = SG_MALLOC(SGSparseVector<int32_t>, new_length);
2181  break;
2182  case PT_UINT32:
2184  = SG_MALLOC(SGSparseVector<uint32_t>, new_length); break;
2185  case PT_INT64:
2187  = SG_MALLOC(SGSparseVector<int64_t>, new_length); break;
2188  case PT_UINT64:
2190  = SG_MALLOC(SGSparseVector<uint64_t>, new_length); break;
2191  case PT_FLOAT32:
2193  = SG_MALLOC(SGSparseVector<float32_t>, new_length); break;
2194  case PT_FLOAT64:
2196  = SG_MALLOC(SGSparseVector<float64_t>, new_length); break;
2197  case PT_FLOATMAX:
2199  = SG_MALLOC(SGSparseVector<floatmax_t>, new_length); break;
2200  case PT_COMPLEX128:
2202  = SG_MALLOC(SGSparseVector<complex128_t>, new_length); break;
2203  case PT_SGOBJECT:
2204  SG_SERROR("TParameter::new_cont(): Implementation "
2205  "error: Could not allocate "
2206  "Sparse<SGSerializable*>");
2207  break;
2208  case PT_UNDEFINED: default:
2209  SG_SERROR("Implementation error: undefined primitive type\n");
2210  break;
2211  }
2212  break;
2213  case ST_UNDEFINED: default:
2214  SG_SERROR("Implementation error: undefined structure type\n");
2215  break;
2216  } /* switch (m_datatype.m_stype) */
2217 
2218  s=SG_MALLOC(char, 200);
2219  m_datatype.to_string(s, 200);
2220  SG_SDEBUG("leaving TParameter::new_cont for \"%s\" of type %s\n",
2221  s, m_name ? m_name : "(nil)");
2222  SG_FREE(s);
2223 }
2224 
2225 bool
2226 TParameter::new_sgserial(CSGObject** param,
2227  EPrimitiveType generic,
2228  const char* sgserializable_name,
2229  const char* prefix)
2230 {
2231  if (*param != NULL)
2232  SG_UNREF(*param);
2233 
2234  *param = new_sgserializable(sgserializable_name, generic);
2235 
2236  if (*param == NULL) {
2237  string_t buf = {'\0'};
2238 
2239  if (generic != PT_NOT_GENERIC) {
2240  buf[0] = '<';
2241  TSGDataType::ptype_to_string(buf+1, generic,
2242  STRING_LEN - 3);
2243  strcat(buf, ">");
2244  }
2245 
2246  SG_SWARNING("TParameter::new_sgserial(): "
2247  "Class `C%s%s' was not listed during compiling Shogun"
2248  " :( ... Can not construct it for `%s%s'!",
2249  sgserializable_name, buf, prefix, m_name);
2250 
2251  return false;
2252  }
2253 
2254  SG_REF(*param);
2255  return true;
2256 }
2257 
2258 bool
2259 TParameter::save_ptype(CSerializableFile* file, const void* param,
2260  const char* prefix)
2261 {
2262  if (m_datatype.m_ptype == PT_SGOBJECT) {
2263  const char* sgserial_name = "";
2264  EPrimitiveType generic = PT_NOT_GENERIC;
2265 
2266  if (*(CSGObject**) param != NULL) {
2267  sgserial_name = (*(CSGObject**) param)->get_name();
2268  (*(CSGObject**) param)->is_generic(&generic);
2269  }
2270 
2271  if (!file->write_sgserializable_begin(
2272  &m_datatype, m_name, prefix, sgserial_name, generic))
2273  return false;
2274  if (*sgserial_name != '\0') {
2275  char* p = new_prefix(prefix, m_name);
2276  bool result = (*(CSGObject**) param)
2277  ->save_serializable(file, p);
2278  delete p;
2279  if (!result) return false;
2280  }
2281  if (!file->write_sgserializable_end(
2282  &m_datatype, m_name, prefix, sgserial_name, generic))
2283  return false;
2284  } else
2285  if (!file->write_scalar(&m_datatype, m_name, prefix,
2286  param)) return false;
2287 
2288  return true;
2289 }
2290 
2291 bool
2292 TParameter::load_ptype(CSerializableFile* file, void* param,
2293  const char* prefix)
2294 {
2295  if (m_datatype.m_ptype == PT_SGOBJECT) {
2296  string_t sgserial_name = {'\0'};
2297  EPrimitiveType generic = PT_NOT_GENERIC;
2298 
2299  if (!file->read_sgserializable_begin(
2300  &m_datatype, m_name, prefix, sgserial_name, &generic))
2301  return false;
2302  if (*sgserial_name != '\0') {
2303  if (!new_sgserial((CSGObject**) param, generic,
2304  sgserial_name, prefix))
2305  return false;
2306 
2307  char* p = new_prefix(prefix, m_name);
2308  bool result = (*(CSGObject**) param)
2309  ->load_serializable(file, p);
2310  delete p;
2311  if (!result) return false;
2312  }
2313  if (!file->read_sgserializable_end(
2314  &m_datatype, m_name, prefix, sgserial_name, generic))
2315  return false;
2316  } else
2317  if (!file->read_scalar(&m_datatype, m_name, prefix,
2318  param)) return false;
2319 
2320  return true;
2321 }
2322 
2323 bool
2324 TParameter::save_stype(CSerializableFile* file, const void* param,
2325  const char* prefix)
2326 {
2327  SGString<char>* str_ptr = (SGString<char>*) param;
2328  SGSparseVector<char>* spr_ptr = (SGSparseVector<char>*) param;
2329  index_t len_real;
2330 
2331  switch (m_datatype.m_stype) {
2332  case ST_NONE:
2333  if (!save_ptype(file, param, prefix)) return false;
2334  break;
2335  case ST_STRING:
2336  len_real = str_ptr->slen;
2337  if (str_ptr->string == NULL && len_real != 0) {
2338  SG_SWARNING("Inconsistency between data structure and "
2339  "len during saving string `%s%s'! Continuing"
2340  " with len=0.\n",
2341  prefix, m_name);
2342  len_real = 0;
2343  }
2344  if (!file->write_string_begin(
2345  &m_datatype, m_name, prefix, len_real)) return false;
2346  for (index_t i=0; i<len_real; i++) {
2347  if (!file->write_stringentry_begin(
2348  &m_datatype, m_name, prefix, i)) return false;
2349  if (!save_ptype(file, (char*) str_ptr->string
2350  + i *m_datatype.sizeof_ptype(), prefix))
2351  return false;
2352  if (!file->write_stringentry_end(
2353  &m_datatype, m_name, prefix, i)) return false;
2354  }
2355  if (!file->write_string_end(
2356  &m_datatype, m_name, prefix, len_real)) return false;
2357  break;
2358  case ST_SPARSE:
2359  len_real = spr_ptr->num_feat_entries;
2360  if (spr_ptr->features == NULL && len_real != 0) {
2361  SG_SWARNING("Inconsistency between data structure and "
2362  "len during saving sparse `%s%s'! Continuing"
2363  " with len=0.\n",
2364  prefix, m_name);
2365  len_real = 0;
2366  }
2367  if (!file->write_sparse_begin(
2368  &m_datatype, m_name, prefix, len_real)) return false;
2369  for (index_t i=0; i<len_real; i++) {
2371  ((char*) spr_ptr->features + i *TSGDataType
2373  if (!file->write_sparseentry_begin(
2374  &m_datatype, m_name, prefix, spr_ptr->features,
2375  cur->feat_index, i)) return false;
2376  if (!save_ptype(file, (char*) cur + TSGDataType
2377  ::offset_sparseentry(m_datatype.m_ptype),
2378  prefix)) return false;
2379  if (!file->write_sparseentry_end(
2380  &m_datatype, m_name, prefix, spr_ptr->features,
2381  cur->feat_index, i)) return false;
2382  }
2383  if (!file->write_sparse_end(
2384  &m_datatype, m_name, prefix, len_real)) return false;
2385  break;
2386  case ST_UNDEFINED: default:
2387  SG_SERROR("Implementation error: undefined structure type\n");
2388  break;
2389  }
2390 
2391  return true;
2392 }
2393 
2394 bool
2395 TParameter::load_stype(CSerializableFile* file, void* param,
2396  const char* prefix)
2397 {
2398  SGString<char>* str_ptr = (SGString<char>*) param;
2399  SGSparseVector<char>* spr_ptr = (SGSparseVector<char>*) param;
2400  index_t len_real = 0;
2401 
2402  switch (m_datatype.m_stype) {
2403  case ST_NONE:
2404  if (!load_ptype(file, param, prefix)) return false;
2405  break;
2406  case ST_STRING:
2407  if (!file->read_string_begin(
2408  &m_datatype, m_name, prefix, &len_real))
2409  return false;
2410  str_ptr->string = len_real > 0
2411  ? SG_MALLOC(char, len_real*m_datatype.sizeof_ptype()): NULL;
2412  for (index_t i=0; i<len_real; i++) {
2413  if (!file->read_stringentry_begin(
2414  &m_datatype, m_name, prefix, i)) return false;
2415  if (!load_ptype(file, (char*) str_ptr->string
2416  + i *m_datatype.sizeof_ptype(), prefix))
2417  return false;
2418  if (!file->read_stringentry_end(
2419  &m_datatype, m_name, prefix, i)) return false;
2420  }
2421  if (!file->read_string_end(
2422  &m_datatype, m_name, prefix, len_real))
2423  return false;
2424  str_ptr->slen = len_real;
2425  break;
2426  case ST_SPARSE:
2427  if (!file->read_sparse_begin(
2428  &m_datatype, m_name, prefix, &len_real)) return false;
2429  spr_ptr->features = len_real > 0? (SGSparseVectorEntry<char>*)
2430  SG_MALLOC(char, len_real *TSGDataType::sizeof_sparseentry(
2431  m_datatype.m_ptype)): NULL;
2432  for (index_t i=0; i<len_real; i++) {
2434  ((char*) spr_ptr->features + i *TSGDataType
2436  if (!file->read_sparseentry_begin(
2437  &m_datatype, m_name, prefix, spr_ptr->features,
2438  &cur->feat_index, i)) return false;
2439  if (!load_ptype(file, (char*) cur + TSGDataType
2440  ::offset_sparseentry(m_datatype.m_ptype),
2441  prefix)) return false;
2442  if (!file->read_sparseentry_end(
2443  &m_datatype, m_name, prefix, spr_ptr->features,
2444  &cur->feat_index, i)) return false;
2445  }
2446 
2447  if (!file->read_sparse_end(&m_datatype, m_name, prefix, len_real))
2448  return false;
2449 
2450  spr_ptr->num_feat_entries = len_real;
2451  break;
2452  case ST_UNDEFINED: default:
2453  SG_SERROR("Implementation error: undefined structure type\n");
2454  break;
2455  }
2456 
2457  return true;
2458 }
2459 
2461  uint32_t& hash, uint32_t& carry, uint32_t& total_length)
2462 {
2463 
2464  switch (m_datatype.m_ctype)
2465  {
2466  case CT_NDARRAY:
2468  break;
2469  case CT_SCALAR:
2470  {
2471  uint8_t* data = ((uint8_t*) m_parameter);
2472  uint32_t size = m_datatype.sizeof_stype();
2473  total_length += size;
2475  &hash, &carry, data, size);
2476  break;
2477  }
2478  case CT_VECTOR: case CT_MATRIX: case CT_SGVECTOR: case CT_SGMATRIX:
2479  {
2480  index_t len_real_y = 0, len_real_x = 0;
2481 
2482  if (m_datatype.m_length_y)
2483  len_real_y = *m_datatype.m_length_y;
2484 
2485  else
2486  len_real_y = 1;
2487 
2488  if (*(void**) m_parameter == NULL && len_real_y != 0)
2489  {
2490  SG_SWARNING("Inconsistency between data structure and "
2491  "len_y during hashing `%s'! Continuing with "
2492  "len_y=0.\n",
2493  m_name);
2494  len_real_y = 0;
2495  }
2496 
2497  switch (m_datatype.m_ctype)
2498  {
2499  case CT_NDARRAY:
2501  break;
2502  case CT_VECTOR: case CT_SGVECTOR:
2503  len_real_x = 1;
2504  break;
2505  case CT_MATRIX: case CT_SGMATRIX:
2506  len_real_x = *m_datatype.m_length_x;
2507 
2508  if (*(void**) m_parameter == NULL && len_real_x != 0)
2509  {
2510  SG_SWARNING("Inconsistency between data structure and "
2511  "len_x during hashing %s'! Continuing "
2512  "with len_x=0.\n",
2513  m_name);
2514  len_real_x = 0;
2515  }
2516 
2517  if (len_real_x *len_real_y == 0)
2518  len_real_x = len_real_y = 0;
2519 
2520  break;
2521 
2522  case CT_SCALAR: break;
2523  case CT_UNDEFINED: default:
2524  SG_SERROR("Implementation error: undefined container type\n");
2525  break;
2526  }
2527  uint32_t size = (len_real_x*len_real_y)*m_datatype.sizeof_stype();
2528 
2529  total_length += size;
2530 
2531  uint8_t* data = (*(uint8_t**) m_parameter);
2532 
2534  &hash, &carry, data, size);
2535  break;
2536  }
2537  case CT_UNDEFINED: default:
2538  SG_SERROR("Implementation error: undefined container type\n");
2539  break;
2540  }
2541 }
2542 
2543 bool
2545 {
2546  return m_datatype.get_num_elements() > 0;
2547 }
2548 
2549 bool
2550 TParameter::save(CSerializableFile* file, const char* prefix)
2551 {
2552  const int32_t buflen=100;
2553  char* buf=SG_MALLOC(char, buflen);
2554  m_datatype.to_string(buf, buflen);
2555  SG_SINFO("Saving parameter '%s' of type '%s'\n", m_name, buf)
2556  SG_FREE(buf);
2557 
2558  if (!file->write_type_begin(&m_datatype, m_name, prefix))
2559  return false;
2560 
2561  switch (m_datatype.m_ctype) {
2562  case CT_NDARRAY:
2564  break;
2565  case CT_SCALAR:
2566  if (!save_stype(file, m_parameter, prefix)) return false;
2567  break;
2568  case CT_VECTOR: case CT_MATRIX: case CT_SGVECTOR: case CT_SGMATRIX:
2569  {
2570  index_t len_real_y = 0, len_real_x = 0;
2571 
2572  len_real_y = *m_datatype.m_length_y;
2573  if (*(void**) m_parameter == NULL && len_real_y != 0) {
2574  SG_SWARNING("Inconsistency between data structure and "
2575  "len_y during saving `%s%s'! Continuing with "
2576  "len_y=0.\n",
2577  prefix, m_name);
2578  len_real_y = 0;
2579  }
2580 
2581  switch (m_datatype.m_ctype) {
2582  case CT_NDARRAY:
2584  break;
2585  case CT_VECTOR: case CT_SGVECTOR:
2586  len_real_x = 1;
2587  break;
2588  case CT_MATRIX: case CT_SGMATRIX:
2589  len_real_x = *m_datatype.m_length_x;
2590  if (*(void**) m_parameter == NULL && len_real_x != 0) {
2591  SG_SWARNING("Inconsistency between data structure and "
2592  "len_x during saving `%s%s'! Continuing "
2593  "with len_x=0.\n",
2594  prefix, m_name);
2595  len_real_x = 0;
2596  }
2597 
2598  if (len_real_x *len_real_y == 0)
2599  len_real_x = len_real_y = 0;
2600 
2601  break;
2602  case CT_SCALAR: break;
2603  case CT_UNDEFINED: default:
2604  SG_SERROR("Implementation error: undefined container type\n");
2605  break;
2606  }
2607 
2608  if (!file->write_cont_begin(&m_datatype, m_name, prefix,
2609  len_real_y, len_real_x))
2610  return false;
2611 
2612  /* ******************************************************** */
2613 
2614  for (index_t x=0; x<len_real_x; x++)
2615  for (index_t y=0; y<len_real_y; y++) {
2616  if (!file->write_item_begin(
2617  &m_datatype, m_name, prefix, y, x))
2618  return false;
2619 
2620  if (!save_stype(
2621  file, (*(char**) m_parameter)
2622  + (x*len_real_y + y)*m_datatype.sizeof_stype(),
2623  prefix)) return false;
2624  if (!file->write_item_end(
2625  &m_datatype, m_name, prefix, y, x))
2626  return false;
2627  }
2628 
2629  /* ******************************************************** */
2630 
2631  if (!file->write_cont_end(&m_datatype, m_name, prefix,
2632  len_real_y, len_real_x))
2633  return false;
2634 
2635  break;
2636  }
2637  case CT_UNDEFINED: default:
2638  SG_SERROR("Implementation error: undefined container type\n");
2639  break;
2640  }
2641 
2642  if (!file->write_type_end(&m_datatype, m_name, prefix))
2643  return false;
2644 
2645  return true;
2646 }
2647 
2648 bool
2649 TParameter::load(CSerializableFile* file, const char* prefix)
2650 {
2651  REQUIRE(file != NULL, "Serializable file object should be != NULL\n");
2652 
2653  const int32_t buflen=100;
2654  char* buf=SG_MALLOC(char, buflen);
2655  m_datatype.to_string(buf, buflen);
2656  SG_SDEBUG("Loading parameter '%s' of type '%s'\n", m_name, buf)
2657  SG_FREE(buf);
2658 
2659  if (!file->read_type_begin(&m_datatype, m_name, prefix))
2660  return false;
2661 
2662  switch (m_datatype.m_ctype)
2663  {
2664  case CT_NDARRAY:
2666  break;
2667  case CT_SCALAR:
2668  if (!load_stype(file, m_parameter, prefix))
2669  return false;
2670  break;
2671 
2672  case CT_VECTOR: case CT_MATRIX: case CT_SGVECTOR: case CT_SGMATRIX:
2673  {
2674  SGVector<index_t> dims(2);
2675  dims.zero();
2676 
2677  if (!file->read_cont_begin(&m_datatype, m_name, prefix,
2678  &dims.vector[1], &dims.vector[0]))
2679  return false;
2680 
2681  switch (m_datatype.m_ctype)
2682  {
2683  case CT_NDARRAY:
2685  break;
2686  case CT_VECTOR: case CT_SGVECTOR:
2687  dims[0]=1;
2688  new_cont(dims);
2689  break;
2690  case CT_MATRIX: case CT_SGMATRIX:
2691  new_cont(dims);
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  for (index_t x=0; x<dims[0]; x++)
2701  {
2702  for (index_t y=0; y<dims[1]; y++)
2703  {
2704  if (!file->read_item_begin(
2705  &m_datatype, m_name, prefix, y, x))
2706  return false;
2707 
2708  if (!load_stype(
2709  file, (*(char**) m_parameter)
2710  + (x*dims[1] + y)*m_datatype.sizeof_stype(),
2711  prefix)) return false;
2712  if (!file->read_item_end(
2713  &m_datatype, m_name, prefix, y, x))
2714  return false;
2715  }
2716  }
2717 
2718  switch (m_datatype.m_ctype)
2719  {
2720  case CT_NDARRAY:
2722  break;
2723  case CT_VECTOR: case CT_SGVECTOR:
2724  *m_datatype.m_length_y = dims[1];
2725  break;
2726  case CT_MATRIX: case CT_SGMATRIX:
2727  *m_datatype.m_length_y = dims[1];
2728  *m_datatype.m_length_x = dims[0];
2729  break;
2730  case CT_SCALAR:
2731  break;
2732  case CT_UNDEFINED: default:
2733  SG_SERROR("Implementation error: undefined container type\n");
2734  break;
2735  }
2736 
2737  if (!file->read_cont_end(&m_datatype, m_name, prefix,
2738  dims[1], dims[0]))
2739  return false;
2740 
2741  break;
2742  }
2743  case CT_UNDEFINED: default:
2744  SG_SERROR("Implementation error: undefined container type\n");
2745  break;
2746  }
2747 
2748  if (!file->read_type_end(&m_datatype, m_name, prefix))
2749  return false;
2750 
2751  return true;
2752 }
2753 
2754 /*
2755  Initializing m_params(1) with small preallocation-size, because Parameter
2756  will be constructed several times for EACH SGObject instance.
2757  */
2758 Parameter::Parameter() : m_params(1)
2759 {
2760  SG_REF(sg_io);
2761 }
2762 
2764 {
2765  for (int32_t i=0; i<get_num_parameters(); i++)
2766  delete m_params.get_element(i);
2767 
2768  SG_UNREF(sg_io);
2769 }
2770 
2771 void
2772 Parameter::add_type(const TSGDataType* type, void* param,
2773  const char* name, const char* description)
2774 {
2775  if (name == NULL || *name == '\0')
2776  SG_SERROR("FATAL: Parameter::add_type(): `name' is empty!\n")
2777 
2778  for (size_t i=0; i<strlen(name); ++i)
2779  {
2780  if (!std::isalnum(name[i]) && name[i]!='_' && name[i]!='.')
2781  {
2782  SG_SERROR("Character %d of parameter with name \"%s\" is illegal "
2783  "(only alnum or underscore is allowed)\n",
2784  i, name);
2785  }
2786  }
2787 
2788  for (int32_t i=0; i<get_num_parameters(); i++)
2789  if (strcmp(m_params.get_element(i)->m_name, name) == 0)
2790  SG_SERROR("FATAL: Parameter::add_type(): "
2791  "Double parameter `%s'!\n", name);
2792 
2794  new TParameter(type, param, name, description)
2795  );
2796 }
2797 
2798 void
2799 Parameter::print(const char* prefix)
2800 {
2801  for (int32_t i=0; i<get_num_parameters(); i++)
2802  m_params.get_element(i)->print(prefix);
2803 }
2804 
2805 bool
2806 Parameter::save(CSerializableFile* file, const char* prefix)
2807 {
2808  for (int32_t i=0; i<get_num_parameters(); i++)
2809  {
2810  if (!m_params.get_element(i)->save(file, prefix))
2811  return false;
2812  }
2813 
2814  return true;
2815 }
2816 
2817 //bool
2818 //Parameter::load(CSerializableFile* file, const char* prefix)
2819 //{
2820 // for (int32_t i=0; i<get_num_parameters(); i++)
2821 // if (!m_params.get_element(i)->load(file, prefix))
2822 // return false;
2823 //
2824 // return true;
2825 //}
2826 
2828 {
2829  /* iterate over parameters in the given list */
2830  for (index_t i=0; i<params->get_num_parameters(); ++i)
2831  {
2832  TParameter* current=params->get_parameter(i);
2833  TSGDataType current_type=current->m_datatype;
2834 
2836 
2837  /* search for own parameter with same name and check types if found */
2838  TParameter* own=NULL;
2839  for (index_t j=0; j<m_params.get_num_elements(); ++j)
2840  {
2841  own=m_params.get_element(j);
2842  if (!strcmp(own->m_name, current->m_name))
2843  {
2844  if (own->m_datatype==current_type)
2845  {
2846  own=m_params.get_element(j);
2847  break;
2848  }
2849  else
2850  {
2851  index_t l=200;
2852  char* given_type=SG_MALLOC(char, l);
2853  char* own_type=SG_MALLOC(char, l);
2854  current->m_datatype.to_string(given_type, l);
2855  own->m_datatype.to_string(own_type, l);
2856  SG_SERROR("given parameter \"%s\" has a different type (%s)"
2857  " than existing one (%s)\n", current->m_name,
2858  given_type, own_type);
2859  SG_FREE(given_type);
2860  SG_FREE(own_type);
2861  }
2862  }
2863  else
2864  own=NULL;
2865  }
2866 
2867  if (!own)
2868  {
2869  SG_SERROR("parameter with name %s does not exist\n",
2870  current->m_name);
2871  }
2872 
2873  /* check if parameter contained CSGobjects (update reference counts) */
2874  if (current_type.m_ptype==PT_SGOBJECT)
2875  {
2876  /* PT_SGOBJECT only occurs for ST_NONE */
2877  if (own->m_datatype.m_stype==ST_NONE)
2878  {
2879  if (own->m_datatype.m_ctype==CT_SCALAR)
2880  {
2881  CSGObject** to_unref=(CSGObject**) own->m_parameter;
2882  CSGObject** to_ref=(CSGObject**) current->m_parameter;
2883 
2884  if ((*to_ref)!=(*to_unref))
2885  {
2886  SG_REF((*to_ref));
2887  SG_UNREF((*to_unref));
2888  }
2889 
2890  }
2891  else
2892  {
2893  /* unref all SGObjects and reference the new ones */
2894  CSGObject*** to_unref=(CSGObject***) own->m_parameter;
2895  CSGObject*** to_ref=(CSGObject***) current->m_parameter;
2896 
2897  for (index_t j=0; j<own->m_datatype.get_num_elements(); ++j)
2898  {
2899  if ((*to_ref)[j]!=(*to_unref)[j])
2900  {
2901  SG_REF(((*to_ref)[j]));
2902  SG_UNREF(((*to_unref)[j]));
2903  }
2904  }
2905  }
2906  }
2907  else
2908  SG_SERROR("primitive type PT_SGOBJECT occurred with structure "
2909  "type other than ST_NONE");
2910  }
2911 
2912  /* construct pointers to the to be copied parameter data */
2913  void* dest=NULL;
2914  void* source=NULL;
2915  if (current_type.m_ctype==CT_SCALAR)
2916  {
2917  /* for scalar values, just copy content the pointer points to */
2918  dest=own->m_parameter;
2919  source=current->m_parameter;
2920 
2921  /* in case of CSGObject, pointers are not equal if CSGObjects are
2922  * equal, so check. For other values, the pointers are equal and
2923  * the not-copying is handled below before the memcpy call */
2924  if (own->m_datatype.m_ptype==PT_SGOBJECT)
2925  {
2926  if (*((CSGObject**)dest) == *((CSGObject**)source))
2927  {
2928  dest=NULL;
2929  source=NULL;
2930  }
2931  }
2932  }
2933  else
2934  {
2935  /* for matrices and vectors, sadly m_parameter has to be
2936  * de-referenced once, because a pointer to the array address is
2937  * saved, but the array address itself has to be copied.
2938  * consequently, for dereferencing, a type distinction is needed */
2939  switch (own->m_datatype.m_ptype)
2940  {
2941  case PT_FLOAT64:
2942  dest=*((float64_t**) own->m_parameter);
2943  source=*((float64_t**) current->m_parameter);
2944  break;
2945  case PT_SGOBJECT:
2946  dest=*((CSGObject**) own->m_parameter);
2947  source=*((CSGObject**) current->m_parameter);
2948  break;
2949  default:
2951  break;
2952  }
2953  }
2954 
2955  /* copy parameter data, size in memory is equal because of same type */
2956  if (dest!=source)
2957  memcpy(dest, source, own->m_datatype.get_size());
2958  }
2959 }
2960 
2962 {
2963  for (index_t i=0; i<params->get_num_parameters(); ++i)
2964  {
2965  TParameter* current=params->get_parameter(i);
2966  add_type(&(current->m_datatype), current->m_parameter, current->m_name,
2967  current->m_description);
2968  }
2969 }
2970 
2971 bool Parameter::contains_parameter(const char* name)
2972 {
2973  for (index_t i=0; i<m_params.get_num_elements(); ++i)
2974  {
2975  if (!strcmp(name, m_params[i]->m_name))
2976  return true;
2977  }
2978 
2979  return false;
2980 }
2981 
2982 bool TParameter::operator==(const TParameter& other) const
2983 {
2984  bool result=true;
2985  result&=!strcmp(m_name, other.m_name);
2986  return result;
2987 }
2988 
2989 bool TParameter::operator<(const TParameter& other) const
2990 {
2991  return strcmp(m_name, other.m_name)<0;
2992 }
2993 
2994 bool TParameter::operator>(const TParameter& other) const
2995 {
2996  return strcmp(m_name, other.m_name)>0;
2997 }
2998 
3000  bool new_cont_call)
3001 {
3002  SG_SDEBUG("entering TParameter::allocate_data_from_scratch of "
3003  "\"%s\"\n", m_name);
3004 
3005  /* set flag to delete all this stuff later on */
3007 
3008  /* length has to be allocated for matrices/vectors */
3009  switch (m_datatype.m_ctype)
3010  {
3011  case CT_VECTOR: case CT_SGVECTOR:
3012  m_datatype.m_length_y=SG_MALLOC(index_t, 1);
3013  *m_datatype.m_length_y=dims[1];
3014  break;
3015  case CT_MATRIX: case CT_SGMATRIX:
3016  m_datatype.m_length_x=SG_MALLOC(index_t, 1);
3017  m_datatype.m_length_y=SG_MALLOC(index_t, 1);
3018  *m_datatype.m_length_y=dims[1];
3019  *m_datatype.m_length_x=dims[0];
3020  break;
3021  case CT_SCALAR:
3022  m_datatype.m_length_x=NULL;
3023  m_datatype.m_length_y=NULL;
3024  break;
3025  case CT_NDARRAY:
3027  break;
3028  case CT_UNDEFINED: default:
3029  SG_SERROR("Implementation error: undefined container type\n");
3030  break;
3031  }
3032 
3033  /* check if there is no data loss */
3034  if (m_parameter)
3035  SG_SERROR("TParameter::allocate_data_from_scratch must not be called "
3036  "when the underlying TParameter instance already has data.\n");
3037 
3038  /* scalars are treated differently than vectors/matrices. memory has to
3039  * be allocated for the data itself */
3040  if (m_datatype.m_ctype==CT_SCALAR)
3041  {
3042  /* sgobjects are treated differently than the rest */
3043  if (m_datatype.m_ptype!=PT_SGOBJECT)
3044  {
3045  /* for non-sgobject allocate memory because normally they are on
3046  * stack and excluded in the TParameter data allocation.
3047  * Will be deleted by the TParameter destructor */
3048  m_parameter=SG_MALLOC(char, m_datatype.get_size());
3049  }
3050  else
3051  {
3052  /* for sgobjects, allocate memory for pointer and set to NULL
3053  * Will be deleted by the TParameter destructor */
3054  m_parameter=SG_MALLOC(CSGObject**, 1);
3055  *((CSGObject**)m_parameter)=NULL;
3056  }
3057  }
3058  else
3059  {
3060  /* allocate pointer for data pointer */
3061  void** data_p=SG_MALLOC(void*, 1);
3062  *data_p=NULL;
3063 
3064  /* allocate dummy data at the point the above pointer points to
3065  * will be freed by the delete_cont() method of TParameter.
3066  * This is needed because new_cont/delete_cont cannot handle
3067  * non-existing data. Set to NULL to avoid problems */
3068  if (new_cont_call)
3069  {
3070  *data_p=SG_MALLOC(void**, 1);
3071  **(void***)data_p=NULL;
3072  }
3073 
3074  m_parameter=data_p;
3075 
3076  /* perform one data allocation. This may be repeated and therefore
3077  * redundant if load() is called afterwards, however, if one wants
3078  * to write directly to the array data after this call, it is
3079  * necessary */
3080  if (new_cont_call)
3081  new_cont(dims);
3082  }
3083 
3084  SG_SDEBUG("leaving TParameter::allocate_data_from_scratch of "
3085  "\"%s\"\n", m_name);
3086 }
3087 
3089 {
3090  SG_SDEBUG("entering TParameter::copy_data for %s\n", m_name)
3091 
3092  /* assert that type is equal */
3096 
3097  /* first delete old data if non-scalar */
3098  if (m_datatype.m_ctype!=CT_SCALAR)
3099  delete_cont();
3100 
3101  /* then copy data in case of numeric scalars, or pointer to data else */
3102  if (m_datatype.m_ctype==CT_SCALAR && m_datatype.m_ptype!=PT_SGOBJECT)
3103  {
3104  /* just copy value behind pointer */
3105  SG_SDEBUG("Copying scalar data of size %d from %p to %p\n",
3107  memcpy(m_parameter, source->m_parameter,
3108  m_datatype.get_size());
3109  }
3110  else
3111  {
3112  /* if this is a sgobject, the old one has to be unrefed */
3113  if (m_datatype.m_ptype==PT_SGOBJECT)
3114  {
3115  if (m_datatype.m_ctype==CT_SCALAR)
3116  {
3118  }
3119  else
3120  {
3121  int32_t length=1;
3122  length*=m_datatype.m_length_x ? *m_datatype.m_length_x : 1;
3123  length*=m_datatype.m_length_y ? *m_datatype.m_length_y : 1;
3124 
3125  for (index_t j=0; j<length; ++j)
3126  {
3127  SG_UNREF(((CSGObject**)(m_parameter))[j]);
3128  }
3129  }
3130  }
3131 
3132  /* in this case, data is a pointer pointing to the actual
3133  * data, so copy pointer if non-NULL*/
3134  SG_SDEBUG("Copying non-scalar pointer %p\n", *((void**)source->m_parameter))
3135  *((void**)m_parameter)=*((void**)source->m_parameter);
3136  }
3137 
3138  /* copy lengths */
3139  if (source->m_datatype.m_length_x)
3141 
3142  if (source->m_datatype.m_length_y)
3144 
3145  SG_SDEBUG("leaving TParameter::copy_data for %s\n", m_name)
3146 }
3147 
3148 bool TParameter::equals(TParameter* other, float64_t accuracy, bool tolerant)
3149 {
3150  SG_SDEBUG("entering TParameter::equals()\n");
3151 
3152  if (!other)
3153  {
3154  SG_SDEBUG("leaving TParameter::equals(): other parameter is NULL\n");
3155  return false;
3156  }
3157 
3158  if (strcmp(m_name, other->m_name))
3159  {
3160  SG_SDEBUG("leaving TParameter::equals(): name \"%s\" is different from"
3161  " other parameter's name \"%s\"\n", m_name, other->m_name);
3162  return false;
3163  }
3164 
3165  SG_SDEBUG("Comparing datatypes\n");
3166  if (!(m_datatype.equals(other->m_datatype)))
3167  {
3168  SG_SDEBUG("leaving TParameter::equals(): type of \"%s\" is different "
3169  "from other parameter's \"%s\" type\n", m_name, other->m_name);
3170  return false;
3171  }
3172 
3173  /* avoid comparing NULL */
3174  if (!m_parameter && !other->m_parameter)
3175  {
3176  SG_SDEBUG("leaving TParameter::equals(): both parameters are NULL\n");
3177  return true;
3178  }
3179 
3180  if ((!m_parameter && other->m_parameter) || (m_parameter && !other->m_parameter))
3181  {
3182  SG_SDEBUG("leaving TParameter::equals(): param1 is at %p while "
3183  "param2 is at %p\n", m_parameter, other->m_parameter);
3184  return false;
3185  }
3186 
3187  SG_SDEBUG("Comparing ctype\n");
3188  switch (m_datatype.m_ctype)
3189  {
3190  case CT_SCALAR:
3191  {
3192  SG_SDEBUG("CT_SCALAR\n");
3195  other->m_parameter,
3196  accuracy, tolerant))
3197  {
3198  SG_SDEBUG("leaving TParameter::equals(): scalar data differs\n");
3199  return false;
3200  }
3201  break;
3202  }
3203  case CT_VECTOR: case CT_SGVECTOR:
3204  {
3205  SG_SDEBUG("CT_VECTOR or CT_SGVECTOR\n");
3206 
3207  /* x is number of processed bytes */
3208  index_t x=0;
3209  SG_SDEBUG("length_y: %d\n", *m_datatype.m_length_y)
3210  for (index_t i=0; i<*m_datatype.m_length_y; ++i)
3211  {
3212  SG_SDEBUG("comparing element %d which is %d bytes from start\n",
3213  i, x);
3214 
3215  void* pointer_a=&((*(char**)m_parameter)[x]);
3216  void* pointer_b=&((*(char**)other->m_parameter)[x]);
3217 
3219  m_datatype.m_ptype, pointer_a, pointer_b,
3220  accuracy, tolerant))
3221  {
3222  SG_SDEBUG("leaving TParameter::equals(): vector element "
3223  "differs\n");
3224  return false;
3225  }
3226 
3227  x=x+(m_datatype.sizeof_stype());
3228  }
3229 
3230  break;
3231  }
3232  case CT_MATRIX: case CT_SGMATRIX:
3233  {
3234  SG_SDEBUG("CT_MATRIX or CT_SGMATRIX\n");
3235 
3236  /* x is number of processed bytes */
3237  index_t x=0;
3238  SG_SDEBUG("length_y: %d\n", *m_datatype.m_length_y)
3239  SG_SDEBUG("length_x: %d\n", *m_datatype.m_length_x)
3240  int64_t length=0;
3241 
3242  /* For ST_SPARSE, we just need to loop over the rows and compare_stype
3243  * does the comparison for one whole row vector at once. For ST_NONE,
3244  * however, we need to loop over all elements.
3245  */
3246  if (m_datatype.m_stype==ST_SPARSE)
3247  length=(*m_datatype.m_length_y);
3248  else
3249  length=(*m_datatype.m_length_y) * (*m_datatype.m_length_x);
3250 
3251  for (index_t i=0; i<length; ++i)
3252  {
3253  SG_SDEBUG("comparing element %d which is %d bytes from start\n",
3254  i, x);
3255 
3256  void* pointer_a=&((*(char**)m_parameter)[x]);
3257  void* pointer_b=&((*(char**)other->m_parameter)[x]);
3258 
3260  m_datatype.m_ptype, pointer_a, pointer_b,
3261  accuracy, tolerant))
3262  {
3263  SG_SDEBUG("leaving TParameter::equals(): vector element "
3264  "differs\n");
3265  return false;
3266  }
3267 
3268  /* For ST_SPARSE, the iteration is on the pointer of SGSparseVectors */
3269  if (m_datatype.m_stype==ST_SPARSE)
3270  x=x+(m_datatype.sizeof_stype());
3271  else
3272  x=x+(m_datatype.sizeof_stype());
3273  }
3274 
3275  break;
3276  }
3277  case CT_NDARRAY:
3278  {
3279  SG_SDEBUG("CT_NDARRAY\n");
3280  SG_SERROR("TParameter::equals(): Not yet implemented for "
3281  "CT_NDARRAY!\n");
3282  break;
3283  }
3284  case CT_UNDEFINED: default:
3285  SG_SERROR("Implementation error: undefined container type\n");
3286  break;
3287  }
3288 
3289  SG_SDEBUG("leaving TParameter::equals(): Parameters are equal\n");
3290  return true;
3291 }
3292 
3293 bool TParameter::compare_ptype(EPrimitiveType ptype, void* data1, void* data2,
3294  float64_t accuracy, bool tolerant)
3295 {
3296  SG_SDEBUG("entering TParameter::compare_ptype()\n");
3297 
3298  if ((data1 && !data2) || (!data1 && data2))
3299  {
3300  SG_SINFO("leaving TParameter::compare_ptype(): data1 is at %p while "
3301  "data2 is at %p\n", data1, data2);
3302  return false;
3303  }
3304 
3306  if (!data1 && !data2)
3307  {
3308  SG_SDEBUG("leaving TParameter::compare_ptype(): both data are NULL\n");
3309  return true;
3310  }
3311 
3312  switch (ptype)
3313  {
3314  case PT_BOOL:
3315  {
3316  bool casted1=*((bool*)data1);
3317  bool casted2=*((bool*)data2);
3318 
3319  if (CMath::abs(casted1-casted2)>accuracy)
3320  {
3321  SG_SINFO("leaving TParameter::compare_ptype(): PT_BOOL: "
3322  "data1=%d, data2=%d\n", casted1, casted2);
3323  return false;
3324  }
3325  break;
3326  }
3327  case PT_CHAR:
3328  {
3329  char casted1=*((char*)data1);
3330  char casted2=*((char*)data2);
3331 
3332  if (CMath::abs(casted1-casted2)>accuracy)
3333  {
3334  SG_SINFO("leaving TParameter::compare_ptype(): PT_CHAR: "
3335  "data1=%c, data2=%c\n", casted1, casted2);
3336  return false;
3337  }
3338  break;
3339  }
3340  case PT_INT8:
3341  {
3342  int8_t casted1=*((int8_t*)data1);
3343  int8_t casted2=*((int8_t*)data2);
3344 
3345  if (CMath::abs(casted1-casted2)>accuracy)
3346  {
3347  SG_SINFO("leaving TParameter::compare_ptype(): PT_INT8: "
3348  "data1=%d, data2=%d\n", casted1, casted2);
3349  return false;
3350  }
3351  break;
3352  }
3353  case PT_UINT8:
3354  {
3355  uint8_t casted1=*((uint8_t*)data1);
3356  uint8_t casted2=*((uint8_t*)data2);
3357 
3358  if (CMath::abs(casted1-casted2)>accuracy)
3359  {
3360  SG_SINFO("leaving TParameter::compare_ptype(): PT_UINT8: "
3361  "data1=%d, data2=%d\n", casted1, casted2);
3362  return false;
3363  }
3364  break;
3365  }
3366  case PT_INT16:
3367  {
3368  int16_t casted1=*((int16_t*)data1);
3369  int16_t casted2=*((int16_t*)data2);
3370 
3371  if (CMath::abs(casted1-casted2)>accuracy)
3372  {
3373  SG_SINFO("leaving TParameter::compare_ptype(): PT_INT16: "
3374  "data1=%d, data2=%d\n", casted1, casted2);
3375  return false;
3376  }
3377  break;
3378  }
3379  case PT_UINT16:
3380  {
3381  uint16_t casted1=*((uint16_t*)data1);
3382  uint16_t casted2=*((uint16_t*)data2);
3383 
3384  if (CMath::abs(casted1-casted2)>accuracy)
3385  {
3386  SG_SINFO("leaving TParameter::compare_ptype(): PT_UINT16: "
3387  "data1=%d, data2=%d\n", casted1, casted2);
3388  return false;
3389  }
3390  break;
3391  }
3392  case PT_INT32:
3393  {
3394  int32_t casted1=*((int32_t*)data1);
3395  int32_t casted2=*((int32_t*)data2);
3396 
3397  if (CMath::abs(casted1-casted2)>accuracy)
3398  {
3399  SG_SINFO("leaving TParameter::compare_ptype(): PT_INT32: "
3400  "data1=%d, data2=%d\n", casted1, casted2);
3401  return false;
3402  }
3403  break;
3404  }
3405  case PT_UINT32:
3406  {
3407  uint32_t casted1=*((uint32_t*)data1);
3408  uint32_t casted2=*((uint32_t*)data2);
3409 
3410  if (CMath::abs(casted1-casted2)>accuracy)
3411  {
3412  SG_SINFO("leaving TParameter::compare_ptype(): PT_UINT32: "
3413  "data1=%d, data2=%d\n", casted1, casted2);
3414  return false;
3415  }
3416  break;
3417  }
3418  case PT_INT64:
3419  {
3420  int64_t casted1=*((int64_t*)data1);
3421  int64_t casted2=*((int64_t*)data2);
3422 
3423  if (CMath::abs(casted1-casted2)>accuracy)
3424  {
3425  SG_SINFO("leaving TParameter::compare_ptype(): PT_INT64: "
3426  "data1=%d, data2=%d\n", casted1, casted2);
3427  return false;
3428  }
3429  break;
3430  }
3431  case PT_UINT64:
3432  {
3433  uint64_t casted1=*((uint64_t*)data1);
3434  uint64_t casted2=*((uint64_t*)data2);
3435 
3436  if (CMath::abs(casted1-casted2)>accuracy)
3437  {
3438  SG_SINFO("leaving TParameter::compare_ptype(): PT_UINT64: "
3439  "data1=%d, data2=%d\n", casted1, casted2);
3440  return false;
3441  }
3442  break;
3443  }
3444  case PT_FLOAT32:
3445  {
3446  float32_t casted1=*((float32_t*)data1);
3447  float32_t casted2=*((float32_t*)data2);
3448 
3449  SG_SINFO("leaving TParameter::compare_ptype(): PT_FLOAT32: "
3450  "data1=%f, data2=%f\n", casted1, casted2);
3451 
3452  return CMath::fequals<float32_t>(casted1, casted2, accuracy, tolerant);
3453  break;
3454  }
3455  case PT_FLOAT64:
3456  {
3457  float64_t casted1=*((float64_t*)data1);
3458  float64_t casted2=*((float64_t*)data2);
3459 
3460  SG_SINFO("leaving TParameter::compare_ptype(): PT_FLOAT64: "
3461  "data1=%f, data2=%f\n", casted1, casted2);
3462 
3463  return CMath::fequals<float64_t>(casted1, casted2, accuracy, tolerant);
3464  break;
3465  }
3466  case PT_FLOATMAX:
3467  {
3468  floatmax_t casted1=*((floatmax_t*)data1);
3469  floatmax_t casted2=*((floatmax_t*)data2);
3470 
3471  SG_SINFO("leaving TParameter::compare_ptype(): PT_FLOATMAX: "
3472  "data1=%f, data2=%f\n", casted1, casted2);
3473 
3474  return CMath::fequals<floatmax_t>(casted1, casted2, accuracy, tolerant);
3475  break;
3476  }
3477  case PT_COMPLEX128:
3478  {
3479  float64_t casted1_real=((complex128_t*)data1)->real();
3480  float64_t casted1_imag=((complex128_t*)data1)->imag();
3481  float64_t casted2_real=((complex128_t*)data2)->real();
3482  float64_t casted2_imag=((complex128_t*)data2)->imag();
3483  if (CMath::abs(casted1_real-casted2_real)>accuracy ||
3484  CMath::abs(casted1_imag-casted2_imag)>accuracy)
3485  {
3486  SG_SINFO("leaving TParameter::compare_ptype(): PT_COMPLEX128: "
3487  "data1=%f+i%f, data2=%f+i%f\n",
3488  casted1_real, casted1_imag,
3489  casted2_real, casted2_imag);
3490  return false;
3491  }
3492  break;
3493  }
3494  case PT_SGOBJECT:
3495  {
3496  CSGObject* casted1=*((CSGObject**)data1);
3497  CSGObject* casted2=*((CSGObject**)data2);
3498 
3499  /* important not to call methods on NULL */
3500  if (!casted1 && ! casted2)
3501  {
3502  SG_SDEBUG("leaving TParameter::compare_ptype(): SGObjects are equal\n");
3503  return true;
3504  }
3505 
3506  /* make sure to not call NULL methods */
3507  if (casted1)
3508  {
3509  if (!(casted1->equals(casted2, accuracy)))
3510  {
3511  SG_SINFO("leaving TParameter::compare_ptype(): PT_SGOBJECT "
3512  "equals returned false\n");
3513  return false;
3514  }
3515  }
3516  else
3517  {
3518  if (!(casted2->equals(casted1, accuracy)))
3519  {
3520  SG_SINFO("leaving TParameter::compare_ptype(): PT_SGOBJECT "
3521  "equals returned false\n");
3522  return false;
3523  }
3524 
3525  }
3526  break;
3527  }
3528  default:
3529  SG_SERROR("TParameter::compare_ptype(): Encountered unknown primitive"
3530  "-type: %d\n", ptype);
3531  break;
3532  }
3533 
3534  SG_SDEBUG("leaving TParameter::compare_ptype(): Data are equal\n");
3535  return true;
3536 }
3537 
3538 bool TParameter::copy_ptype(EPrimitiveType ptype, void* source, void* target)
3539 {
3540  SG_SDEBUG("entering TParameter::copy_ptype()\n");
3541 
3542  /* rather than using memcpy, use the cumbersome way here and cast all types.
3543  * This makes it so much easier to debug code.
3544  * Copy full stype if this is too slow */
3545  switch (ptype)
3546  {
3547  case PT_BOOL:
3548  {
3549  *((bool*)target)=*((bool*)source);
3550  SG_SDEBUG("after copy of ptype PT_BOOL: source %d, target %d\n",
3551  *((bool*)source), *((bool*)target));
3552  break;
3553  }
3554  case PT_CHAR:
3555  {
3556  *((char*)target)=*((char*)source);
3557  SG_SDEBUG("after copy of ptype PT_CHAR: source %c, target %c\n",
3558  *((char*)source), *((char*)target));
3559  break;
3560  }
3561  case PT_INT8:
3562  {
3563  *((int8_t*)target)=*((int8_t*)source);
3564  SG_SDEBUG("after copy of ptype PT_INT8: source %d, target %d\n",
3565  *((int8_t*)source), *((int8_t*)target));
3566  break;
3567  }
3568  case PT_UINT8:
3569  {
3570  *((uint8_t*)target)=*((uint8_t*)source);
3571  SG_SDEBUG("after copy of ptype PT_UINT8: source %d, target %d\n",
3572  *((uint8_t*)source), *((uint8_t*)target));
3573  break;
3574  }
3575  case PT_INT16:
3576  {
3577  *((int16_t*)target)=*((int16_t*)source);
3578  SG_SDEBUG("after copy of ptype PT_INT16: source %d, target %d\n",
3579  *((int16_t*)source), *((int16_t*)target));
3580  break;
3581  }
3582  case PT_UINT16:
3583  {
3584  *((uint16_t*)target)=*((uint16_t*)source);
3585  SG_SDEBUG("after copy of ptype PT_UINT16: source %d, target %d\n",
3586  *((uint16_t*)source), *((uint16_t*)target));
3587  break;
3588  }
3589  case PT_INT32:
3590  {
3591  *((int32_t*)target)=*((int32_t*)source);
3592  SG_SDEBUG("after copy of ptype PT_INT32: source %d, target %d\n",
3593  *((int32_t*)source), *((int32_t*)target));
3594  break;
3595  }
3596  case PT_UINT32:
3597  {
3598  *((uint32_t*)target)=*((uint32_t*)source);
3599  SG_SDEBUG("after copy of ptype PT_UINT32: source %d, target %d\n",
3600  *((uint32_t*)source), *((uint32_t*)target));
3601  break;
3602  }
3603  case PT_INT64:
3604  {
3605  *((int64_t*)target)=*((int64_t*)source);
3606  SG_SDEBUG("after copy of ptype PT_INT64: source %d, target %d\n",
3607  *((int64_t*)source), *((int64_t*)target));
3608  break;
3609  }
3610  case PT_UINT64:
3611  {
3612  *((uint64_t*)target)=*((uint64_t*)source);
3613  SG_SDEBUG("after copy of ptype PT_UINT64: source %d, target %d\n",
3614  *((uint64_t*)source), *((uint64_t*)target));
3615  break;
3616  }
3617  case PT_FLOAT32:
3618  {
3619  *((float32_t*)target)=*((float32_t*)source);
3620  SG_SDEBUG("after copy of ptype PT_FLOAT32: source %f, target %f\n",
3621  *((float32_t*)source), *((float32_t*)target));
3622  break;
3623  }
3624  case PT_FLOAT64:
3625  {
3626  *((float64_t*)target)=*((float64_t*)source);
3627  SG_SDEBUG("after copy of ptype PT_FLOAT64: source %f, target %f\n",
3628  *((float64_t*)source), *((float64_t*)target));
3629  break;
3630  }
3631  case PT_FLOATMAX:
3632  {
3633  *((floatmax_t*)target)=*((floatmax_t*)source);
3634  SG_SDEBUG("after copy of ptype PT_FLOATMAX: source %Lf, target %Lf\n",
3635  *((floatmax_t*)source), *((floatmax_t*)target));
3636  break;
3637  }
3638  case PT_COMPLEX128:
3639  {
3640  *((complex128_t*)target)=*((complex128_t*)source);
3641  SG_SDEBUG("after copy of ptype PT_COMPLEX128: "
3642  "source real %f, target real %f,"
3643  "source imag %f, target imag %f,"
3644  "\n",
3645  ((complex128_t*)source)->real(), ((complex128_t*)target)->real(),
3646  ((complex128_t*)source)->imag(), ((complex128_t*)target)->imag());
3647  break;
3648  }
3649  case PT_SGOBJECT:
3650  {
3651  CSGObject* casted1=*((CSGObject**)source);
3652  CSGObject* casted2=*((CSGObject**)target);
3653 
3654  /* important not to call methods on NULL */
3655  if (!casted1 && ! casted2)
3656  {
3657  SG_SDEBUG("leaving TParameter::copy_ptype(): Both SGObjects are NULL\n");
3658  return true;
3659  }
3660 
3661  /* make sure to not call NULL methods */
3662  if (casted1)
3663  {
3664  /* in case of overwriting old objects */
3665  SG_UNREF(*((CSGObject**)target));
3666  *((CSGObject**)target) = casted1->clone();
3667  }
3668 
3669  break;
3670  }
3671  default:
3672  SG_SERROR("TParameter::compare_ptype(): Encountered unknown primitive"
3673  "-type: %d\n", ptype);
3674  return false;
3675  break;
3676  }
3677 
3678  SG_SDEBUG("leaving TParameter::copy_ptype(): Copy successful\n");
3679  return true;
3680 }
3681 
3682 bool TParameter::compare_stype(EStructType stype, EPrimitiveType ptype,
3683  void* data1, void* data2, float64_t accuracy, bool tolerant)
3684 {
3685  SG_SDEBUG("entering TParameter::compare_stype()\n");
3686 
3687  size_t size_ptype=TSGDataType::sizeof_ptype(ptype);
3688 
3689  /* Avoid comparing NULL */
3690  if (!data1 && !data2)
3691  {
3692  SG_SDEBUG("leaving TParameter::compare_stype(): both data are NULL\n");
3693  return true;
3694  }
3695 
3696  /* If one is NULL, data are not equal */
3697  if ((data1 && !data2) || (!data1 && data2))
3698  {
3699  SG_SINFO("leaving TParameter::compare_stype(): data1 is at %p while "
3700  "data2 is at %p\n", data1, data2);
3701  return false;
3702  }
3703 
3704  switch (stype)
3705  {
3706  case ST_NONE:
3707  {
3708  SG_SDEBUG("ST_NONE\n");
3709  return TParameter::compare_ptype(ptype, data1, data2, accuracy, tolerant);
3710  break;
3711  }
3712  case ST_SPARSE:
3713  {
3714  SG_SDEBUG("ST_SPARSE\n");
3715  SGSparseVector<char>* spr_ptr1 = (SGSparseVector<char>*) data1;
3716  SGSparseVector<char>* spr_ptr2 = (SGSparseVector<char>*) data2;
3717 
3718  if (spr_ptr1->num_feat_entries != spr_ptr2->num_feat_entries)
3719  {
3720  SG_SINFO("leaving TParameter::compare_stype(): Length of "
3721  "sparse vector1 (%d) is different of vector 2 (%d)\n",
3722  spr_ptr1->num_feat_entries, spr_ptr2->num_feat_entries);
3723  return false;
3724  }
3725 
3726  SG_SDEBUG("Comparing sparse vectors\n");
3727  for (index_t i=0; i<spr_ptr1->num_feat_entries; ++i)
3728  {
3729  SG_SDEBUG("Comparing sparse entry %d at offset %d\n", i,
3731 
3733  ((char*) spr_ptr1->features + i*TSGDataType
3734  ::sizeof_sparseentry(ptype));
3736  ((char*) spr_ptr2->features + i*TSGDataType
3737  ::sizeof_sparseentry(ptype));
3738 
3739  /* sparse entries have an offset of the enty pointer depending
3740  * on type. Since I cast everything down to char, I need to remove
3741  * the char offset and add the offset of the ptype */
3742  index_t char_offset=TSGDataType::offset_sparseentry(PT_CHAR);
3743  index_t ptype_offset=TSGDataType::offset_sparseentry(ptype);
3744  void* pointer1=&(cur1->entry)-char_offset+ptype_offset;
3745  void* pointer2=&(cur2->entry)-char_offset+ptype_offset;
3746 
3747  if (!TParameter::compare_ptype(ptype, pointer1,
3748  pointer2, accuracy, tolerant))
3749  {
3750  SG_SINFO("leaving TParameter::compare_stype(): Data of"
3751  " sparse vector element is different\n");
3752  return false;
3753  }
3754 
3755  /* also compare feature indices */
3756  if (cur2->feat_index!=cur1->feat_index)
3757  {
3758  SG_SINFO("leaving TParameter::compare_stype(): Feature "
3759  "index of sparse vector element is different. "
3760  "source: %d, target: %d\n",
3761  cur1->feat_index, cur2->feat_index);
3762  return false;
3763  }
3764  }
3765  break;
3766  }
3767  case ST_STRING:
3768  {
3769  SG_SDEBUG("ST_STRING\n");
3770  SGString<char>* str_ptr1 = (SGString<char>*) data1;
3771  SGString<char>* str_ptr2 = (SGString<char>*) data2;
3772 
3773  if (str_ptr1->slen != str_ptr2->slen)
3774  {
3775  SG_SINFO("leaving TParameter::compare_stype(): Length of "
3776  "string1 (%d) is different of string2 (%d)\n",
3777  str_ptr1->slen, str_ptr2->slen);
3778  return false;
3779  }
3780 
3781  SG_SDEBUG("Comparing strings\n");
3782  for (index_t i=0; i<str_ptr1->slen; ++i)
3783  {
3784  SG_SDEBUG("Comparing string element %d at offset %d\n", i,
3785  i*size_ptype);
3786  void* pointer1=str_ptr1->string+i*size_ptype;
3787  void* pointer2=str_ptr2->string+i*size_ptype;
3788 
3789  if (!TParameter::compare_ptype(ptype, pointer1,
3790  pointer2, accuracy, tolerant))
3791  {
3792  SG_SINFO("leaving TParameter::compare_stype(): Data of"
3793  " string element is different\n");
3794  return false;
3795  }
3796  }
3797  break;
3798  }
3799  default:
3800  {
3801  SG_SERROR("TParameter::compare_stype(): Undefined struct type\n");
3802  break;
3803  }
3804  }
3805 
3806  SG_SDEBUG("leaving TParameter::compare_stype(): Data were equal\n");
3807  return true;
3808 }
3809 
3810 bool TParameter::copy_stype(EStructType stype, EPrimitiveType ptype,
3811  void* source, void* target)
3812 {
3813  SG_SDEBUG("entering TParameter::copy_stype()\n");
3814  size_t size_ptype=TSGDataType::sizeof_ptype(ptype);
3815 
3816  /* Heiko Strathmann: While I know that copying the stypes string and sparse
3817  * element wise is slower than doing the full things, it is way easier to
3818  * program and to debug since I already made sure that copy_ptype works as
3819  * intended. In addition, strings and vectors of SGObjects can be treated
3820  * recursively this way (we dont have cases for this currently, June 2013,
3821  * but they can be added without having to modify this code)
3822  *
3823  * Therefore, this code is very close to the the equals code for
3824  * stypes. If it turns out to be too slow (which I doubt), stypes can be
3825  * copied with memcpy over the full memory blocks */
3826 
3827  switch (stype)
3828  {
3829  case ST_NONE:
3830  {
3831  SG_SDEBUG("ST_NONE\n");
3832  return TParameter::copy_ptype(ptype, source, target);
3833  break;
3834  }
3835  case ST_STRING:
3836  {
3837  SG_SDEBUG("ST_STRING\n");
3838  SGString<char>* source_ptr = (SGString<char>*) source;
3839  SGString<char>* target_ptr = (SGString<char>*) target;
3840 
3841  if (source_ptr->slen != target_ptr->slen)
3842  {
3843  SG_SDEBUG("string lengths different (source: %d vs target: %d),"
3844  " freeing memory.\n", source_ptr->slen, target_ptr->slen);
3845 
3846  /* if string have different lengths, free data and make equal */
3847  SG_FREE(target_ptr->string);
3848  target_ptr->string=NULL;
3849  target_ptr->slen=0;
3850  }
3851 
3852  if (!target_ptr->string)
3853  {
3854  /* allocate memory if data is NULL */
3855  size_t num_bytes=source_ptr->slen * size_ptype;
3856 
3857  SG_SDEBUG("target string data NULL, allocating %d bytes.\n",
3858  num_bytes);
3859  target_ptr->string=SG_MALLOC(char, num_bytes);
3860  target_ptr->slen=source_ptr->slen;
3861  }
3862 
3863  SG_SDEBUG("Copying strings\n");
3864  for (index_t i=0; i<source_ptr->slen; ++i)
3865  {
3866  SG_SDEBUG("Copying string element %d at offset %d\n", i,
3867  i*size_ptype);
3868  void* pointer1=source_ptr->string+i*size_ptype;
3869  void* pointer2=target_ptr->string+i*size_ptype;
3870 
3871  if (!TParameter::copy_ptype(ptype, pointer1, pointer2))
3872  {
3873  SG_SDEBUG("leaving TParameter::copy_stype(): Copy of string"
3874  " element failed.\n");
3875  return false;
3876  }
3877  }
3878  break;
3879  }
3880  case ST_SPARSE:
3881  {
3882  SG_SDEBUG("ST_SPARSE\n");
3883  SGSparseVector<char>* source_ptr = (SGSparseVector<char>*) source;
3884  SGSparseVector<char>* target_ptr = (SGSparseVector<char>*) target;
3885 
3886  if (source_ptr->num_feat_entries != target_ptr->num_feat_entries)
3887  {
3888  SG_SDEBUG("sparse vector lengths different (source: %d vs target: %d),"
3889  " freeing memory.\n",
3890  source_ptr->num_feat_entries, target_ptr->num_feat_entries);
3891 
3892  /* if string have different lengths, free data and make equal */
3893  SG_FREE(target_ptr->features);
3894  target_ptr->features=NULL;
3895  target_ptr->num_feat_entries=0;
3896  }
3897 
3898  if (!target_ptr->features)
3899  {
3900  /* allocate memory if data is NULL */
3901  size_t num_bytes=source_ptr->num_feat_entries *
3903 
3904  SG_SDEBUG("target sparse data NULL, allocating %d bytes.\n",
3905  num_bytes);
3906  target_ptr->features=(SGSparseVectorEntry<char>*)SG_MALLOC(char, num_bytes);
3907  target_ptr->num_feat_entries=source_ptr->num_feat_entries;
3908  }
3909 
3910  SG_SDEBUG("Copying sparse vectors\n");
3911  for (index_t i=0; i<source_ptr->num_feat_entries; ++i)
3912  {
3913  SG_SDEBUG("Copying sparse entry %d at offset %d\n", i,
3915 
3917  ((char*) source_ptr->features + i*TSGDataType
3918  ::sizeof_sparseentry(ptype));
3920  ((char*) target_ptr->features + i*TSGDataType
3921  ::sizeof_sparseentry(ptype));
3922 
3923  /* sparse entries have an offset of the enty pointer depending
3924  * on type. Since I cast everything down to char, I need to remove
3925  * the char offset and add the offset of the ptype */
3926  index_t char_offset=TSGDataType::offset_sparseentry(PT_CHAR);
3927  index_t ptype_offset=TSGDataType::offset_sparseentry(ptype);
3928  void* pointer1=&(cur1->entry)-char_offset+ptype_offset;
3929  void* pointer2=&(cur2->entry)-char_offset+ptype_offset;
3930 
3931  if (!TParameter::copy_ptype(ptype, pointer1, pointer2))
3932  {
3933  SG_SDEBUG("leaving TParameter::copy_stype(): Copy of sparse"
3934  " vector element failed\n");
3935  return false;
3936  }
3937 
3938  /* afterwards, copy feature indices, wich are the data before
3939  * the avove offeet */
3940  cur2->feat_index=cur1->feat_index;
3941  }
3942  break;
3943  }
3944  default:
3945  {
3946  SG_SERROR("TParameter::copy_stype(): Undefined struct type\n");
3947  return false;
3948  break;
3949  }
3950  }
3951 
3952  SG_SDEBUG("leaving TParameter::copy_stype(): Copy successful\n");
3953  return true;
3954 }
3955 
3957 {
3958  SG_SDEBUG("entering TParameter::copy()\n");
3959 
3960  if (!target)
3961  {
3962  SG_SDEBUG("leaving TParameter::copy(): other parameter is NULL\n");
3963  return false;
3964  }
3965 
3966  if (!m_parameter)
3967  {
3968  SG_SDEBUG("leaving TParameter::copy(): m_parameter of source is NULL\n");
3969  return false;
3970  }
3971 
3972  if (!target->m_parameter)
3973  {
3974  SG_SDEBUG("leaving TParameter::copy(): m_parameter of target is NULL\n");
3975  return false;
3976  }
3977 
3978  if (strcmp(m_name, target->m_name))
3979  {
3980  SG_SDEBUG("leaving TParameter::copy(): name \"%s\" is different from"
3981  " target parameter's "
3982  "name \"%s\"\n", m_name, target->m_name);
3983  return false;
3984  }
3985 
3986  SG_SDEBUG("Comparing datatypes without length\n");
3988  {
3989  SG_SDEBUG("leaving TParameter::copy(): type of \"%s\" is different "
3990  "from target parameter's \"%s\" type\n", m_name, target->m_name);
3991  return false;
3992  }
3993 
3994  switch (m_datatype.m_ctype)
3995  {
3996  case CT_SCALAR:
3997  {
3998  SG_SDEBUG("CT_SCALAR\n");
4001  target->m_parameter))
4002  {
4003  SG_SDEBUG("leaving TParameter::copy(): scalar data copy error\n");
4004  return false;
4005  }
4006  break;
4007  }
4008  case CT_VECTOR: case CT_SGVECTOR:
4009  {
4010  SG_SDEBUG("CT_VECTOR or CT_SGVECTOR\n");
4011 
4012  /* if sizes are different or memory is not allocated, do that */
4013  if (!m_datatype.equals(target->m_datatype))
4014  {
4015  SG_SDEBUG("changing size of target vector and freeing memory\n");
4016  /* first case: different sizes, free target memory */
4017  SG_FREE(*(char**)target->m_parameter);
4018  *(char**)target->m_parameter=NULL;
4019 
4020  }
4021 
4022  /* check whether target m_parameter data contains NULL, if yes
4023  * create if the length is non-zero */
4024  if (*(char**)target->m_parameter==NULL && *m_datatype.m_length_y>0)
4025  {
4026  size_t num_bytes=*m_datatype.m_length_y * m_datatype.sizeof_stype();
4027  SG_SDEBUG("allocating %d bytes memory for target vector\n", num_bytes);
4028 
4029  *(char**)target->m_parameter=SG_MALLOC(char, num_bytes);
4030  /* check whether ptype is SGOBJECT, if yes we need to initialize
4031  the memory with NULL for the way copy_ptype handles it */
4032  if (m_datatype.m_ptype==PT_SGOBJECT)
4033  memset(*(void**)target->m_parameter, 0, num_bytes);
4034 
4035  /* use length of source */
4037  }
4038 
4039  /* now start actual copying, assume that sizes are equal and memory
4040  * is there */
4041  ASSERT(m_datatype.equals(target->m_datatype));
4042 
4043  /* x is number of processed bytes */
4044  index_t x=0;
4045  SG_SDEBUG("length_y: %d\n", *m_datatype.m_length_y)
4046  for (index_t i=0; i<*m_datatype.m_length_y; ++i)
4047  {
4048  SG_SDEBUG("copying element %d which is %d byes from start\n",
4049  i, x);
4050 
4051  void* pointer_a=&((*(char**)m_parameter)[x]);
4052  void* pointer_b=&((*(char**)target->m_parameter)[x]);
4053 
4055  m_datatype.m_ptype, pointer_a, pointer_b))
4056  {
4057  SG_SDEBUG("leaving TParameter::copy(): vector element "
4058  "copy error\n");
4059  return false;
4060  }
4061 
4062  x=x+(m_datatype.sizeof_ptype());
4063  }
4064 
4065  break;
4066  }
4067  case CT_MATRIX: case CT_SGMATRIX:
4068  {
4069  SG_SDEBUG("CT_MATRIX or CT_SGMATRIX\n");
4070 
4071  /* if sizes are different or memory is not allocated, do that */
4072  if (!m_datatype.equals(target->m_datatype))
4073  {
4074  SG_SDEBUG("changing size of target vector and freeing memory\n");
4075  /* first case: different sizes, free target memory */
4076  SG_FREE(*(char**)target->m_parameter);
4077  *(char**)target->m_parameter=NULL;
4078  }
4079 
4080  /* check whether target m_parameter data contains NULL, if yes, create */
4081  if (*(char**)target->m_parameter==NULL)
4082  {
4083  SG_SDEBUG("allocating memory for target vector\n");
4084  size_t num_bytes=0;
4085  /* for ST_SPARSE allocate only for a vector of m_length_y */
4086  if (m_datatype.m_stype==ST_SPARSE)
4088  else
4089  num_bytes=*m_datatype.m_length_y *
4091 
4092  *(char**)target->m_parameter=SG_MALLOC(char, num_bytes);
4093 
4094  /* check whether ptype is SGOBJECT, if yes we need to initialize
4095  the memory with NULL for the way copy_ptype handles it */
4096  if (m_datatype.m_ptype==PT_SGOBJECT)
4097  memset(*(void**)target->m_parameter, 0, num_bytes);
4098 
4099  /* use length of source */
4102 
4103  SG_SDEBUG("%d bytes are allocated\n", num_bytes);
4104  }
4105 
4106  /* now start actual copying, assume that sizes are equal and memory
4107  * is there */
4108  ASSERT(m_datatype.equals(target->m_datatype));
4109 
4110  /* x is number of processed bytes */
4111  index_t x=0;
4112  SG_SDEBUG("length_y: %d\n", *m_datatype.m_length_y)
4113  SG_SDEBUG("length_x: %d\n", *m_datatype.m_length_x)
4114  int64_t length=0;
4115  /* for ST_SPARSE allocate iterate over a vector of m_length_y */
4116  if (m_datatype.m_stype==ST_SPARSE)
4117  length=(*m_datatype.m_length_y);
4118  else
4119  length=(*m_datatype.m_length_y) * (*m_datatype.m_length_x);
4120  for (index_t i=0; i<length; ++i)
4121  {
4122  SG_SDEBUG("copying element %d which is %d byes from start\n",
4123  i, x);
4124 
4125  void* pointer_a=&((*(char**)m_parameter)[x]);
4126  void* pointer_b=&((*(char**)target->m_parameter)[x]);
4127 
4129  m_datatype.m_ptype, pointer_a, pointer_b))
4130  {
4131  SG_SDEBUG("leaving TParameter::copy(): vector element "
4132  "differs\n");
4133  return false;
4134  }
4135 
4136  /* For ST_SPARSE, the iteration is on the pointer of SGSparseVectors */
4137  if (m_datatype.m_stype==ST_SPARSE)
4138  x=x+(m_datatype.sizeof_stype());
4139  else
4140  x=x+(m_datatype.sizeof_ptype());
4141  }
4142 
4143  break;
4144  }
4145  case CT_NDARRAY:
4146  {
4147  SG_SDEBUG("CT_NDARRAY\n");
4148  SG_SERROR("TParameter::copy(): Not yet implemented for "
4149  "CT_NDARRAY!\n");
4150  break;
4151  }
4152  case CT_UNDEFINED: default:
4153  SG_SERROR("Implementation error: undefined container type\n");
4154  break;
4155  }
4156 
4157  SG_SDEBUG("leaving TParameter::copy(): Copy successful\n");
4158  return true;
4159 }

SHOGUN Machine Learning Toolbox - Documentation