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

SHOGUN Machine Learning Toolbox - Documentation