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  const int32_t buflen=100;
2652  char* buf=SG_MALLOC(char, buflen);
2653  m_datatype.to_string(buf, buflen);
2654  SG_SDEBUG("Loading parameter '%s' of type '%s'\n", m_name, buf)
2655  SG_FREE(buf);
2656 
2657  if (!file->read_type_begin(&m_datatype, m_name, prefix))
2658  return false;
2659 
2660  switch (m_datatype.m_ctype)
2661  {
2662  case CT_NDARRAY:
2664  break;
2665  case CT_SCALAR:
2666  if (!load_stype(file, m_parameter, prefix))
2667  return false;
2668  break;
2669 
2670  case CT_VECTOR: case CT_MATRIX: case CT_SGVECTOR: case CT_SGMATRIX:
2671  {
2672  SGVector<index_t> dims(2);
2673  dims.zero();
2674 
2675  if (!file->read_cont_begin(&m_datatype, m_name, prefix,
2676  &dims.vector[1], &dims.vector[0]))
2677  return false;
2678 
2679  switch (m_datatype.m_ctype)
2680  {
2681  case CT_NDARRAY:
2683  break;
2684  case CT_VECTOR: case CT_SGVECTOR:
2685  dims[0]=1;
2686  new_cont(dims);
2687  break;
2688  case CT_MATRIX: case CT_SGMATRIX:
2689  new_cont(dims);
2690  break;
2691  case CT_SCALAR:
2692  break;
2693  case CT_UNDEFINED: default:
2694  SG_SERROR("Implementation error: undefined container type\n");
2695  break;
2696  }
2697 
2698  for (index_t x=0; x<dims[0]; x++)
2699  {
2700  for (index_t y=0; y<dims[1]; y++)
2701  {
2702  if (!file->read_item_begin(
2703  &m_datatype, m_name, prefix, y, x))
2704  return false;
2705 
2706  if (!load_stype(
2707  file, (*(char**) m_parameter)
2708  + (x*dims[1] + y)*m_datatype.sizeof_stype(),
2709  prefix)) return false;
2710  if (!file->read_item_end(
2711  &m_datatype, m_name, prefix, y, x))
2712  return false;
2713  }
2714  }
2715 
2716  switch (m_datatype.m_ctype)
2717  {
2718  case CT_NDARRAY:
2720  break;
2721  case CT_VECTOR: case CT_SGVECTOR:
2722  *m_datatype.m_length_y = dims[1];
2723  break;
2724  case CT_MATRIX: case CT_SGMATRIX:
2725  *m_datatype.m_length_y = dims[1];
2726  *m_datatype.m_length_x = dims[0];
2727  break;
2728  case CT_SCALAR:
2729  break;
2730  case CT_UNDEFINED: default:
2731  SG_SERROR("Implementation error: undefined container type\n");
2732  break;
2733  }
2734 
2735  if (!file->read_cont_end(&m_datatype, m_name, prefix,
2736  dims[1], dims[0]))
2737  return false;
2738 
2739  break;
2740  }
2741  case CT_UNDEFINED: default:
2742  SG_SERROR("Implementation error: undefined container type\n");
2743  break;
2744  }
2745 
2746  if (!file->read_type_end(&m_datatype, m_name, prefix))
2747  return false;
2748 
2749  return true;
2750 }
2751 
2752 /*
2753  Initializing m_params(1) with small preallocation-size, because Parameter
2754  will be constructed several times for EACH SGObject instance.
2755  */
2756 Parameter::Parameter() : m_params(1)
2757 {
2758  SG_REF(sg_io);
2759 }
2760 
2762 {
2763  for (int32_t i=0; i<get_num_parameters(); i++)
2764  delete m_params.get_element(i);
2765 
2766  SG_UNREF(sg_io);
2767 }
2768 
2769 void
2770 Parameter::add_type(const TSGDataType* type, void* param,
2771  const char* name, const char* description)
2772 {
2773  if (name == NULL || *name == '\0')
2774  SG_SERROR("FATAL: Parameter::add_type(): `name' is empty!\n")
2775 
2776  for (size_t i=0; i<strlen(name); ++i)
2777  {
2778  if (!std::isalnum(name[i]) && name[i]!='_' && name[i]!='.')
2779  {
2780  SG_SERROR("Character %d of parameter with name \"%s\" is illegal "
2781  "(only alnum or underscore is allowed)\n",
2782  i, name);
2783  }
2784  }
2785 
2786  for (int32_t i=0; i<get_num_parameters(); i++)
2787  if (strcmp(m_params.get_element(i)->m_name, name) == 0)
2788  SG_SERROR("FATAL: Parameter::add_type(): "
2789  "Double parameter `%s'!\n", name);
2790 
2792  new TParameter(type, param, name, description)
2793  );
2794 }
2795 
2796 void
2797 Parameter::print(const char* prefix)
2798 {
2799  for (int32_t i=0; i<get_num_parameters(); i++)
2800  m_params.get_element(i)->print(prefix);
2801 }
2802 
2803 bool
2804 Parameter::save(CSerializableFile* file, const char* prefix)
2805 {
2806  for (int32_t i=0; i<get_num_parameters(); i++)
2807  {
2808  if (!m_params.get_element(i)->save(file, prefix))
2809  return false;
2810  }
2811 
2812  return true;
2813 }
2814 
2815 //bool
2816 //Parameter::load(CSerializableFile* file, const char* prefix)
2817 //{
2818 // for (int32_t i=0; i<get_num_parameters(); i++)
2819 // if (!m_params.get_element(i)->load(file, prefix))
2820 // return false;
2821 //
2822 // return true;
2823 //}
2824 
2826 {
2827  /* iterate over parameters in the given list */
2828  for (index_t i=0; i<params->get_num_parameters(); ++i)
2829  {
2830  TParameter* current=params->get_parameter(i);
2831  TSGDataType current_type=current->m_datatype;
2832 
2834 
2835  /* search for own parameter with same name and check types if found */
2836  TParameter* own=NULL;
2837  for (index_t j=0; j<m_params.get_num_elements(); ++j)
2838  {
2839  own=m_params.get_element(j);
2840  if (!strcmp(own->m_name, current->m_name))
2841  {
2842  if (own->m_datatype==current_type)
2843  {
2844  own=m_params.get_element(j);
2845  break;
2846  }
2847  else
2848  {
2849  index_t l=200;
2850  char* given_type=SG_MALLOC(char, l);
2851  char* own_type=SG_MALLOC(char, l);
2852  current->m_datatype.to_string(given_type, l);
2853  own->m_datatype.to_string(own_type, l);
2854  SG_SERROR("given parameter \"%s\" has a different type (%s)"
2855  " than existing one (%s)\n", current->m_name,
2856  given_type, own_type);
2857  SG_FREE(given_type);
2858  SG_FREE(own_type);
2859  }
2860  }
2861  else
2862  own=NULL;
2863  }
2864 
2865  if (!own)
2866  {
2867  SG_SERROR("parameter with name %s does not exist\n",
2868  current->m_name);
2869  }
2870 
2871  /* check if parameter contained CSGobjects (update reference counts) */
2872  if (current_type.m_ptype==PT_SGOBJECT)
2873  {
2874  /* PT_SGOBJECT only occurs for ST_NONE */
2875  if (own->m_datatype.m_stype==ST_NONE)
2876  {
2877  if (own->m_datatype.m_ctype==CT_SCALAR)
2878  {
2879  CSGObject** to_unref=(CSGObject**) own->m_parameter;
2880  CSGObject** to_ref=(CSGObject**) current->m_parameter;
2881 
2882  if ((*to_ref)!=(*to_unref))
2883  {
2884  SG_REF((*to_ref));
2885  SG_UNREF((*to_unref));
2886  }
2887 
2888  }
2889  else
2890  {
2891  /* unref all SGObjects and reference the new ones */
2892  CSGObject*** to_unref=(CSGObject***) own->m_parameter;
2893  CSGObject*** to_ref=(CSGObject***) current->m_parameter;
2894 
2895  for (index_t j=0; j<own->m_datatype.get_num_elements(); ++j)
2896  {
2897  if ((*to_ref)[j]!=(*to_unref)[j])
2898  {
2899  SG_REF(((*to_ref)[j]));
2900  SG_UNREF(((*to_unref)[j]));
2901  }
2902  }
2903  }
2904  }
2905  else
2906  SG_SERROR("primitive type PT_SGOBJECT occurred with structure "
2907  "type other than ST_NONE");
2908  }
2909 
2910  /* construct pointers to the to be copied parameter data */
2911  void* dest=NULL;
2912  void* source=NULL;
2913  if (current_type.m_ctype==CT_SCALAR)
2914  {
2915  /* for scalar values, just copy content the pointer points to */
2916  dest=own->m_parameter;
2917  source=current->m_parameter;
2918 
2919  /* in case of CSGObject, pointers are not equal if CSGObjects are
2920  * equal, so check. For other values, the pointers are equal and
2921  * the not-copying is handled below before the memcpy call */
2922  if (own->m_datatype.m_ptype==PT_SGOBJECT)
2923  {
2924  if (*((CSGObject**)dest) == *((CSGObject**)source))
2925  {
2926  dest=NULL;
2927  source=NULL;
2928  }
2929  }
2930  }
2931  else
2932  {
2933  /* for matrices and vectors, sadly m_parameter has to be
2934  * de-referenced once, because a pointer to the array address is
2935  * saved, but the array address itself has to be copied.
2936  * consequently, for dereferencing, a type distinction is needed */
2937  switch (own->m_datatype.m_ptype)
2938  {
2939  case PT_FLOAT64:
2940  dest=*((float64_t**) own->m_parameter);
2941  source=*((float64_t**) current->m_parameter);
2942  break;
2943  case PT_SGOBJECT:
2944  dest=*((CSGObject**) own->m_parameter);
2945  source=*((CSGObject**) current->m_parameter);
2946  break;
2947  default:
2949  break;
2950  }
2951  }
2952 
2953  /* copy parameter data, size in memory is equal because of same type */
2954  if (dest!=source)
2955  memcpy(dest, source, own->m_datatype.get_size());
2956  }
2957 }
2958 
2960 {
2961  for (index_t i=0; i<params->get_num_parameters(); ++i)
2962  {
2963  TParameter* current=params->get_parameter(i);
2964  add_type(&(current->m_datatype), current->m_parameter, current->m_name,
2965  current->m_description);
2966  }
2967 }
2968 
2969 bool Parameter::contains_parameter(const char* name)
2970 {
2971  for (index_t i=0; i<m_params.get_num_elements(); ++i)
2972  {
2973  if (!strcmp(name, m_params[i]->m_name))
2974  return true;
2975  }
2976 
2977  return false;
2978 }
2979 
2980 bool TParameter::operator==(const TParameter& other) const
2981 {
2982  bool result=true;
2983  result&=!strcmp(m_name, other.m_name);
2984  return result;
2985 }
2986 
2987 bool TParameter::operator<(const TParameter& other) const
2988 {
2989  return strcmp(m_name, other.m_name)<0;
2990 }
2991 
2992 bool TParameter::operator>(const TParameter& other) const
2993 {
2994  return strcmp(m_name, other.m_name)>0;
2995 }
2996 
2998  bool new_cont_call)
2999 {
3000  SG_SDEBUG("entering TParameter::allocate_data_from_scratch of "
3001  "\"%s\"\n", m_name);
3002 
3003  /* set flag to delete all this stuff later on */
3005 
3006  /* length has to be allocated for matrices/vectors */
3007  switch (m_datatype.m_ctype)
3008  {
3009  case CT_VECTOR: case CT_SGVECTOR:
3010  m_datatype.m_length_y=SG_MALLOC(index_t, 1);
3011  *m_datatype.m_length_y=dims[1];
3012  break;
3013  case CT_MATRIX: case CT_SGMATRIX:
3014  m_datatype.m_length_x=SG_MALLOC(index_t, 1);
3015  m_datatype.m_length_y=SG_MALLOC(index_t, 1);
3016  *m_datatype.m_length_y=dims[1];
3017  *m_datatype.m_length_x=dims[0];
3018  break;
3019  case CT_SCALAR:
3020  m_datatype.m_length_x=NULL;
3021  m_datatype.m_length_y=NULL;
3022  break;
3023  case CT_NDARRAY:
3025  break;
3026  case CT_UNDEFINED: default:
3027  SG_SERROR("Implementation error: undefined container type\n");
3028  break;
3029  }
3030 
3031  /* check if there is no data loss */
3032  if (m_parameter)
3033  SG_SERROR("TParameter::allocate_data_from_scratch must not be called "
3034  "when the underlying TParameter instance already has data.\n");
3035 
3036  /* scalars are treated differently than vectors/matrices. memory has to
3037  * be allocated for the data itself */
3038  if (m_datatype.m_ctype==CT_SCALAR)
3039  {
3040  /* sgobjects are treated differently than the rest */
3041  if (m_datatype.m_ptype!=PT_SGOBJECT)
3042  {
3043  /* for non-sgobject allocate memory because normally they are on
3044  * stack and excluded in the TParameter data allocation.
3045  * Will be deleted by the TParameter destructor */
3046  m_parameter=SG_MALLOC(char, m_datatype.get_size());
3047  }
3048  else
3049  {
3050  /* for sgobjects, allocate memory for pointer and set to NULL
3051  * Will be deleted by the TParameter destructor */
3052  m_parameter=SG_MALLOC(CSGObject**, 1);
3053  *((CSGObject**)m_parameter)=NULL;
3054  }
3055  }
3056  else
3057  {
3058  /* allocate pointer for data pointer */
3059  void** data_p=SG_MALLOC(void*, 1);
3060  *data_p=NULL;
3061 
3062  /* allocate dummy data at the point the above pointer points to
3063  * will be freed by the delete_cont() method of TParameter.
3064  * This is needed because new_cont/delete_cont cannot handle
3065  * non-existing data. Set to NULL to avoid problems */
3066  if (new_cont_call)
3067  {
3068  *data_p=SG_MALLOC(void**, 1);
3069  **(void***)data_p=NULL;
3070  }
3071 
3072  m_parameter=data_p;
3073 
3074  /* perform one data allocation. This may be repeated and therefore
3075  * redundant if load() is called afterwards, however, if one wants
3076  * to write directly to the array data after this call, it is
3077  * necessary */
3078  if (new_cont_call)
3079  new_cont(dims);
3080  }
3081 
3082  SG_SDEBUG("leaving TParameter::allocate_data_from_scratch of "
3083  "\"%s\"\n", m_name);
3084 }
3085 
3087 {
3088  SG_SDEBUG("entering TParameter::copy_data for %s\n", m_name)
3089 
3090  /* assert that type is equal */
3094 
3095  /* first delete old data if non-scalar */
3096  if (m_datatype.m_ctype!=CT_SCALAR)
3097  delete_cont();
3098 
3099  /* then copy data in case of numeric scalars, or pointer to data else */
3100  if (m_datatype.m_ctype==CT_SCALAR && m_datatype.m_ptype!=PT_SGOBJECT)
3101  {
3102  /* just copy value behind pointer */
3103  SG_SDEBUG("Copying scalar data of size %d from %p to %p\n",
3105  memcpy(m_parameter, source->m_parameter,
3106  m_datatype.get_size());
3107  }
3108  else
3109  {
3110  /* if this is a sgobject, the old one has to be unrefed */
3111  if (m_datatype.m_ptype==PT_SGOBJECT)
3112  {
3113  if (m_datatype.m_ctype==CT_SCALAR)
3114  {
3116  }
3117  else
3118  {
3119  int32_t length=1;
3120  length*=m_datatype.m_length_x ? *m_datatype.m_length_x : 1;
3121  length*=m_datatype.m_length_y ? *m_datatype.m_length_y : 1;
3122 
3123  for (index_t j=0; j<length; ++j)
3124  {
3125  SG_UNREF(((CSGObject**)(m_parameter))[j]);
3126  }
3127  }
3128  }
3129 
3130  /* in this case, data is a pointer pointing to the actual
3131  * data, so copy pointer if non-NULL*/
3132  SG_SDEBUG("Copying non-scalar pointer %p\n", *((void**)source->m_parameter))
3133  *((void**)m_parameter)=*((void**)source->m_parameter);
3134  }
3135 
3136  /* copy lengths */
3137  if (source->m_datatype.m_length_x)
3139 
3140  if (source->m_datatype.m_length_y)
3142 
3143  SG_SDEBUG("leaving TParameter::copy_data for %s\n", m_name)
3144 }
3145 
3146 bool TParameter::equals(TParameter* other, float64_t accuracy, bool tolerant)
3147 {
3148  SG_SDEBUG("entering TParameter::equals()\n");
3149 
3150  if (!other)
3151  {
3152  SG_SDEBUG("leaving TParameter::equals(): other parameter is NULL\n");
3153  return false;
3154  }
3155 
3156  if (strcmp(m_name, other->m_name))
3157  {
3158  SG_SDEBUG("leaving TParameter::equals(): name \"%s\" is different from"
3159  " other parameter's name \"%s\"\n", m_name, other->m_name);
3160  return false;
3161  }
3162 
3163  SG_SDEBUG("Comparing datatypes\n");
3164  if (!(m_datatype.equals(other->m_datatype)))
3165  {
3166  SG_SDEBUG("leaving TParameter::equals(): type of \"%s\" is different "
3167  "from other parameter's \"%s\" type\n", m_name, other->m_name);
3168  return false;
3169  }
3170 
3171  /* avoid comparing NULL */
3172  if (!m_parameter && !other->m_parameter)
3173  {
3174  SG_SDEBUG("leaving TParameter::equals(): both parameters are NULL\n");
3175  return true;
3176  }
3177 
3178  if ((!m_parameter && other->m_parameter) || (m_parameter && !other->m_parameter))
3179  {
3180  SG_SDEBUG("leaving TParameter::equals(): param1 is at %p while "
3181  "param2 is at %p\n", m_parameter, other->m_parameter);
3182  return false;
3183  }
3184 
3185  SG_SDEBUG("Comparing ctype\n");
3186  switch (m_datatype.m_ctype)
3187  {
3188  case CT_SCALAR:
3189  {
3190  SG_SDEBUG("CT_SCALAR\n");
3193  other->m_parameter,
3194  accuracy, tolerant))
3195  {
3196  SG_SDEBUG("leaving TParameter::equals(): scalar data differs\n");
3197  return false;
3198  }
3199  break;
3200  }
3201  case CT_VECTOR: case CT_SGVECTOR:
3202  {
3203  SG_SDEBUG("CT_VECTOR or CT_SGVECTOR\n");
3204 
3205  /* x is number of processed bytes */
3206  index_t x=0;
3207  SG_SDEBUG("length_y: %d\n", *m_datatype.m_length_y)
3208  for (index_t i=0; i<*m_datatype.m_length_y; ++i)
3209  {
3210  SG_SDEBUG("comparing element %d which is %d bytes from start\n",
3211  i, x);
3212 
3213  void* pointer_a=&((*(char**)m_parameter)[x]);
3214  void* pointer_b=&((*(char**)other->m_parameter)[x]);
3215 
3217  m_datatype.m_ptype, pointer_a, pointer_b,
3218  accuracy, tolerant))
3219  {
3220  SG_SDEBUG("leaving TParameter::equals(): vector element "
3221  "differs\n");
3222  return false;
3223  }
3224 
3225  x=x+(m_datatype.sizeof_stype());
3226  }
3227 
3228  break;
3229  }
3230  case CT_MATRIX: case CT_SGMATRIX:
3231  {
3232  SG_SDEBUG("CT_MATRIX or CT_SGMATRIX\n");
3233 
3234  /* x is number of processed bytes */
3235  index_t x=0;
3236  SG_SDEBUG("length_y: %d\n", *m_datatype.m_length_y)
3237  SG_SDEBUG("length_x: %d\n", *m_datatype.m_length_x)
3238  int64_t length=0;
3239 
3240  /* For ST_SPARSE, we just need to loop over the rows and compare_stype
3241  * does the comparison for one whole row vector at once. For ST_NONE,
3242  * however, we need to loop over all elements.
3243  */
3244  if (m_datatype.m_stype==ST_SPARSE)
3245  length=(*m_datatype.m_length_y);
3246  else
3247  length=(*m_datatype.m_length_y) * (*m_datatype.m_length_x);
3248 
3249  for (index_t i=0; i<length; ++i)
3250  {
3251  SG_SDEBUG("comparing element %d which is %d bytes from start\n",
3252  i, x);
3253 
3254  void* pointer_a=&((*(char**)m_parameter)[x]);
3255  void* pointer_b=&((*(char**)other->m_parameter)[x]);
3256 
3258  m_datatype.m_ptype, pointer_a, pointer_b,
3259  accuracy, tolerant))
3260  {
3261  SG_SDEBUG("leaving TParameter::equals(): vector element "
3262  "differs\n");
3263  return false;
3264  }
3265 
3266  /* For ST_SPARSE, the iteration is on the pointer of SGSparseVectors */
3267  if (m_datatype.m_stype==ST_SPARSE)
3268  x=x+(m_datatype.sizeof_stype());
3269  else
3270  x=x+(m_datatype.sizeof_stype());
3271  }
3272 
3273  break;
3274  }
3275  case CT_NDARRAY:
3276  {
3277  SG_SDEBUG("CT_NDARRAY\n");
3278  SG_SERROR("TParameter::equals(): Not yet implemented for "
3279  "CT_NDARRAY!\n");
3280  break;
3281  }
3282  case CT_UNDEFINED: default:
3283  SG_SERROR("Implementation error: undefined container type\n");
3284  break;
3285  }
3286 
3287  SG_SDEBUG("leaving TParameter::equals(): Parameters are equal\n");
3288  return true;
3289 }
3290 
3291 bool TParameter::compare_ptype(EPrimitiveType ptype, void* data1, void* data2,
3292  float64_t accuracy, bool tolerant)
3293 {
3294  SG_SDEBUG("entering TParameter::compare_ptype()\n");
3295 
3296  if ((data1 && !data2) || (!data1 && data2))
3297  {
3298  SG_SINFO("leaving TParameter::compare_ptype(): data1 is at %p while "
3299  "data2 is at %p\n", data1, data2);
3300  return false;
3301  }
3302 
3304  if (!data1 && !data2)
3305  {
3306  SG_SDEBUG("leaving TParameter::compare_ptype(): both data are NULL\n");
3307  return true;
3308  }
3309 
3310  switch (ptype)
3311  {
3312  case PT_BOOL:
3313  {
3314  bool casted1=*((bool*)data1);
3315  bool casted2=*((bool*)data2);
3316 
3317  if (CMath::abs(casted1-casted2)>accuracy)
3318  {
3319  SG_SINFO("leaving TParameter::compare_ptype(): PT_BOOL: "
3320  "data1=%d, data2=%d\n", casted1, casted2);
3321  return false;
3322  }
3323  break;
3324  }
3325  case PT_CHAR:
3326  {
3327  char casted1=*((char*)data1);
3328  char casted2=*((char*)data2);
3329 
3330  if (CMath::abs(casted1-casted2)>accuracy)
3331  {
3332  SG_SINFO("leaving TParameter::compare_ptype(): PT_CHAR: "
3333  "data1=%c, data2=%c\n", casted1, casted2);
3334  return false;
3335  }
3336  break;
3337  }
3338  case PT_INT8:
3339  {
3340  int8_t casted1=*((int8_t*)data1);
3341  int8_t casted2=*((int8_t*)data2);
3342 
3343  if (CMath::abs(casted1-casted2)>accuracy)
3344  {
3345  SG_SINFO("leaving TParameter::compare_ptype(): PT_INT8: "
3346  "data1=%d, data2=%d\n", casted1, casted2);
3347  return false;
3348  }
3349  break;
3350  }
3351  case PT_UINT8:
3352  {
3353  uint8_t casted1=*((uint8_t*)data1);
3354  uint8_t casted2=*((uint8_t*)data2);
3355 
3356  if (CMath::abs(casted1-casted2)>accuracy)
3357  {
3358  SG_SINFO("leaving TParameter::compare_ptype(): PT_UINT8: "
3359  "data1=%d, data2=%d\n", casted1, casted2);
3360  return false;
3361  }
3362  break;
3363  }
3364  case PT_INT16:
3365  {
3366  int16_t casted1=*((int16_t*)data1);
3367  int16_t casted2=*((int16_t*)data2);
3368 
3369  if (CMath::abs(casted1-casted2)>accuracy)
3370  {
3371  SG_SINFO("leaving TParameter::compare_ptype(): PT_INT16: "
3372  "data1=%d, data2=%d\n", casted1, casted2);
3373  return false;
3374  }
3375  break;
3376  }
3377  case PT_UINT16:
3378  {
3379  uint16_t casted1=*((uint16_t*)data1);
3380  uint16_t casted2=*((uint16_t*)data2);
3381 
3382  if (CMath::abs(casted1-casted2)>accuracy)
3383  {
3384  SG_SINFO("leaving TParameter::compare_ptype(): PT_UINT16: "
3385  "data1=%d, data2=%d\n", casted1, casted2);
3386  return false;
3387  }
3388  break;
3389  }
3390  case PT_INT32:
3391  {
3392  int32_t casted1=*((int32_t*)data1);
3393  int32_t casted2=*((int32_t*)data2);
3394 
3395  if (CMath::abs(casted1-casted2)>accuracy)
3396  {
3397  SG_SINFO("leaving TParameter::compare_ptype(): PT_INT32: "
3398  "data1=%d, data2=%d\n", casted1, casted2);
3399  return false;
3400  }
3401  break;
3402  }
3403  case PT_UINT32:
3404  {
3405  uint32_t casted1=*((uint32_t*)data1);
3406  uint32_t casted2=*((uint32_t*)data2);
3407 
3408  if (CMath::abs(casted1-casted2)>accuracy)
3409  {
3410  SG_SINFO("leaving TParameter::compare_ptype(): PT_UINT32: "
3411  "data1=%d, data2=%d\n", casted1, casted2);
3412  return false;
3413  }
3414  break;
3415  }
3416  case PT_INT64:
3417  {
3418  int64_t casted1=*((int64_t*)data1);
3419  int64_t casted2=*((int64_t*)data2);
3420 
3421  if (CMath::abs(casted1-casted2)>accuracy)
3422  {
3423  SG_SINFO("leaving TParameter::compare_ptype(): PT_INT64: "
3424  "data1=%d, data2=%d\n", casted1, casted2);
3425  return false;
3426  }
3427  break;
3428  }
3429  case PT_UINT64:
3430  {
3431  uint64_t casted1=*((uint64_t*)data1);
3432  uint64_t casted2=*((uint64_t*)data2);
3433 
3434  if (CMath::abs(casted1-casted2)>accuracy)
3435  {
3436  SG_SINFO("leaving TParameter::compare_ptype(): PT_UINT64: "
3437  "data1=%d, data2=%d\n", casted1, casted2);
3438  return false;
3439  }
3440  break;
3441  }
3442  case PT_FLOAT32:
3443  {
3444  float32_t casted1=*((float32_t*)data1);
3445  float32_t casted2=*((float32_t*)data2);
3446 
3447  SG_SINFO("leaving TParameter::compare_ptype(): PT_FLOAT32: "
3448  "data1=%f, data2=%f\n", casted1, casted2);
3449 
3450  return CMath::fequals<float32_t>(casted1, casted2, accuracy, tolerant);
3451  break;
3452  }
3453  case PT_FLOAT64:
3454  {
3455  float64_t casted1=*((float64_t*)data1);
3456  float64_t casted2=*((float64_t*)data2);
3457 
3458  SG_SINFO("leaving TParameter::compare_ptype(): PT_FLOAT64: "
3459  "data1=%f, data2=%f\n", casted1, casted2);
3460 
3461  return CMath::fequals<float64_t>(casted1, casted2, accuracy, tolerant);
3462  break;
3463  }
3464  case PT_FLOATMAX:
3465  {
3466  floatmax_t casted1=*((floatmax_t*)data1);
3467  floatmax_t casted2=*((floatmax_t*)data2);
3468 
3469  SG_SINFO("leaving TParameter::compare_ptype(): PT_FLOATMAX: "
3470  "data1=%f, data2=%f\n", casted1, casted2);
3471 
3472  return CMath::fequals<floatmax_t>(casted1, casted2, accuracy, tolerant);
3473  break;
3474  }
3475  case PT_COMPLEX128:
3476  {
3477  float64_t casted1_real=((complex128_t*)data1)->real();
3478  float64_t casted1_imag=((complex128_t*)data1)->imag();
3479  float64_t casted2_real=((complex128_t*)data2)->real();
3480  float64_t casted2_imag=((complex128_t*)data2)->imag();
3481  if (CMath::abs(casted1_real-casted2_real)>accuracy ||
3482  CMath::abs(casted1_imag-casted2_imag)>accuracy)
3483  {
3484  SG_SINFO("leaving TParameter::compare_ptype(): PT_COMPLEX128: "
3485  "data1=%f+i%f, data2=%f+i%f\n",
3486  casted1_real, casted1_imag,
3487  casted2_real, casted2_imag);
3488  return false;
3489  }
3490  break;
3491  }
3492  case PT_SGOBJECT:
3493  {
3494  CSGObject* casted1=*((CSGObject**)data1);
3495  CSGObject* casted2=*((CSGObject**)data2);
3496 
3497  /* important not to call methods on NULL */
3498  if (!casted1 && ! casted2)
3499  {
3500  SG_SDEBUG("leaving TParameter::compare_ptype(): SGObjects are equal\n");
3501  return true;
3502  }
3503 
3504  /* make sure to not call NULL methods */
3505  if (casted1)
3506  {
3507  if (!(casted1->equals(casted2, accuracy)))
3508  {
3509  SG_SINFO("leaving TParameter::compare_ptype(): PT_SGOBJECT "
3510  "equals returned false\n");
3511  return false;
3512  }
3513  }
3514  else
3515  {
3516  if (!(casted2->equals(casted1, accuracy)))
3517  {
3518  SG_SINFO("leaving TParameter::compare_ptype(): PT_SGOBJECT "
3519  "equals returned false\n");
3520  return false;
3521  }
3522 
3523  }
3524  break;
3525  }
3526  default:
3527  SG_SERROR("TParameter::compare_ptype(): Encountered unknown primitive"
3528  "-type: %d\n", ptype);
3529  break;
3530  }
3531 
3532  SG_SDEBUG("leaving TParameter::compare_ptype(): Data are equal\n");
3533  return true;
3534 }
3535 
3536 bool TParameter::copy_ptype(EPrimitiveType ptype, void* source, void* target)
3537 {
3538  SG_SDEBUG("entering TParameter::copy_ptype()\n");
3539 
3540  /* rather than using memcpy, use the cumbersome way here and cast all types.
3541  * This makes it so much easier to debug code.
3542  * Copy full stype if this is too slow */
3543  switch (ptype)
3544  {
3545  case PT_BOOL:
3546  {
3547  *((bool*)target)=*((bool*)source);
3548  SG_SDEBUG("after copy of ptype PT_BOOL: source %d, target %d\n",
3549  *((bool*)source), *((bool*)target));
3550  break;
3551  }
3552  case PT_CHAR:
3553  {
3554  *((char*)target)=*((char*)source);
3555  SG_SDEBUG("after copy of ptype PT_CHAR: source %c, target %c\n",
3556  *((char*)source), *((char*)target));
3557  break;
3558  }
3559  case PT_INT8:
3560  {
3561  *((int8_t*)target)=*((int8_t*)source);
3562  SG_SDEBUG("after copy of ptype PT_INT8: source %d, target %d\n",
3563  *((int8_t*)source), *((int8_t*)target));
3564  break;
3565  }
3566  case PT_UINT8:
3567  {
3568  *((uint8_t*)target)=*((uint8_t*)source);
3569  SG_SDEBUG("after copy of ptype PT_UINT8: source %d, target %d\n",
3570  *((uint8_t*)source), *((uint8_t*)target));
3571  break;
3572  }
3573  case PT_INT16:
3574  {
3575  *((int16_t*)target)=*((int16_t*)source);
3576  SG_SDEBUG("after copy of ptype PT_INT16: source %d, target %d\n",
3577  *((int16_t*)source), *((int16_t*)target));
3578  break;
3579  }
3580  case PT_UINT16:
3581  {
3582  *((uint16_t*)target)=*((uint16_t*)source);
3583  SG_SDEBUG("after copy of ptype PT_UINT16: source %d, target %d\n",
3584  *((uint16_t*)source), *((uint16_t*)target));
3585  break;
3586  }
3587  case PT_INT32:
3588  {
3589  *((int32_t*)target)=*((int32_t*)source);
3590  SG_SDEBUG("after copy of ptype PT_INT32: source %d, target %d\n",
3591  *((int32_t*)source), *((int32_t*)target));
3592  break;
3593  }
3594  case PT_UINT32:
3595  {
3596  *((uint32_t*)target)=*((uint32_t*)source);
3597  SG_SDEBUG("after copy of ptype PT_UINT32: source %d, target %d\n",
3598  *((uint32_t*)source), *((uint32_t*)target));
3599  break;
3600  }
3601  case PT_INT64:
3602  {
3603  *((int64_t*)target)=*((int64_t*)source);
3604  SG_SDEBUG("after copy of ptype PT_INT64: source %d, target %d\n",
3605  *((int64_t*)source), *((int64_t*)target));
3606  break;
3607  }
3608  case PT_UINT64:
3609  {
3610  *((uint64_t*)target)=*((uint64_t*)source);
3611  SG_SDEBUG("after copy of ptype PT_UINT64: source %d, target %d\n",
3612  *((uint64_t*)source), *((uint64_t*)target));
3613  break;
3614  }
3615  case PT_FLOAT32:
3616  {
3617  *((float32_t*)target)=*((float32_t*)source);
3618  SG_SDEBUG("after copy of ptype PT_FLOAT32: source %f, target %f\n",
3619  *((float32_t*)source), *((float32_t*)target));
3620  break;
3621  }
3622  case PT_FLOAT64:
3623  {
3624  *((float64_t*)target)=*((float64_t*)source);
3625  SG_SDEBUG("after copy of ptype PT_FLOAT64: source %f, target %f\n",
3626  *((float64_t*)source), *((float64_t*)target));
3627  break;
3628  }
3629  case PT_FLOATMAX:
3630  {
3631  *((floatmax_t*)target)=*((floatmax_t*)source);
3632  SG_SDEBUG("after copy of ptype PT_FLOATMAX: source %Lf, target %Lf\n",
3633  *((floatmax_t*)source), *((floatmax_t*)target));
3634  break;
3635  }
3636  case PT_COMPLEX128:
3637  {
3638  *((complex128_t*)target)=*((complex128_t*)source);
3639  SG_SDEBUG("after copy of ptype PT_COMPLEX128: "
3640  "source real %f, target real %f,"
3641  "source imag %f, target imag %f,"
3642  "\n",
3643  ((complex128_t*)source)->real(), ((complex128_t*)target)->real(),
3644  ((complex128_t*)source)->imag(), ((complex128_t*)target)->imag());
3645  break;
3646  }
3647  case PT_SGOBJECT:
3648  {
3649  CSGObject* casted1=*((CSGObject**)source);
3650  CSGObject* casted2=*((CSGObject**)target);
3651 
3652  /* important not to call methods on NULL */
3653  if (!casted1 && ! casted2)
3654  {
3655  SG_SDEBUG("leaving TParameter::copy_ptype(): Both SGObjects are NULL\n");
3656  return true;
3657  }
3658 
3659  /* make sure to not call NULL methods */
3660  if (casted1)
3661  {
3662  /* in case of overwriting old objects */
3663  SG_UNREF(*((CSGObject**)target));
3664  *((CSGObject**)target) = casted1->clone();
3665  }
3666 
3667  break;
3668  }
3669  default:
3670  SG_SERROR("TParameter::compare_ptype(): Encountered unknown primitive"
3671  "-type: %d\n", ptype);
3672  return false;
3673  break;
3674  }
3675 
3676  SG_SDEBUG("leaving TParameter::copy_ptype(): Copy successful\n");
3677  return true;
3678 }
3679 
3680 bool TParameter::compare_stype(EStructType stype, EPrimitiveType ptype,
3681  void* data1, void* data2, float64_t accuracy, bool tolerant)
3682 {
3683  SG_SDEBUG("entering TParameter::compare_stype()\n");
3684 
3685  size_t size_ptype=TSGDataType::sizeof_ptype(ptype);
3686 
3687  /* Avoid comparing NULL */
3688  if (!data1 && !data2)
3689  {
3690  SG_SDEBUG("leaving TParameter::compare_stype(): both data are NULL\n");
3691  return true;
3692  }
3693 
3694  /* If one is NULL, data are not equal */
3695  if ((data1 && !data2) || (!data1 && data2))
3696  {
3697  SG_SINFO("leaving TParameter::compare_stype(): data1 is at %p while "
3698  "data2 is at %p\n", data1, data2);
3699  return false;
3700  }
3701 
3702  switch (stype)
3703  {
3704  case ST_NONE:
3705  {
3706  SG_SDEBUG("ST_NONE\n");
3707  return TParameter::compare_ptype(ptype, data1, data2, accuracy, tolerant);
3708  break;
3709  }
3710  case ST_SPARSE:
3711  {
3712  SG_SDEBUG("ST_SPARSE\n");
3713  SGSparseVector<char>* spr_ptr1 = (SGSparseVector<char>*) data1;
3714  SGSparseVector<char>* spr_ptr2 = (SGSparseVector<char>*) data2;
3715 
3716  if (spr_ptr1->num_feat_entries != spr_ptr2->num_feat_entries)
3717  {
3718  SG_SINFO("leaving TParameter::compare_stype(): Length of "
3719  "sparse vector1 (%d) is different of vector 2 (%d)\n",
3720  spr_ptr1->num_feat_entries, spr_ptr2->num_feat_entries);
3721  return false;
3722  }
3723 
3724  SG_SDEBUG("Comparing sparse vectors\n");
3725  for (index_t i=0; i<spr_ptr1->num_feat_entries; ++i)
3726  {
3727  SG_SDEBUG("Comparing sparse entry %d at offset %d\n", i,
3729 
3731  ((char*) spr_ptr1->features + i*TSGDataType
3732  ::sizeof_sparseentry(ptype));
3734  ((char*) spr_ptr2->features + i*TSGDataType
3735  ::sizeof_sparseentry(ptype));
3736 
3737  /* sparse entries have an offset of the enty pointer depending
3738  * on type. Since I cast everything down to char, I need to remove
3739  * the char offset and add the offset of the ptype */
3740  index_t char_offset=TSGDataType::offset_sparseentry(PT_CHAR);
3741  index_t ptype_offset=TSGDataType::offset_sparseentry(ptype);
3742  void* pointer1=&(cur1->entry)-char_offset+ptype_offset;
3743  void* pointer2=&(cur2->entry)-char_offset+ptype_offset;
3744 
3745  if (!TParameter::compare_ptype(ptype, pointer1,
3746  pointer2, accuracy, tolerant))
3747  {
3748  SG_SINFO("leaving TParameter::compare_stype(): Data of"
3749  " sparse vector element is different\n");
3750  return false;
3751  }
3752 
3753  /* also compare feature indices */
3754  if (cur2->feat_index!=cur1->feat_index)
3755  {
3756  SG_SINFO("leaving TParameter::compare_stype(): Feature "
3757  "index of sparse vector element is different. "
3758  "source: %d, target: %d\n",
3759  cur1->feat_index, cur2->feat_index);
3760  return false;
3761  }
3762  }
3763  break;
3764  }
3765  case ST_STRING:
3766  {
3767  SG_SDEBUG("ST_STRING\n");
3768  SGString<char>* str_ptr1 = (SGString<char>*) data1;
3769  SGString<char>* str_ptr2 = (SGString<char>*) data2;
3770 
3771  if (str_ptr1->slen != str_ptr2->slen)
3772  {
3773  SG_SINFO("leaving TParameter::compare_stype(): Length of "
3774  "string1 (%d) is different of string2 (%d)\n",
3775  str_ptr1->slen, str_ptr2->slen);
3776  return false;
3777  }
3778 
3779  SG_SDEBUG("Comparing strings\n");
3780  for (index_t i=0; i<str_ptr1->slen; ++i)
3781  {
3782  SG_SDEBUG("Comparing string element %d at offset %d\n", i,
3783  i*size_ptype);
3784  void* pointer1=str_ptr1->string+i*size_ptype;
3785  void* pointer2=str_ptr2->string+i*size_ptype;
3786 
3787  if (!TParameter::compare_ptype(ptype, pointer1,
3788  pointer2, accuracy, tolerant))
3789  {
3790  SG_SINFO("leaving TParameter::compare_stype(): Data of"
3791  " string element is different\n");
3792  return false;
3793  }
3794  }
3795  break;
3796  }
3797  default:
3798  {
3799  SG_SERROR("TParameter::compare_stype(): Undefined struct type\n");
3800  break;
3801  }
3802  }
3803 
3804  SG_SDEBUG("leaving TParameter::compare_stype(): Data were equal\n");
3805  return true;
3806 }
3807 
3808 bool TParameter::copy_stype(EStructType stype, EPrimitiveType ptype,
3809  void* source, void* target)
3810 {
3811  SG_SDEBUG("entering TParameter::copy_stype()\n");
3812  size_t size_ptype=TSGDataType::sizeof_ptype(ptype);
3813 
3814  /* Heiko Strathmann: While I know that copying the stypes string and sparse
3815  * element wise is slower than doing the full things, it is way easier to
3816  * program and to debug since I already made sure that copy_ptype works as
3817  * intended. In addition, strings and vectors of SGObjects can be treated
3818  * recursively this way (we dont have cases for this currently, June 2013,
3819  * but they can be added without having to modify this code)
3820  *
3821  * Therefore, this code is very close to the the equals code for
3822  * stypes. If it turns out to be too slow (which I doubt), stypes can be
3823  * copied with memcpy over the full memory blocks */
3824 
3825  switch (stype)
3826  {
3827  case ST_NONE:
3828  {
3829  SG_SDEBUG("ST_NONE\n");
3830  return TParameter::copy_ptype(ptype, source, target);
3831  break;
3832  }
3833  case ST_STRING:
3834  {
3835  SG_SDEBUG("ST_STRING\n");
3836  SGString<char>* source_ptr = (SGString<char>*) source;
3837  SGString<char>* target_ptr = (SGString<char>*) target;
3838 
3839  if (source_ptr->slen != target_ptr->slen)
3840  {
3841  SG_SDEBUG("string lengths different (source: %d vs target: %d),"
3842  " freeing memory.\n", source_ptr->slen, target_ptr->slen);
3843 
3844  /* if string have different lengths, free data and make equal */
3845  SG_FREE(target_ptr->string);
3846  target_ptr->string=NULL;
3847  target_ptr->slen=0;
3848  }
3849 
3850  if (!target_ptr->string)
3851  {
3852  /* allocate memory if data is NULL */
3853  size_t num_bytes=source_ptr->slen * size_ptype;
3854 
3855  SG_SDEBUG("target string data NULL, allocating %d bytes.\n",
3856  num_bytes);
3857  target_ptr->string=SG_MALLOC(char, num_bytes);
3858  target_ptr->slen=source_ptr->slen;
3859  }
3860 
3861  SG_SDEBUG("Copying strings\n");
3862  for (index_t i=0; i<source_ptr->slen; ++i)
3863  {
3864  SG_SDEBUG("Copying string element %d at offset %d\n", i,
3865  i*size_ptype);
3866  void* pointer1=source_ptr->string+i*size_ptype;
3867  void* pointer2=target_ptr->string+i*size_ptype;
3868 
3869  if (!TParameter::copy_ptype(ptype, pointer1, pointer2))
3870  {
3871  SG_SDEBUG("leaving TParameter::copy_stype(): Copy of string"
3872  " element failed.\n");
3873  return false;
3874  }
3875  }
3876  break;
3877  }
3878  case ST_SPARSE:
3879  {
3880  SG_SDEBUG("ST_SPARSE\n");
3881  SGSparseVector<char>* source_ptr = (SGSparseVector<char>*) source;
3882  SGSparseVector<char>* target_ptr = (SGSparseVector<char>*) target;
3883 
3884  if (source_ptr->num_feat_entries != target_ptr->num_feat_entries)
3885  {
3886  SG_SDEBUG("sparse vector lengths different (source: %d vs target: %d),"
3887  " freeing memory.\n",
3888  source_ptr->num_feat_entries, target_ptr->num_feat_entries);
3889 
3890  /* if string have different lengths, free data and make equal */
3891  SG_FREE(target_ptr->features);
3892  target_ptr->features=NULL;
3893  target_ptr->num_feat_entries=0;
3894  }
3895 
3896  if (!target_ptr->features)
3897  {
3898  /* allocate memory if data is NULL */
3899  size_t num_bytes=source_ptr->num_feat_entries *
3901 
3902  SG_SDEBUG("target sparse data NULL, allocating %d bytes.\n",
3903  num_bytes);
3904  target_ptr->features=(SGSparseVectorEntry<char>*)SG_MALLOC(char, num_bytes);
3905  target_ptr->num_feat_entries=source_ptr->num_feat_entries;
3906  }
3907 
3908  SG_SDEBUG("Copying sparse vectors\n");
3909  for (index_t i=0; i<source_ptr->num_feat_entries; ++i)
3910  {
3911  SG_SDEBUG("Copying sparse entry %d at offset %d\n", i,
3913 
3915  ((char*) source_ptr->features + i*TSGDataType
3916  ::sizeof_sparseentry(ptype));
3918  ((char*) target_ptr->features + i*TSGDataType
3919  ::sizeof_sparseentry(ptype));
3920 
3921  /* sparse entries have an offset of the enty pointer depending
3922  * on type. Since I cast everything down to char, I need to remove
3923  * the char offset and add the offset of the ptype */
3924  index_t char_offset=TSGDataType::offset_sparseentry(PT_CHAR);
3925  index_t ptype_offset=TSGDataType::offset_sparseentry(ptype);
3926  void* pointer1=&(cur1->entry)-char_offset+ptype_offset;
3927  void* pointer2=&(cur2->entry)-char_offset+ptype_offset;
3928 
3929  if (!TParameter::copy_ptype(ptype, pointer1, pointer2))
3930  {
3931  SG_SDEBUG("leaving TParameter::copy_stype(): Copy of sparse"
3932  " vector element failed\n");
3933  return false;
3934  }
3935 
3936  /* afterwards, copy feature indices, wich are the data before
3937  * the avove offeet */
3938  cur2->feat_index=cur1->feat_index;
3939  }
3940  break;
3941  }
3942  default:
3943  {
3944  SG_SERROR("TParameter::copy_stype(): Undefined struct type\n");
3945  return false;
3946  break;
3947  }
3948  }
3949 
3950  SG_SDEBUG("leaving TParameter::copy_stype(): Copy successful\n");
3951  return true;
3952 }
3953 
3955 {
3956  SG_SDEBUG("entering TParameter::copy()\n");
3957 
3958  if (!target)
3959  {
3960  SG_SDEBUG("leaving TParameter::copy(): other parameter is NULL\n");
3961  return false;
3962  }
3963 
3964  if (!m_parameter)
3965  {
3966  SG_SDEBUG("leaving TParameter::copy(): m_parameter of source is NULL\n");
3967  return false;
3968  }
3969 
3970  if (!target->m_parameter)
3971  {
3972  SG_SDEBUG("leaving TParameter::copy(): m_parameter of target is NULL\n");
3973  return false;
3974  }
3975 
3976  if (strcmp(m_name, target->m_name))
3977  {
3978  SG_SDEBUG("leaving TParameter::copy(): name \"%s\" is different from"
3979  " target parameter's "
3980  "name \"%s\"\n", m_name, target->m_name);
3981  return false;
3982  }
3983 
3984  SG_SDEBUG("Comparing datatypes without length\n");
3986  {
3987  SG_SDEBUG("leaving TParameter::copy(): type of \"%s\" is different "
3988  "from target parameter's \"%s\" type\n", m_name, target->m_name);
3989  return false;
3990  }
3991 
3992  switch (m_datatype.m_ctype)
3993  {
3994  case CT_SCALAR:
3995  {
3996  SG_SDEBUG("CT_SCALAR\n");
3999  target->m_parameter))
4000  {
4001  SG_SDEBUG("leaving TParameter::copy(): scalar data copy error\n");
4002  return false;
4003  }
4004  break;
4005  }
4006  case CT_VECTOR: case CT_SGVECTOR:
4007  {
4008  SG_SDEBUG("CT_VECTOR or CT_SGVECTOR\n");
4009 
4010  /* if sizes are different or memory is not allocated, do that */
4011  if (!m_datatype.equals(target->m_datatype))
4012  {
4013  SG_SDEBUG("changing size of target vector and freeing memory\n");
4014  /* first case: different sizes, free target memory */
4015  SG_FREE(*(char**)target->m_parameter);
4016  *(char**)target->m_parameter=NULL;
4017 
4018  }
4019 
4020  /* check whether target m_parameter data contains NULL, if yes
4021  * create if the length is non-zero */
4022  if (*(char**)target->m_parameter==NULL && *m_datatype.m_length_y>0)
4023  {
4024  size_t num_bytes=*m_datatype.m_length_y * m_datatype.sizeof_stype();
4025  SG_SDEBUG("allocating %d bytes memory for target vector\n", num_bytes);
4026 
4027  *(char**)target->m_parameter=SG_MALLOC(char, num_bytes);
4028  /* check whether ptype is SGOBJECT, if yes we need to initialize
4029  the memory with NULL for the way copy_ptype handles it */
4030  if (m_datatype.m_ptype==PT_SGOBJECT)
4031  memset(*(void**)target->m_parameter, 0, num_bytes);
4032 
4033  /* use length of source */
4035  }
4036 
4037  /* now start actual copying, assume that sizes are equal and memory
4038  * is there */
4039  ASSERT(m_datatype.equals(target->m_datatype));
4040 
4041  /* x is number of processed bytes */
4042  index_t x=0;
4043  SG_SDEBUG("length_y: %d\n", *m_datatype.m_length_y)
4044  for (index_t i=0; i<*m_datatype.m_length_y; ++i)
4045  {
4046  SG_SDEBUG("copying element %d which is %d byes from start\n",
4047  i, x);
4048 
4049  void* pointer_a=&((*(char**)m_parameter)[x]);
4050  void* pointer_b=&((*(char**)target->m_parameter)[x]);
4051 
4053  m_datatype.m_ptype, pointer_a, pointer_b))
4054  {
4055  SG_SDEBUG("leaving TParameter::copy(): vector element "
4056  "copy error\n");
4057  return false;
4058  }
4059 
4060  x=x+(m_datatype.sizeof_ptype());
4061  }
4062 
4063  break;
4064  }
4065  case CT_MATRIX: case CT_SGMATRIX:
4066  {
4067  SG_SDEBUG("CT_MATRIX or CT_SGMATRIX\n");
4068 
4069  /* if sizes are different or memory is not allocated, do that */
4070  if (!m_datatype.equals(target->m_datatype))
4071  {
4072  SG_SDEBUG("changing size of target vector and freeing memory\n");
4073  /* first case: different sizes, free target memory */
4074  SG_FREE(*(char**)target->m_parameter);
4075  *(char**)target->m_parameter=NULL;
4076  }
4077 
4078  /* check whether target m_parameter data contains NULL, if yes, create */
4079  if (*(char**)target->m_parameter==NULL)
4080  {
4081  SG_SDEBUG("allocating memory for target vector\n");
4082  size_t num_bytes=0;
4083  /* for ST_SPARSE allocate only for a vector of m_length_y */
4084  if (m_datatype.m_stype==ST_SPARSE)
4086  else
4087  num_bytes=*m_datatype.m_length_y *
4089 
4090  *(char**)target->m_parameter=SG_MALLOC(char, num_bytes);
4091 
4092  /* check whether ptype is SGOBJECT, if yes we need to initialize
4093  the memory with NULL for the way copy_ptype handles it */
4094  if (m_datatype.m_ptype==PT_SGOBJECT)
4095  memset(*(void**)target->m_parameter, 0, num_bytes);
4096 
4097  /* use length of source */
4100 
4101  SG_SDEBUG("%d bytes are allocated\n", num_bytes);
4102  }
4103 
4104  /* now start actual copying, assume that sizes are equal and memory
4105  * is there */
4106  ASSERT(m_datatype.equals(target->m_datatype));
4107 
4108  /* x is number of processed bytes */
4109  index_t x=0;
4110  SG_SDEBUG("length_y: %d\n", *m_datatype.m_length_y)
4111  SG_SDEBUG("length_x: %d\n", *m_datatype.m_length_x)
4112  int64_t length=0;
4113  /* for ST_SPARSE allocate iterate over a vector of m_length_y */
4114  if (m_datatype.m_stype==ST_SPARSE)
4115  length=(*m_datatype.m_length_y);
4116  else
4117  length=(*m_datatype.m_length_y) * (*m_datatype.m_length_x);
4118  for (index_t i=0; i<length; ++i)
4119  {
4120  SG_SDEBUG("copying element %d which is %d byes from start\n",
4121  i, x);
4122 
4123  void* pointer_a=&((*(char**)m_parameter)[x]);
4124  void* pointer_b=&((*(char**)target->m_parameter)[x]);
4125 
4127  m_datatype.m_ptype, pointer_a, pointer_b))
4128  {
4129  SG_SDEBUG("leaving TParameter::copy(): vector element "
4130  "differs\n");
4131  return false;
4132  }
4133 
4134  /* For ST_SPARSE, the iteration is on the pointer of SGSparseVectors */
4135  if (m_datatype.m_stype==ST_SPARSE)
4136  x=x+(m_datatype.sizeof_stype());
4137  else
4138  x=x+(m_datatype.sizeof_ptype());
4139  }
4140 
4141  break;
4142  }
4143  case CT_NDARRAY:
4144  {
4145  SG_SDEBUG("CT_NDARRAY\n");
4146  SG_SERROR("TParameter::copy(): Not yet implemented for "
4147  "CT_NDARRAY!\n");
4148  break;
4149  }
4150  case CT_UNDEFINED: default:
4151  SG_SERROR("Implementation error: undefined container type\n");
4152  break;
4153  }
4154 
4155  SG_SDEBUG("leaving TParameter::copy(): Copy successful\n");
4156  return true;
4157 }

SHOGUN Machine Learning Toolbox - Documentation