SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Parameter.cpp
Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 2010 Soeren Sonnenburg
00008  * Written (W) 2011-2013 Heiko Strathmann
00009  * Copyright (C) 2010 Berlin Institute of Technology
00010  */
00011 
00012 #include <string.h>
00013 
00014 #include <shogun/base/Parameter.h>
00015 #include <shogun/base/class_list.h>
00016 #include <shogun/lib/Hash.h>
00017 #include <shogun/lib/memory.h>
00018 #include <shogun/io/SGIO.h>
00019 
00020 using namespace shogun;
00021 
00022 
00023 /* **************************************************************** */
00024 /* Scalar wrappers  */
00025 
00026 void
00027 Parameter::add(bool* param, const char* name,
00028                const char* description) {
00029     TSGDataType type(CT_SCALAR, ST_NONE, PT_BOOL);
00030     add_type(&type, param, name, description);
00031 }
00032 
00033 void
00034 Parameter::add(char* param, const char* name,
00035                const char* description) {
00036     TSGDataType type(CT_SCALAR, ST_NONE, PT_CHAR);
00037     add_type(&type, param, name, description);
00038 }
00039 
00040 void
00041 Parameter::add(int8_t* param, const char* name,
00042                const char* description) {
00043     TSGDataType type(CT_SCALAR, ST_NONE, PT_INT8);
00044     add_type(&type, param, name, description);
00045 }
00046 
00047 void
00048 Parameter::add(uint8_t* param, const char* name,
00049                const char* description) {
00050     TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT8);
00051     add_type(&type, param, name, description);
00052 }
00053 
00054 void
00055 Parameter::add(int16_t* param, const char* name,
00056                const char* description) {
00057     TSGDataType type(CT_SCALAR, ST_NONE, PT_INT16);
00058     add_type(&type, param, name, description);
00059 }
00060 
00061 void
00062 Parameter::add(uint16_t* param, const char* name,
00063                const char* description) {
00064     TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT16);
00065     add_type(&type, param, name, description);
00066 }
00067 
00068 void
00069 Parameter::add(int32_t* param, const char* name,
00070                const char* description) {
00071     TSGDataType type(CT_SCALAR, ST_NONE, PT_INT32);
00072     add_type(&type, param, name, description);
00073 }
00074 
00075 void
00076 Parameter::add(uint32_t* param, const char* name,
00077                const char* description) {
00078     TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT32);
00079     add_type(&type, param, name, description);
00080 }
00081 
00082 void
00083 Parameter::add(int64_t* param, const char* name,
00084                const char* description) {
00085     TSGDataType type(CT_SCALAR, ST_NONE, PT_INT64);
00086     add_type(&type, param, name, description);
00087 }
00088 
00089 void
00090 Parameter::add(uint64_t* param, const char* name,
00091                const char* description) {
00092     TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT64);
00093     add_type(&type, param, name, description);
00094 }
00095 
00096 void
00097 Parameter::add(float32_t* param, const char* name,
00098                const char* description) {
00099     TSGDataType type(CT_SCALAR, ST_NONE, PT_FLOAT32);
00100     add_type(&type, param, name, description);
00101 }
00102 
00103 void
00104 Parameter::add(float64_t* param, const char* name,
00105                const char* description) {
00106     TSGDataType type(CT_SCALAR, ST_NONE, PT_FLOAT64);
00107     add_type(&type, param, name, description);
00108 }
00109 
00110 void
00111 Parameter::add(floatmax_t* param, const char* name,
00112                const char* description) {
00113     TSGDataType type(CT_SCALAR, ST_NONE, PT_FLOATMAX);
00114     add_type(&type, param, name, description);
00115 }
00116 
00117 void
00118 Parameter::add(complex128_t* param, const char* name,
00119                const char* description) {
00120     TSGDataType type(CT_SCALAR, ST_NONE, PT_COMPLEX128);
00121     add_type(&type, param, name, description);
00122 }
00123 
00124 void
00125 Parameter::add(CSGObject** param,
00126                const char* name, const char* description) {
00127     TSGDataType type(CT_SCALAR, ST_NONE, PT_SGOBJECT);
00128     add_type(&type, param, name, description);
00129 }
00130 
00131 void
00132 Parameter::add(SGString<bool>* param, const char* name,
00133                const char* description) {
00134     TSGDataType type(CT_SCALAR, ST_STRING, PT_BOOL);
00135     add_type(&type, param, name, description);
00136 }
00137 
00138 void
00139 Parameter::add(SGString<char>* param, const char* name,
00140                const char* description) {
00141     TSGDataType type(CT_SCALAR, ST_STRING, PT_CHAR);
00142     add_type(&type, param, name, description);
00143 }
00144 
00145 void
00146 Parameter::add(SGString<int8_t>* param, const char* name,
00147                const char* description) {
00148     TSGDataType type(CT_SCALAR, ST_STRING, PT_INT8);
00149     add_type(&type, param, name, description);
00150 }
00151 
00152 void
00153 Parameter::add(SGString<uint8_t>* param, const char* name,
00154                const char* description) {
00155     TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT8);
00156     add_type(&type, param, name, description);
00157 }
00158 
00159 void
00160 Parameter::add(SGString<int16_t>* param, const char* name,
00161                const char* description) {
00162     TSGDataType type(CT_SCALAR, ST_STRING, PT_INT16);
00163     add_type(&type, param, name, description);
00164 }
00165 
00166 void
00167 Parameter::add(SGString<uint16_t>* param, const char* name,
00168                const char* description) {
00169     TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT16);
00170     add_type(&type, param, name, description);
00171 }
00172 
00173 void
00174 Parameter::add(SGString<int32_t>* param, const char* name,
00175                const char* description) {
00176     TSGDataType type(CT_SCALAR, ST_STRING, PT_INT32);
00177     add_type(&type, param, name, description);
00178 }
00179 
00180 void
00181 Parameter::add(SGString<uint32_t>* param, const char* name,
00182                const char* description) {
00183     TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT32);
00184     add_type(&type, param, name, description);
00185 }
00186 
00187 void
00188 Parameter::add(SGString<int64_t>* param, const char* name,
00189                const char* description) {
00190     TSGDataType type(CT_SCALAR, ST_STRING, PT_INT64);
00191     add_type(&type, param, name, description);
00192 }
00193 
00194 void
00195 Parameter::add(SGString<uint64_t>* param, const char* name,
00196                const char* description) {
00197     TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT64);
00198     add_type(&type, param, name, description);
00199 }
00200 
00201 void
00202 Parameter::add(SGString<float32_t>* param, const char* name,
00203                const char* description) {
00204     TSGDataType type(CT_SCALAR, ST_STRING, PT_FLOAT32);
00205     add_type(&type, param, name, description);
00206 }
00207 
00208 void
00209 Parameter::add(SGString<float64_t>* param, const char* name,
00210                const char* description) {
00211     TSGDataType type(CT_SCALAR, ST_STRING, PT_FLOAT64);
00212     add_type(&type, param, name, description);
00213 }
00214 
00215 void
00216 Parameter::add(SGString<floatmax_t>* param, const char* name,
00217                const char* description) {
00218     TSGDataType type(CT_SCALAR, ST_STRING, PT_FLOATMAX);
00219     add_type(&type, param, name, description);
00220 }
00221 
00222 void
00223 Parameter::add(SGSparseVector<bool>* param, const char* name,
00224                const char* description) {
00225     TSGDataType type(CT_SCALAR, ST_SPARSE, PT_BOOL);
00226     add_type(&type, param, name, description);
00227 }
00228 
00229 void
00230 Parameter::add(SGSparseVector<char>* param, const char* name,
00231                const char* description) {
00232     TSGDataType type(CT_SCALAR, ST_SPARSE, PT_CHAR);
00233     add_type(&type, param, name, description);
00234 }
00235 
00236 void
00237 Parameter::add(SGSparseVector<int8_t>* param, const char* name,
00238                const char* description) {
00239     TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT8);
00240     add_type(&type, param, name, description);
00241 }
00242 
00243 void
00244 Parameter::add(SGSparseVector<uint8_t>* param, const char* name,
00245                const char* description) {
00246     TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT8);
00247     add_type(&type, param, name, description);
00248 }
00249 
00250 void
00251 Parameter::add(SGSparseVector<int16_t>* param, const char* name,
00252                const char* description) {
00253     TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT16);
00254     add_type(&type, param, name, description);
00255 }
00256 
00257 void
00258 Parameter::add(SGSparseVector<uint16_t>* param, const char* name,
00259                const char* description) {
00260     TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT16);
00261     add_type(&type, param, name, description);
00262 }
00263 
00264 void
00265 Parameter::add(SGSparseVector<int32_t>* param, const char* name,
00266                const char* description) {
00267     TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT32);
00268     add_type(&type, param, name, description);
00269 }
00270 
00271 void
00272 Parameter::add(SGSparseVector<uint32_t>* param, const char* name,
00273                const char* description) {
00274     TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT32);
00275     add_type(&type, param, name, description);
00276 }
00277 
00278 void
00279 Parameter::add(SGSparseVector<int64_t>* param, const char* name,
00280                const char* description) {
00281     TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT64);
00282     add_type(&type, param, name, description);
00283 }
00284 
00285 void
00286 Parameter::add(SGSparseVector<uint64_t>* param, const char* name,
00287                const char* description) {
00288     TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT64);
00289     add_type(&type, param, name, description);
00290 }
00291 
00292 void
00293 Parameter::add(SGSparseVector<float32_t>* param, const char* name,
00294                const char* description) {
00295     TSGDataType type(CT_SCALAR, ST_SPARSE, PT_FLOAT32);
00296     add_type(&type, param, name, description);
00297 }
00298 
00299 void
00300 Parameter::add(SGSparseVector<float64_t>* param, const char* name,
00301                const char* description) {
00302     TSGDataType type(CT_SCALAR, ST_SPARSE, PT_FLOAT64);
00303     add_type(&type, param, name, description);
00304 }
00305 
00306 void
00307 Parameter::add(SGSparseVector<floatmax_t>* param, const char* name,
00308                const char* description) {
00309     TSGDataType type(CT_SCALAR, ST_SPARSE, PT_FLOATMAX);
00310     add_type(&type, param, name, description);
00311 }
00312 
00313 void
00314 Parameter::add(SGSparseVector<complex128_t>* param, const char* name,
00315                const char* description) {
00316     TSGDataType type(CT_SCALAR, ST_SPARSE, PT_COMPLEX128);
00317     add_type(&type, param, name, description);
00318 }
00319 
00320 /* **************************************************************** */
00321 /* Vector wrappers  */
00322 
00323 void
00324 Parameter::add_vector(
00325     bool** param, index_t* length, const char* name,
00326     const char* description) {
00327     TSGDataType type(CT_VECTOR, ST_NONE, PT_BOOL, length);
00328     add_type(&type, param, name, description);
00329 }
00330 
00331 void
00332 Parameter::add_vector(
00333     char** param, index_t* length, const char* name,
00334     const char* description) {
00335     TSGDataType type(CT_VECTOR, ST_NONE, PT_CHAR, length);
00336     add_type(&type, param, name, description);
00337 }
00338 
00339 void
00340 Parameter::add_vector(
00341     int8_t** param, index_t* length, const char* name,
00342     const char* description) {
00343     TSGDataType type(CT_VECTOR, ST_NONE, PT_INT8, length);
00344     add_type(&type, param, name, description);
00345 }
00346 
00347 void
00348 Parameter::add_vector(
00349     uint8_t** param, index_t* length, const char* name,
00350     const char* description) {
00351     TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT8, length);
00352     add_type(&type, param, name, description);
00353 }
00354 
00355 void
00356 Parameter::add_vector(
00357     int16_t** param, index_t* length, const char* name,
00358     const char* description) {
00359     TSGDataType type(CT_VECTOR, ST_NONE, PT_INT16, length);
00360     add_type(&type, param, name, description);
00361 }
00362 
00363 void
00364 Parameter::add_vector(
00365     uint16_t** param, index_t* length, const char* name,
00366     const char* description) {
00367     TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT16, length);
00368     add_type(&type, param, name, description);
00369 }
00370 
00371 void
00372 Parameter::add_vector(
00373     int32_t** param, index_t* length, const char* name,
00374     const char* description) {
00375     TSGDataType type(CT_VECTOR, ST_NONE, PT_INT32, length);
00376     add_type(&type, param, name, description);
00377 }
00378 
00379 void
00380 Parameter::add_vector(
00381     uint32_t** param, index_t* length, const char* name,
00382     const char* description) {
00383     TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT32, length);
00384     add_type(&type, param, name, description);
00385 }
00386 
00387 void
00388 Parameter::add_vector(
00389     int64_t** param, index_t* length, const char* name,
00390     const char* description) {
00391     TSGDataType type(CT_VECTOR, ST_NONE, PT_INT64, length);
00392     add_type(&type, param, name, description);
00393 }
00394 
00395 void
00396 Parameter::add_vector(
00397     uint64_t** param, index_t* length, const char* name,
00398     const char* description) {
00399     TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT64, length);
00400     add_type(&type, param, name, description);
00401 }
00402 
00403 void
00404 Parameter::add_vector(
00405     float32_t** param, index_t* length, const char* name,
00406     const char* description) {
00407     TSGDataType type(CT_VECTOR, ST_NONE, PT_FLOAT32, length);
00408     add_type(&type, param, name, description);
00409 }
00410 
00411 void
00412 Parameter::add_vector(
00413     float64_t** param, index_t* length, const char* name,
00414     const char* description) {
00415     TSGDataType type(CT_VECTOR, ST_NONE, PT_FLOAT64, length);
00416     add_type(&type, param, name, description);
00417 }
00418 
00419 void
00420 Parameter::add_vector(
00421     floatmax_t** param, index_t* length, const char* name,
00422     const char* description) {
00423     TSGDataType type(CT_VECTOR, ST_NONE, PT_FLOATMAX, length);
00424     add_type(&type, param, name, description);
00425 }
00426 
00427 void
00428 Parameter::add_vector(
00429     complex128_t** param, index_t* length, const char* name,
00430     const char* description) {
00431     TSGDataType type(CT_VECTOR, ST_NONE, PT_COMPLEX128, length);
00432     add_type(&type, param, name, description);
00433 }
00434 
00435 void
00436 Parameter::add_vector(CSGObject*** param, index_t* length,
00437                        const char* name, const char* description) {
00438     TSGDataType type(CT_VECTOR, ST_NONE, PT_SGOBJECT,
00439                      length);
00440     add_type(&type, param, name, description);
00441 }
00442 
00443 void
00444 Parameter::add_vector(SGString<bool>** param, index_t* length,
00445                       const char* name, const char* description) {
00446     TSGDataType type(CT_VECTOR, ST_STRING, PT_BOOL, length);
00447     add_type(&type, param, name, description);
00448 }
00449 
00450 void
00451 Parameter::add_vector(SGString<char>** param, index_t* length,
00452                       const char* name, const char* description) {
00453     TSGDataType type(CT_VECTOR, ST_STRING, PT_CHAR, length);
00454     add_type(&type, param, name, description);
00455 }
00456 
00457 void
00458 Parameter::add_vector(SGString<int8_t>** param, index_t* length,
00459                       const char* name, const char* description) {
00460     TSGDataType type(CT_VECTOR, ST_STRING, PT_INT8, length);
00461     add_type(&type, param, name, description);
00462 }
00463 
00464 void
00465 Parameter::add_vector(SGString<uint8_t>** param, index_t* length,
00466                       const char* name, const char* description) {
00467     TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT8, length);
00468     add_type(&type, param, name, description);
00469 }
00470 
00471 void
00472 Parameter::add_vector(SGString<int16_t>** param, index_t* length,
00473                       const char* name, const char* description) {
00474     TSGDataType type(CT_VECTOR, ST_STRING, PT_INT16, length);
00475     add_type(&type, param, name, description);
00476 }
00477 
00478 void
00479 Parameter::add_vector(SGString<uint16_t>** param, index_t* length,
00480                       const char* name, const char* description) {
00481     TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT16, length);
00482     add_type(&type, param, name, description);
00483 }
00484 
00485 void
00486 Parameter::add_vector(SGString<int32_t>** param, index_t* length,
00487                       const char* name, const char* description) {
00488     TSGDataType type(CT_VECTOR, ST_STRING, PT_INT32, length);
00489     add_type(&type, param, name, description);
00490 }
00491 
00492 void
00493 Parameter::add_vector(SGString<uint32_t>** param, index_t* length,
00494                       const char* name, const char* description) {
00495     TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT32, length);
00496     add_type(&type, param, name, description);
00497 }
00498 
00499 void
00500 Parameter::add_vector(SGString<int64_t>** param, index_t* length,
00501                       const char* name, const char* description) {
00502     TSGDataType type(CT_VECTOR, ST_STRING, PT_INT64, length);
00503     add_type(&type, param, name, description);
00504 }
00505 
00506 void
00507 Parameter::add_vector(SGString<uint64_t>** param, index_t* length,
00508                       const char* name, const char* description) {
00509     TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT64, length);
00510     add_type(&type, param, name, description);
00511 }
00512 
00513 void
00514 Parameter::add_vector(SGString<float32_t>** param, index_t* length,
00515                       const char* name, const char* description) {
00516     TSGDataType type(CT_VECTOR, ST_STRING, PT_FLOAT32, length);
00517     add_type(&type, param, name, description);
00518 }
00519 
00520 void
00521 Parameter::add_vector(SGString<float64_t>** param, index_t* length,
00522                       const char* name, const char* description) {
00523     TSGDataType type(CT_VECTOR, ST_STRING, PT_FLOAT64, length);
00524     add_type(&type, param, name, description);
00525 }
00526 
00527 void
00528 Parameter::add_vector(SGString<floatmax_t>** param, index_t* length,
00529                       const char* name, const char* description) {
00530     TSGDataType type(CT_VECTOR, ST_STRING, PT_FLOATMAX, length);
00531     add_type(&type, param, name, description);
00532 }
00533 
00534 void
00535 Parameter::add_vector(SGSparseVector<bool>** param, index_t* length,
00536                       const char* name, const char* description) {
00537     TSGDataType type(CT_VECTOR, ST_SPARSE, PT_BOOL, length);
00538     add_type(&type, param, name, description);
00539 }
00540 
00541 void
00542 Parameter::add_vector(SGSparseVector<char>** param, index_t* length,
00543                       const char* name, const char* description) {
00544     TSGDataType type(CT_VECTOR, ST_SPARSE, PT_CHAR, length);
00545     add_type(&type, param, name, description);
00546 }
00547 
00548 void
00549 Parameter::add_vector(SGSparseVector<int8_t>** param, index_t* length,
00550                       const char* name, const char* description) {
00551     TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT8, length);
00552     add_type(&type, param, name, description);
00553 }
00554 
00555 void
00556 Parameter::add_vector(SGSparseVector<uint8_t>** param, index_t* length,
00557                       const char* name, const char* description) {
00558     TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT8, length);
00559     add_type(&type, param, name, description);
00560 }
00561 
00562 void
00563 Parameter::add_vector(SGSparseVector<int16_t>** param, index_t* length,
00564                       const char* name, const char* description) {
00565     TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT16, length);
00566     add_type(&type, param, name, description);
00567 }
00568 
00569 void
00570 Parameter::add_vector(SGSparseVector<uint16_t>** param, index_t* length,
00571                       const char* name, const char* description) {
00572     TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT16, length);
00573     add_type(&type, param, name, description);
00574 }
00575 
00576 void
00577 Parameter::add_vector(SGSparseVector<int32_t>** param, index_t* length,
00578                       const char* name, const char* description) {
00579     TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT32, length);
00580     add_type(&type, param, name, description);
00581 }
00582 
00583 void
00584 Parameter::add_vector(SGSparseVector<uint32_t>** param, index_t* length,
00585                       const char* name, const char* description) {
00586     TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT32, length);
00587     add_type(&type, param, name, description);
00588 }
00589 
00590 void
00591 Parameter::add_vector(SGSparseVector<int64_t>** param, index_t* length,
00592                       const char* name, const char* description) {
00593     TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT64, length);
00594     add_type(&type, param, name, description);
00595 }
00596 
00597 void
00598 Parameter::add_vector(SGSparseVector<uint64_t>** param, index_t* length,
00599                       const char* name, const char* description) {
00600     TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT64, length);
00601     add_type(&type, param, name, description);
00602 }
00603 
00604 void
00605 Parameter::add_vector(SGSparseVector<float32_t>** param, index_t* length,
00606                       const char* name, const char* description) {
00607     TSGDataType type(CT_VECTOR, ST_SPARSE, PT_FLOAT32, length);
00608     add_type(&type, param, name, description);
00609 }
00610 
00611 void
00612 Parameter::add_vector(SGSparseVector<float64_t>** param, index_t* length,
00613                       const char* name, const char* description) {
00614     TSGDataType type(CT_VECTOR, ST_SPARSE, PT_FLOAT64, length);
00615     add_type(&type, param, name, description);
00616 }
00617 
00618 void
00619 Parameter::add_vector(SGSparseVector<floatmax_t>** param, index_t* length,
00620                       const char* name, const char* description) {
00621     TSGDataType type(CT_VECTOR, ST_SPARSE, PT_FLOATMAX, length);
00622     add_type(&type, param, name, description);
00623 }
00624 
00625 void
00626 Parameter::add_vector(SGSparseVector<complex128_t>** param, index_t* length,
00627                       const char* name, const char* description) {
00628     TSGDataType type(CT_VECTOR, ST_SPARSE, PT_COMPLEX128, length);
00629     add_type(&type, param, name, description);
00630 }
00631 
00632 
00633 
00634 
00635 void Parameter::add(SGVector<bool>* param, const char* name,
00636         const char* description)
00637 {
00638     TSGDataType type(CT_SGVECTOR, ST_NONE, PT_BOOL, &param->vlen);
00639     add_type(&type, &param->vector, name, description);
00640 }
00641 
00642 void Parameter::add(SGVector<char>* param, const char* name,
00643         const char* description)
00644 {
00645     TSGDataType type(CT_SGVECTOR, ST_NONE, PT_CHAR, &param->vlen);
00646     add_type(&type, &param->vector, name, description);
00647 }
00648 
00649 void Parameter::add(SGVector<int8_t>* param, const char* name,
00650         const char* description)
00651 {
00652     TSGDataType type(CT_SGVECTOR, ST_NONE, PT_INT8, &param->vlen);
00653     add_type(&type, &param->vector, name, description);
00654 }
00655 
00656 void Parameter::add(SGVector<uint8_t>* param, const char* name,
00657         const char* description)
00658 {
00659     TSGDataType type(CT_SGVECTOR, ST_NONE, PT_UINT8, &param->vlen);
00660     add_type(&type, &param->vector, name, description);
00661 }
00662 
00663 void Parameter::add(SGVector<int16_t>* param, const char* name,
00664         const char* description)
00665 {
00666     TSGDataType type(CT_SGVECTOR, ST_NONE, PT_INT16, &param->vlen);
00667     add_type(&type, &param->vector, name, description);
00668 }
00669 
00670 void Parameter::add(SGVector<uint16_t>* param, const char* name,
00671         const char* description)
00672 {
00673     TSGDataType type(CT_SGVECTOR, ST_NONE, PT_UINT16, &param->vlen);
00674     add_type(&type, &param->vector, name, description);
00675 }
00676 
00677 void Parameter::add(SGVector<int32_t>* param, const char* name,
00678         const char* description)
00679 {
00680     TSGDataType type(CT_SGVECTOR, ST_NONE, PT_INT32, &param->vlen);
00681     add_type(&type, &param->vector, name, description);
00682 }
00683 
00684 void Parameter::add(SGVector<uint32_t>* param, const char* name,
00685         const char* description)
00686 {
00687     TSGDataType type(CT_SGVECTOR, ST_NONE, PT_UINT32, &param->vlen);
00688     add_type(&type, &param->vector, name, description);
00689 }
00690 
00691 void Parameter::add(SGVector<int64_t>* param, const char* name,
00692         const char* description)
00693 {
00694     TSGDataType type(CT_SGVECTOR, ST_NONE, PT_INT64, &param->vlen);
00695     add_type(&type, &param->vector, name, description);
00696 }
00697 
00698 void Parameter::add(SGVector<uint64_t>* param, const char* name,
00699         const char* description)
00700 {
00701     TSGDataType type(CT_SGVECTOR, ST_NONE, PT_UINT64, &param->vlen);
00702     add_type(&type, &param->vector, name, description);
00703 }
00704 
00705 void Parameter::add(SGVector<float32_t>* param, const char* name,
00706         const char* description)
00707 {
00708     TSGDataType type(CT_SGVECTOR, ST_NONE, PT_FLOAT32, &param->vlen);
00709     add_type(&type, &param->vector, name, description);
00710 }
00711 
00712 void Parameter::add(SGVector<float64_t>* param, const char* name,
00713         const char* description)
00714 {
00715     TSGDataType type(CT_SGVECTOR, ST_NONE, PT_FLOAT64, &param->vlen);
00716     add_type(&type, &param->vector, name, description);
00717 }
00718 
00719 void Parameter::add(SGVector<floatmax_t>* param, const char* name,
00720         const char* description)
00721 {
00722     TSGDataType type(CT_SGVECTOR, ST_NONE, PT_FLOATMAX, &param->vlen);
00723     add_type(&type, &param->vector, name, description);
00724 }
00725 
00726 void Parameter::add(SGVector<complex128_t>* param, const char* name,
00727         const char* description)
00728 {
00729     TSGDataType type(CT_SGVECTOR, ST_NONE, PT_COMPLEX128, &param->vlen);
00730     add_type(&type, &param->vector, name, description);
00731 }
00732 
00733 void Parameter::add(SGVector<CSGObject*>* param, const char* name,
00734         const char* description)
00735 {
00736     TSGDataType type(CT_SGVECTOR, ST_NONE, PT_SGOBJECT, &param->vlen);
00737     add_type(&type, &param->vector, name, description);
00738 }
00739 
00740 void Parameter::add(SGVector<SGString<bool> >* param, const char* name,
00741         const char* description)
00742 {
00743     TSGDataType type(CT_SGVECTOR, ST_STRING, PT_BOOL, &param->vlen);
00744     add_type(&type, &param->vector, name, description);
00745 }
00746 
00747 void Parameter::add(SGVector<SGString<char> >* param, const char* name,
00748         const char* description)
00749 {
00750     TSGDataType type(CT_SGVECTOR, ST_STRING, PT_CHAR, &param->vlen);
00751     add_type(&type, &param->vector, name, description);
00752 }
00753 
00754 void Parameter::add(SGVector<SGString<int8_t> >* param,
00755         const char* name, const char* description)
00756 {
00757     TSGDataType type(CT_SGVECTOR, ST_STRING, PT_INT8, &param->vlen);
00758     add_type(&type, &param->vector, name, description);
00759 }
00760 
00761 void Parameter::add(SGVector<SGString<uint8_t> >* param,
00762         const char* name, const char* description)
00763 {
00764     TSGDataType type(CT_SGVECTOR, ST_STRING, PT_UINT8, &param->vlen);
00765     add_type(&type, &param->vector, name, description);
00766 }
00767 
00768 void Parameter::add(SGVector<SGString<int16_t> >* param,
00769         const char* name, const char* description)
00770 {
00771     TSGDataType type(CT_SGVECTOR, ST_STRING, PT_INT16, &param->vlen);
00772     add_type(&type, &param->vector, name, description);
00773 }
00774 
00775 void Parameter::add(SGVector<SGString<uint16_t> >* param,
00776         const char* name, const char* description)
00777 {
00778     TSGDataType type(CT_SGVECTOR, ST_STRING, PT_UINT16, &param->vlen);
00779     add_type(&type, &param->vector, name, description);
00780 }
00781 
00782 void Parameter::add(SGVector<SGString<int32_t> >* param,
00783         const char* name, const char* description)
00784 {
00785     TSGDataType type(CT_SGVECTOR, ST_STRING, PT_INT32, &param->vlen);
00786     add_type(&type, &param->vector, name, description);
00787 }
00788 
00789 void Parameter::add(SGVector<SGString<uint32_t> >* param,
00790         const char* name, const char* description)
00791 {
00792     TSGDataType type(CT_SGVECTOR, ST_STRING, PT_UINT32, &param->vlen);
00793     add_type(&type, &param->vector, name, description);
00794 }
00795 
00796 void Parameter::add(SGVector<SGString<int64_t> >* param,
00797         const char* name, const char* description)
00798 {
00799     TSGDataType type(CT_SGVECTOR, ST_STRING, PT_INT64, &param->vlen);
00800     add_type(&type, &param->vector, name, description);
00801 }
00802 
00803 void Parameter::add(SGVector<SGString<uint64_t> >* param,
00804         const char* name, const char* description)
00805 {
00806     TSGDataType type(CT_SGVECTOR, ST_STRING, PT_UINT64, &param->vlen);
00807     add_type(&type, &param->vector, name, description);
00808 }
00809 
00810 void Parameter::add(SGVector<SGString<float32_t> >* param,
00811         const char* name, const char* description)
00812 {
00813     TSGDataType type(CT_SGVECTOR, ST_STRING, PT_FLOAT32, &param->vlen);
00814     add_type(&type, &param->vector, name, description);
00815 }
00816 
00817 void Parameter::add(SGVector<SGString<float64_t> >* param,
00818         const char* name, const char* description)
00819 {
00820     TSGDataType type(CT_SGVECTOR, ST_STRING, PT_FLOAT64, &param->vlen);
00821     add_type(&type, &param->vector, name, description);
00822 }
00823 
00824 void Parameter::add(SGVector<SGString<floatmax_t> >* param,
00825         const char* name, const char* description)
00826 {
00827     TSGDataType type(CT_SGVECTOR, ST_STRING, PT_FLOATMAX, &param->vlen);
00828     add_type(&type, &param->vector, name, description);
00829 }
00830 
00831 void Parameter::add(SGVector<SGSparseVector<bool> >* param,
00832         const char* name, const char* description)
00833 {
00834     TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_BOOL, &param->vlen);
00835     add_type(&type, &param->vector, name, description);
00836 }
00837 
00838 void Parameter::add(SGVector<SGSparseVector<char> >* param,
00839         const char* name, const char* description)
00840 {
00841     TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_CHAR, &param->vlen);
00842     add_type(&type, &param->vector, name, description);
00843 }
00844 
00845 void Parameter::add(SGVector<SGSparseVector<int8_t> >* param,
00846         const char* name, const char* description)
00847 {
00848     TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_INT8, &param->vlen);
00849     add_type(&type, &param->vector, name, description);
00850 }
00851 
00852 void Parameter::add(SGVector<SGSparseVector<uint8_t> >* param,
00853         const char* name, const char* description)
00854 {
00855     TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_UINT8, &param->vlen);
00856     add_type(&type, &param->vector, name, description);
00857 }
00858 
00859 void Parameter::add(SGVector<SGSparseVector<int16_t> >* param,
00860         const char* name, const char* description)
00861 {
00862     TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_INT16, &param->vlen);
00863     add_type(&type, &param->vector, name, description);
00864 }
00865 
00866 void Parameter::add(SGVector<SGSparseVector<uint16_t> >* param,
00867         const char* name, const char* description)
00868 {
00869     TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_UINT16, &param->vlen);
00870     add_type(&type, &param->vector, name, description);
00871 }
00872 
00873 void Parameter::add(SGVector<SGSparseVector<int32_t> >* param,
00874         const char* name, const char* description)
00875 {
00876     TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_INT32, &param->vlen);
00877     add_type(&type, &param->vector, name, description);
00878 }
00879 
00880 void Parameter::add(SGVector<SGSparseVector<uint32_t> >* param,
00881         const char* name, const char* description)
00882 {
00883     TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_UINT32, &param->vlen);
00884     add_type(&type, &param->vector, name, description);
00885 }
00886 
00887 void Parameter::add(SGVector<SGSparseVector<int64_t> >* param,
00888         const char* name, const char* description)
00889 {
00890     TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_INT64, &param->vlen);
00891     add_type(&type, &param->vector, name, description);
00892 }
00893 
00894 void Parameter::add(SGVector<SGSparseVector<uint64_t> >* param,
00895         const char* name, const char* description)
00896 {
00897     TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_UINT64, &param->vlen);
00898     add_type(&type, &param->vector, name, description);
00899 }
00900 
00901 void Parameter::add(SGVector<SGSparseVector<float32_t> >* param,
00902         const char* name, const char* description)
00903 {
00904     TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_FLOAT32, &param->vlen);
00905     add_type(&type, &param->vector, name, description);
00906 }
00907 
00908 void Parameter::add(SGVector<SGSparseVector<float64_t> >* param,
00909         const char* name, const char* description)
00910 {
00911     TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_FLOAT64, &param->vlen);
00912     add_type(&type, &param->vector, name, description);
00913 }
00914 
00915 void Parameter::add(SGVector<SGSparseVector<floatmax_t> >* param,
00916         const char* name, const char* description)
00917 {
00918     TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_FLOATMAX, &param->vlen);
00919     add_type(&type, &param->vector, name, description);
00920 }
00921 
00922 void Parameter::add(SGVector<SGSparseVector<complex128_t> >* param,
00923         const char* name, const char* description)
00924 {
00925     TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_COMPLEX128, &param->vlen);
00926     add_type(&type, &param->vector, name, description);
00927 }
00928 
00929 /* **************************************************************** */
00930 /* Matrix wrappers  */
00931 
00932 void
00933 Parameter::add_matrix(
00934     bool** param, index_t* length_y, index_t* length_x,
00935     const char* name, const char* description) {
00936     TSGDataType type(CT_MATRIX, ST_NONE, PT_BOOL, length_y,
00937                      length_x);
00938     add_type(&type, param, name, description);
00939 }
00940 
00941 void
00942 Parameter::add_matrix(
00943     char** param, index_t* length_y, index_t* length_x,
00944     const char* name, const char* description) {
00945     TSGDataType type(CT_MATRIX, ST_NONE, PT_CHAR, length_y,
00946                      length_x);
00947     add_type(&type, param, name, description);
00948 }
00949 
00950 void
00951 Parameter::add_matrix(
00952     int8_t** param, index_t* length_y, index_t* length_x,
00953     const char* name, const char* description) {
00954     TSGDataType type(CT_MATRIX, ST_NONE, PT_INT8, length_y,
00955                      length_x);
00956     add_type(&type, param, name, description);
00957 }
00958 
00959 void
00960 Parameter::add_matrix(
00961     uint8_t** param, index_t* length_y, index_t* length_x,
00962     const char* name, const char* description) {
00963     TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT8, length_y,
00964                      length_x);
00965     add_type(&type, param, name, description);
00966 }
00967 
00968 void
00969 Parameter::add_matrix(
00970     int16_t** param, index_t* length_y, index_t* length_x,
00971     const char* name, const char* description) {
00972     TSGDataType type(CT_MATRIX, ST_NONE, PT_INT16, length_y,
00973                      length_x);
00974     add_type(&type, param, name, description);
00975 }
00976 
00977 void
00978 Parameter::add_matrix(
00979     uint16_t** param, index_t* length_y, index_t* length_x,
00980     const char* name, const char* description) {
00981     TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT16, length_y,
00982                      length_x);
00983     add_type(&type, param, name, description);
00984 }
00985 
00986 void
00987 Parameter::add_matrix(
00988     int32_t** param, index_t* length_y, index_t* length_x,
00989     const char* name, const char* description) {
00990     TSGDataType type(CT_MATRIX, ST_NONE, PT_INT32, length_y,
00991                      length_x);
00992     add_type(&type, param, name, description);
00993 }
00994 
00995 void
00996 Parameter::add_matrix(
00997     uint32_t** param, index_t* length_y, index_t* length_x,
00998     const char* name, const char* description) {
00999     TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT32, length_y,
01000                      length_x);
01001     add_type(&type, param, name, description);
01002 }
01003 
01004 void
01005 Parameter::add_matrix(
01006     int64_t** param, index_t* length_y, index_t* length_x,
01007     const char* name, const char* description) {
01008     TSGDataType type(CT_MATRIX, ST_NONE, PT_INT64, length_y,
01009                      length_x);
01010     add_type(&type, param, name, description);
01011 }
01012 
01013 void
01014 Parameter::add_matrix(
01015     uint64_t** param, index_t* length_y, index_t* length_x,
01016     const char* name, const char* description) {
01017     TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT64, length_y,
01018                      length_x);
01019     add_type(&type, param, name, description);
01020 }
01021 
01022 void
01023 Parameter::add_matrix(
01024     float32_t** param, index_t* length_y, index_t* length_x,
01025     const char* name, const char* description) {
01026     TSGDataType type(CT_MATRIX, ST_NONE, PT_FLOAT32, length_y,
01027                      length_x);
01028     add_type(&type, param, name, description);
01029 }
01030 
01031 void
01032 Parameter::add_matrix(
01033     float64_t** param, index_t* length_y, index_t* length_x,
01034     const char* name, const char* description) {
01035     TSGDataType type(CT_MATRIX, ST_NONE, PT_FLOAT64, length_y,
01036                      length_x);
01037     add_type(&type, param, name, description);
01038 }
01039 
01040 void
01041 Parameter::add_matrix(
01042     floatmax_t** param, index_t* length_y, index_t* length_x,
01043     const char* name, const char* description) {
01044     TSGDataType type(CT_MATRIX, ST_NONE, PT_FLOATMAX, length_y,
01045                      length_x);
01046     add_type(&type, param, name, description);
01047 }
01048 
01049 void
01050 Parameter::add_matrix(
01051     complex128_t** param, index_t* length_y, index_t* length_x,
01052     const char* name, const char* description) {
01053     TSGDataType type(CT_MATRIX, ST_NONE, PT_COMPLEX128, length_y,
01054                      length_x);
01055     add_type(&type, param, name, description);
01056 }
01057 
01058 void
01059 Parameter::add_matrix(
01060     CSGObject*** param, index_t* length_y, index_t* length_x,
01061     const char* name, const char* description) {
01062     TSGDataType type(CT_MATRIX, ST_NONE, PT_SGOBJECT,
01063                      length_y, length_x);
01064     add_type(&type, param, name, description);
01065 }
01066 
01067 void
01068 Parameter::add_matrix(SGString<bool>** param,
01069                       index_t* length_y, index_t* length_x,
01070                       const char* name, const char* description) {
01071     TSGDataType type(CT_MATRIX, ST_STRING, PT_BOOL, length_y,
01072                      length_x);
01073     add_type(&type, param, name, description);
01074 }
01075 
01076 void
01077 Parameter::add_matrix(SGString<char>** param,
01078                       index_t* length_y, index_t* length_x,
01079                       const char* name, const char* description) {
01080     TSGDataType type(CT_MATRIX, ST_STRING, PT_CHAR, length_y,
01081                      length_x);
01082     add_type(&type, param, name, description);
01083 }
01084 
01085 void
01086 Parameter::add_matrix(SGString<int8_t>** param,
01087                       index_t* length_y, index_t* length_x,
01088                       const char* name, const char* description) {
01089     TSGDataType type(CT_MATRIX, ST_STRING, PT_INT8, length_y,
01090                      length_x);
01091     add_type(&type, param, name, description);
01092 }
01093 
01094 void
01095 Parameter::add_matrix(SGString<uint8_t>** param,
01096                       index_t* length_y, index_t* length_x,
01097                       const char* name, const char* description) {
01098     TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT8, length_y,
01099                      length_x);
01100     add_type(&type, param, name, description);
01101 }
01102 
01103 void
01104 Parameter::add_matrix(SGString<int16_t>** param,
01105                       index_t* length_y, index_t* length_x,
01106                       const char* name, const char* description) {
01107     TSGDataType type(CT_MATRIX, ST_STRING, PT_INT16, length_y,
01108                      length_x);
01109     add_type(&type, param, name, description);
01110 }
01111 
01112 void
01113 Parameter::add_matrix(SGString<uint16_t>** param,
01114                       index_t* length_y, index_t* length_x,
01115                       const char* name, const char* description) {
01116     TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT16, length_y,
01117                      length_x);
01118     add_type(&type, param, name, description);
01119 }
01120 
01121 void
01122 Parameter::add_matrix(SGString<int32_t>** param,
01123                       index_t* length_y, index_t* length_x,
01124                       const char* name, const char* description) {
01125     TSGDataType type(CT_MATRIX, ST_STRING, PT_INT32, length_y,
01126                      length_x);
01127     add_type(&type, param, name, description);
01128 }
01129 
01130 void
01131 Parameter::add_matrix(SGString<uint32_t>** param,
01132                       index_t* length_y, index_t* length_x,
01133                       const char* name, const char* description) {
01134     TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT32, length_y,
01135                      length_x);
01136     add_type(&type, param, name, description);
01137 }
01138 
01139 void
01140 Parameter::add_matrix(SGString<int64_t>** param,
01141                       index_t* length_y, index_t* length_x,
01142                       const char* name, const char* description) {
01143     TSGDataType type(CT_MATRIX, ST_STRING, PT_INT64, length_y,
01144                      length_x);
01145     add_type(&type, param, name, description);
01146 }
01147 
01148 void
01149 Parameter::add_matrix(SGString<uint64_t>** param,
01150                       index_t* length_y, index_t* length_x,
01151                       const char* name, const char* description) {
01152     TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT64, length_y,
01153                      length_x);
01154     add_type(&type, param, name, description);
01155 }
01156 
01157 void
01158 Parameter::add_matrix(SGString<float32_t>** param,
01159                       index_t* length_y, index_t* length_x,
01160                       const char* name, const char* description) {
01161     TSGDataType type(CT_MATRIX, ST_STRING, PT_FLOAT32, length_y,
01162                      length_x);
01163     add_type(&type, param, name, description);
01164 }
01165 
01166 void
01167 Parameter::add_matrix(SGString<float64_t>** param,
01168                       index_t* length_y, index_t* length_x,
01169                       const char* name, const char* description) {
01170     TSGDataType type(CT_MATRIX, ST_STRING, PT_FLOAT64, length_y,
01171                      length_x);
01172     add_type(&type, param, name, description);
01173 }
01174 
01175 void
01176 Parameter::add_matrix(SGString<floatmax_t>** param,
01177                       index_t* length_y, index_t* length_x,
01178                       const char* name, const char* description) {
01179     TSGDataType type(CT_MATRIX, ST_STRING, PT_FLOATMAX, length_y,
01180                      length_x);
01181     add_type(&type, param, name, description);
01182 }
01183 
01184 void
01185 Parameter::add_matrix(SGSparseVector<bool>** param,
01186                       index_t* length_y, index_t* length_x,
01187                       const char* name, const char* description) {
01188     TSGDataType type(CT_MATRIX, ST_SPARSE, PT_BOOL, length_y,
01189                      length_x);
01190     add_type(&type, param, name, description);
01191 }
01192 
01193 void
01194 Parameter::add_matrix(SGSparseVector<char>** param,
01195                       index_t* length_y, index_t* length_x,
01196                       const char* name, const char* description) {
01197     TSGDataType type(CT_MATRIX, ST_SPARSE, PT_CHAR, length_y,
01198                      length_x);
01199     add_type(&type, param, name, description);
01200 }
01201 
01202 void
01203 Parameter::add_matrix(SGSparseVector<int8_t>** param,
01204                       index_t* length_y, index_t* length_x,
01205                       const char* name, const char* description) {
01206     TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT8, length_y,
01207                      length_x);
01208     add_type(&type, param, name, description);
01209 }
01210 
01211 void
01212 Parameter::add_matrix(SGSparseVector<uint8_t>** param,
01213                       index_t* length_y, index_t* length_x,
01214                       const char* name, const char* description) {
01215     TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT8, length_y,
01216                      length_x);
01217     add_type(&type, param, name, description);
01218 }
01219 
01220 void
01221 Parameter::add_matrix(SGSparseVector<int16_t>** param,
01222                       index_t* length_y, index_t* length_x,
01223                       const char* name, const char* description) {
01224     TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT16, length_y,
01225                      length_x);
01226     add_type(&type, param, name, description);
01227 }
01228 
01229 void
01230 Parameter::add_matrix(SGSparseVector<uint16_t>** param,
01231                       index_t* length_y, index_t* length_x,
01232                       const char* name, const char* description) {
01233     TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT16, length_y,
01234                      length_x);
01235     add_type(&type, param, name, description);
01236 }
01237 
01238 void
01239 Parameter::add_matrix(SGSparseVector<int32_t>** param,
01240                       index_t* length_y, index_t* length_x,
01241                       const char* name, const char* description) {
01242     TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT32, length_y,
01243                      length_x);
01244     add_type(&type, param, name, description);
01245 }
01246 
01247 void
01248 Parameter::add_matrix(SGSparseVector<uint32_t>** param,
01249                       index_t* length_y, index_t* length_x,
01250                       const char* name, const char* description) {
01251     TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT32, length_y,
01252                      length_x);
01253     add_type(&type, param, name, description);
01254 }
01255 
01256 void
01257 Parameter::add_matrix(SGSparseVector<int64_t>** param,
01258                       index_t* length_y, index_t* length_x,
01259                       const char* name, const char* description) {
01260     TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT64, length_y,
01261                      length_x);
01262     add_type(&type, param, name, description);
01263 }
01264 
01265 void
01266 Parameter::add_matrix(SGSparseVector<uint64_t>** param,
01267                       index_t* length_y, index_t* length_x,
01268                       const char* name, const char* description) {
01269     TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT64, length_y,
01270                      length_x);
01271     add_type(&type, param, name, description);
01272 }
01273 
01274 void
01275 Parameter::add_matrix(SGSparseVector<float32_t>** param,
01276                       index_t* length_y, index_t* length_x,
01277                       const char* name, const char* description) {
01278     TSGDataType type(CT_MATRIX, ST_SPARSE, PT_FLOAT32, length_y,
01279                      length_x);
01280     add_type(&type, param, name, description);
01281 }
01282 
01283 void
01284 Parameter::add_matrix(SGSparseVector<float64_t>** param,
01285                       index_t* length_y, index_t* length_x,
01286                       const char* name, const char* description) {
01287     TSGDataType type(CT_MATRIX, ST_SPARSE, PT_FLOAT64, length_y,
01288                      length_x);
01289     add_type(&type, param, name, description);
01290 }
01291 
01292 void
01293 Parameter::add_matrix(SGSparseVector<floatmax_t>** param,
01294                       index_t* length_y, index_t* length_x,
01295                       const char* name, const char* description) {
01296     TSGDataType type(CT_MATRIX, ST_SPARSE, PT_FLOATMAX, length_y,
01297                      length_x);
01298     add_type(&type, param, name, description);
01299 }
01300 
01301 void
01302 Parameter::add_matrix(SGSparseVector<complex128_t>** param,
01303                       index_t* length_y, index_t* length_x,
01304                       const char* name, const char* description) {
01305     TSGDataType type(CT_MATRIX, ST_SPARSE, PT_COMPLEX128, length_y,
01306                      length_x);
01307     add_type(&type, param, name, description);
01308 }
01309 
01310 
01311 
01312 
01313 void Parameter::add(SGMatrix<bool>* param, const char* name,
01314         const char* description)
01315 {
01316     TSGDataType type(CT_SGMATRIX, ST_NONE, PT_BOOL, &param->num_rows,
01317             &param->num_cols);
01318     add_type(&type, &param->matrix, name, description);
01319 }
01320 
01321 void Parameter::add(SGMatrix<char>* param, const char* name,
01322         const char* description)
01323 {
01324     TSGDataType type(CT_SGMATRIX, ST_NONE, PT_CHAR, &param->num_rows,
01325             &param->num_cols);
01326     add_type(&type, &param->matrix, name, description);
01327 }
01328 
01329 void Parameter::add(SGMatrix<int8_t>* param, const char* name,
01330         const char* description)
01331 {
01332     TSGDataType type(CT_SGMATRIX, ST_NONE, PT_INT8, &param->num_rows,
01333             &param->num_cols);
01334     add_type(&type, &param->matrix, name, description);
01335 }
01336 
01337 void Parameter::add(SGMatrix<uint8_t>* param, const char* name,
01338         const char* description)
01339 {
01340     TSGDataType type(CT_SGMATRIX, ST_NONE, PT_UINT8, &param->num_rows,
01341             &param->num_cols);
01342     add_type(&type, &param->matrix, name, description);
01343 }
01344 
01345 void Parameter::add(SGMatrix<int16_t>* param, const char* name,
01346         const char* description)
01347 {
01348     TSGDataType type(CT_SGMATRIX, ST_NONE, PT_INT16, &param->num_rows,
01349             &param->num_cols);
01350     add_type(&type, &param->matrix, name, description);
01351 }
01352 
01353 void Parameter::add(SGMatrix<uint16_t>* param, const char* name,
01354         const char* description)
01355 {
01356     TSGDataType type(CT_SGMATRIX, ST_NONE, PT_UINT16, &param->num_rows,
01357             &param->num_cols);
01358     add_type(&type, &param->matrix, name, description);
01359 }
01360 
01361 void Parameter::add(SGMatrix<int32_t>* param, const char* name,
01362         const char* description)
01363 {
01364     TSGDataType type(CT_SGMATRIX, ST_NONE, PT_INT32, &param->num_rows,
01365             &param->num_cols);
01366     add_type(&type, &param->matrix, name, description);
01367 }
01368 
01369 void Parameter::add(SGMatrix<uint32_t>* param, const char* name,
01370         const char* description)
01371 {
01372     TSGDataType type(CT_SGMATRIX, ST_NONE, PT_UINT32, &param->num_rows,
01373             &param->num_cols);
01374     add_type(&type, &param->matrix, name, description);
01375 }
01376 
01377 void Parameter::add(SGMatrix<int64_t>* param, const char* name,
01378         const char* description)
01379 {
01380     TSGDataType type(CT_SGMATRIX, ST_NONE, PT_INT64, &param->num_rows,
01381             &param->num_cols);
01382     add_type(&type, &param->matrix, name, description);
01383 }
01384 
01385 void Parameter::add(SGMatrix<uint64_t>* param, const char* name,
01386         const char* description)
01387 {
01388     TSGDataType type(CT_SGMATRIX, ST_NONE, PT_UINT64, &param->num_rows,
01389             &param->num_cols);
01390     add_type(&type, &param->matrix, name, description);
01391 }
01392 
01393 void Parameter::add(SGMatrix<float32_t>* param, const char* name,
01394         const char* description)
01395 {
01396     TSGDataType type(CT_SGMATRIX, ST_NONE, PT_FLOAT32, &param->num_rows,
01397             &param->num_cols);
01398     add_type(&type, &param->matrix, name, description);
01399 }
01400 
01401 void Parameter::add(SGMatrix<float64_t>* param, const char* name,
01402         const char* description)
01403 {
01404     TSGDataType type(CT_SGMATRIX, ST_NONE, PT_FLOAT64, &param->num_rows,
01405             &param->num_cols);
01406     add_type(&type, &param->matrix, name, description);
01407 }
01408 
01409 void Parameter::add(SGMatrix<floatmax_t>* param, const char* name,
01410         const char* description)
01411 {
01412     TSGDataType type(CT_SGMATRIX, ST_NONE, PT_FLOATMAX, &param->num_rows,
01413             &param->num_cols);
01414     add_type(&type, &param->matrix, name, description);
01415 }
01416 
01417 void Parameter::add(SGMatrix<complex128_t>* param, const char* name,
01418         const char* description)
01419 {
01420     TSGDataType type(CT_SGMATRIX, ST_NONE, PT_COMPLEX128, &param->num_rows,
01421             &param->num_cols);
01422     add_type(&type, &param->matrix, name, description);
01423 }
01424 
01425 void Parameter::add(SGMatrix<CSGObject*>* param, const char* name,
01426         const char* description)
01427 {
01428     TSGDataType type(CT_SGMATRIX, ST_NONE, PT_SGOBJECT, &param->num_rows,
01429             &param->num_cols);
01430     add_type(&type, &param->matrix, name, description);
01431 }
01432 
01433 void Parameter::add(SGMatrix<SGString<bool> >* param, const char* name,
01434         const char* description)
01435 {
01436     TSGDataType type(CT_SGMATRIX, ST_STRING, PT_BOOL, &param->num_rows,
01437             &param->num_cols);
01438     add_type(&type, &param->matrix, name, description);
01439 }
01440 
01441 void Parameter::add(SGMatrix<SGString<char> >* param, const char* name,
01442         const char* description)
01443 {
01444     TSGDataType type(CT_SGMATRIX, ST_STRING, PT_CHAR, &param->num_rows,
01445             &param->num_cols);
01446     add_type(&type, &param->matrix, name, description);
01447 }
01448 
01449 void Parameter::add(SGMatrix<SGString<int8_t> >* param,
01450         const char* name, const char* description)
01451 {
01452     TSGDataType type(CT_SGMATRIX, ST_STRING, PT_INT8, &param->num_rows,
01453             &param->num_cols);
01454     add_type(&type, &param->matrix, name, description);
01455 }
01456 
01457 void Parameter::add(SGMatrix<SGString<uint8_t> >* param,
01458         const char* name, const char* description)
01459 {
01460     TSGDataType type(CT_SGMATRIX, ST_STRING, PT_UINT8, &param->num_rows,
01461             &param->num_cols);
01462     add_type(&type, &param->matrix, name, description);
01463 }
01464 
01465 void Parameter::add(SGMatrix<SGString<int16_t> >* param,
01466         const char* name, const char* description)
01467 {
01468     TSGDataType type(CT_SGMATRIX, ST_STRING, PT_INT16, &param->num_rows,
01469             &param->num_cols);
01470     add_type(&type, &param->matrix, name, description);
01471 }
01472 
01473 void Parameter::add(SGMatrix<SGString<uint16_t> >* param,
01474         const char* name, const char* description)
01475 {
01476     TSGDataType type(CT_SGMATRIX, ST_STRING, PT_UINT16, &param->num_rows,
01477             &param->num_cols);
01478     add_type(&type, &param->matrix, name, description);
01479 }
01480 
01481 void Parameter::add(SGMatrix<SGString<int32_t> >* param,
01482         const char* name, const char* description)
01483 {
01484     TSGDataType type(CT_SGMATRIX, ST_STRING, PT_INT32, &param->num_rows,
01485             &param->num_cols);
01486     add_type(&type, &param->matrix, name, description);
01487 }
01488 
01489 void Parameter::add(SGMatrix<SGString<uint32_t> >* param,
01490         const char* name, const char* description)
01491 {
01492     TSGDataType type(CT_SGMATRIX, ST_STRING, PT_UINT32, &param->num_rows,
01493             &param->num_cols);
01494     add_type(&type, &param->matrix, name, description);
01495 }
01496 
01497 void Parameter::add(SGMatrix<SGString<int64_t> >* param,
01498         const char* name, const char* description)
01499 {
01500     TSGDataType type(CT_SGMATRIX, ST_STRING, PT_INT64, &param->num_rows,
01501             &param->num_cols);
01502     add_type(&type, &param->matrix, name, description);
01503 }
01504 
01505 void Parameter::add(SGMatrix<SGString<uint64_t> >* param,
01506         const char* name, const char* description)
01507 {
01508     TSGDataType type(CT_SGMATRIX, ST_STRING, PT_UINT64, &param->num_rows,
01509             &param->num_cols);
01510     add_type(&type, &param->matrix, name, description);
01511 }
01512 
01513 void Parameter::add(SGMatrix<SGString<float32_t> >* param,
01514         const char* name, const char* description)
01515 {
01516     TSGDataType type(CT_SGMATRIX, ST_STRING, PT_FLOAT32, &param->num_rows,
01517             &param->num_cols);
01518     add_type(&type, &param->matrix, name, description);
01519 }
01520 
01521 void Parameter::add(SGMatrix<SGString<float64_t> >* param,
01522         const char* name, const char* description)
01523 {
01524     TSGDataType type(CT_SGMATRIX, ST_STRING, PT_FLOAT64, &param->num_rows,
01525             &param->num_cols);
01526     add_type(&type, &param->matrix, name, description);
01527 }
01528 
01529 void Parameter::add(SGMatrix<SGString<floatmax_t> >* param,
01530         const char* name, const char* description)
01531 {
01532     TSGDataType type(CT_SGMATRIX, ST_STRING, PT_FLOATMAX, &param->num_rows,
01533             &param->num_cols);
01534     add_type(&type, &param->matrix, name, description);
01535 }
01536 
01537 void Parameter::add(SGMatrix<SGSparseVector<bool> >* param,
01538         const char* name, const char* description)
01539 {
01540     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_BOOL, &param->num_rows,
01541             &param->num_cols);
01542     add_type(&type, &param->matrix, name, description);
01543 }
01544 
01545 void Parameter::add(SGMatrix<SGSparseVector<char> >* param,
01546         const char* name, const char* description)
01547 {
01548     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_CHAR, &param->num_rows,
01549             &param->num_cols);
01550     add_type(&type, &param->matrix, name, description);
01551 }
01552 
01553 void Parameter::add(SGMatrix<SGSparseVector<int8_t> >* param,
01554         const char* name, const char* description)
01555 {
01556     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT8, &param->num_rows,
01557             &param->num_cols);
01558     add_type(&type, &param->matrix, name, description);
01559 }
01560 
01561 void Parameter::add(SGMatrix<SGSparseVector<uint8_t> >* param,
01562         const char* name, const char* description)
01563 {
01564     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT8, &param->num_rows,
01565             &param->num_cols);
01566     add_type(&type, &param->matrix, name, description);
01567 }
01568 
01569 void Parameter::add(SGMatrix<SGSparseVector<int16_t> >* param,
01570         const char* name, const char* description)
01571 {
01572     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT16, &param->num_rows,
01573             &param->num_cols);
01574     add_type(&type, &param->matrix, name, description);
01575 }
01576 
01577 void Parameter::add(SGMatrix<SGSparseVector<uint16_t> >* param,
01578         const char* name, const char* description)
01579 {
01580     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT16, &param->num_rows,
01581             &param->num_cols);
01582     add_type(&type, &param->matrix, name, description);
01583 }
01584 
01585 void Parameter::add(SGMatrix<SGSparseVector<int32_t> >* param,
01586         const char* name, const char* description)
01587 {
01588     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT32, &param->num_rows,
01589             &param->num_cols);
01590     add_type(&type, &param->matrix, name, description);
01591 }
01592 
01593 void Parameter::add(SGMatrix<SGSparseVector<uint32_t> >* param,
01594         const char* name, const char* description)
01595 {
01596     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT32, &param->num_rows,
01597             &param->num_cols);
01598     add_type(&type, &param->matrix, name, description);
01599 }
01600 
01601 void Parameter::add(SGMatrix<SGSparseVector<int64_t> >* param,
01602         const char* name, const char* description)
01603 {
01604     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT64, &param->num_rows,
01605             &param->num_cols);
01606     add_type(&type, &param->matrix, name, description);
01607 }
01608 
01609 void Parameter::add(SGMatrix<SGSparseVector<uint64_t> >* param,
01610         const char* name, const char* description)
01611 {
01612     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT64, &param->num_rows,
01613             &param->num_cols);
01614     add_type(&type, &param->matrix, name, description);
01615 }
01616 
01617 void Parameter::add(SGMatrix<SGSparseVector<float32_t> >* param,
01618         const char* name, const char* description)
01619 {
01620     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOAT32, &param->num_rows,
01621             &param->num_cols);
01622     add_type(&type, &param->matrix, name, description);
01623 }
01624 
01625 void Parameter::add(SGMatrix<SGSparseVector<float64_t> >* param,
01626         const char* name, const char* description)
01627 {
01628     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOAT64, &param->num_rows,
01629             &param->num_cols);
01630     add_type(&type, &param->matrix, name, description);
01631 }
01632 
01633 void Parameter::add(SGMatrix<SGSparseVector<floatmax_t> >* param,
01634         const char* name, const char* description)
01635 {
01636     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOATMAX, &param->num_rows,
01637             &param->num_cols);
01638     add_type(&type, &param->matrix, name, description);
01639 }
01640 
01641 void Parameter::add(SGMatrix<SGSparseVector<complex128_t> >* param,
01642         const char* name, const char* description)
01643 {
01644     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_COMPLEX128, &param->num_rows,
01645             &param->num_cols);
01646     add_type(&type, &param->matrix, name, description);
01647 }
01648 
01649 void Parameter::add(SGSparseMatrix<bool>* param,
01650         const char* name, const char* description)
01651 {
01652     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_BOOL, &param->num_vectors,
01653             &param->num_features);
01654     add_type(&type, &param->sparse_matrix, name, description);
01655 }
01656 
01657 void Parameter::add(SGSparseMatrix<char>* param,
01658         const char* name, const char* description)
01659 {
01660     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_CHAR, &param->num_vectors,
01661             &param->num_features);
01662     add_type(&type, &param->sparse_matrix, name, description);
01663 }
01664 
01665 void Parameter::add(SGSparseMatrix<int8_t>* param,
01666         const char* name, const char* description)
01667 {
01668     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT8, &param->num_vectors,
01669             &param->num_features);
01670     add_type(&type, &param->sparse_matrix, name, description);
01671 }
01672 
01673 void Parameter::add(SGSparseMatrix<uint8_t>* param,
01674         const char* name, const char* description)
01675 {
01676     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT8, &param->num_vectors,
01677             &param->num_features);
01678     add_type(&type, &param->sparse_matrix, name, description);
01679 }
01680 
01681 void Parameter::add(SGSparseMatrix<int16_t>* param,
01682         const char* name, const char* description)
01683 {
01684     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT16, &param->num_vectors,
01685             &param->num_features);
01686     add_type(&type, &param->sparse_matrix, name, description);
01687 }
01688 
01689 void Parameter::add(SGSparseMatrix<uint16_t>* param,
01690         const char* name, const char* description)
01691 {
01692     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT16, &param->num_vectors,
01693             &param->num_features);
01694     add_type(&type, &param->sparse_matrix, name, description);
01695 }
01696 
01697 void Parameter::add(SGSparseMatrix<int32_t>* param,
01698         const char* name, const char* description)
01699 {
01700     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT32, &param->num_vectors,
01701             &param->num_features);
01702     add_type(&type, &param->sparse_matrix, name, description);
01703 }
01704 
01705 void Parameter::add(SGSparseMatrix<uint32_t>* param,
01706         const char* name, const char* description)
01707 {
01708     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT32, &param->num_vectors,
01709             &param->num_features);
01710     add_type(&type, &param->sparse_matrix, name, description);
01711 }
01712 
01713 void Parameter::add(SGSparseMatrix<int64_t>* param,
01714         const char* name, const char* description)
01715 {
01716     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT64, &param->num_vectors,
01717             &param->num_features);
01718     add_type(&type, &param->sparse_matrix, name, description);
01719 }
01720 
01721 void Parameter::add(SGSparseMatrix<uint64_t>* param,
01722         const char* name, const char* description)
01723 {
01724     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT64, &param->num_vectors,
01725             &param->num_features);
01726     add_type(&type, &param->sparse_matrix, name, description);
01727 }
01728 
01729 void Parameter::add(SGSparseMatrix<float32_t>* param,
01730         const char* name, const char* description)
01731 {
01732     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOAT32, &param->num_vectors,
01733             &param->num_features);
01734     add_type(&type, &param->sparse_matrix, name, description);
01735 }
01736 
01737 void Parameter::add(SGSparseMatrix<float64_t>* param,
01738         const char* name, const char* description)
01739 {
01740     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOAT64, &param->num_vectors,
01741             &param->num_features);
01742     add_type(&type, &param->sparse_matrix, name, description);
01743 }
01744 
01745 void Parameter::add(SGSparseMatrix<floatmax_t>* param,
01746         const char* name, const char* description)
01747 {
01748     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOATMAX, &param->num_vectors,
01749             &param->num_features);
01750     add_type(&type, &param->sparse_matrix, name, description);
01751 }
01752 
01753 void Parameter::add(SGSparseMatrix<complex128_t>* param,
01754         const char* name, const char* description)
01755 {
01756     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_COMPLEX128, &param->num_vectors,
01757             &param->num_features);
01758     add_type(&type, &param->sparse_matrix, name, description);
01759 }
01760 
01761 void Parameter::add(SGSparseMatrix<CSGObject*>* param,
01762         const char* name, const char* description)
01763 {
01764     TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_SGOBJECT, &param->num_vectors,
01765             &param->num_features);
01766     add_type(&type, &param->sparse_matrix, name, description);
01767 }
01768 
01769 /* **************************************************************** */
01770 /* End of wrappers  */
01771 
01772 TParameter::TParameter(const TSGDataType* datatype, void* parameter,
01773                        const char* name, const char* description)
01774     :m_datatype(*datatype)
01775 {
01776     m_parameter = parameter;
01777     m_name = get_strdup(name);
01778     m_description = get_strdup(description);
01779     m_delete_data=false;
01780     m_was_allocated_from_scratch=false;
01781 }
01782 
01783 TParameter::~TParameter()
01784 {
01785 //  SG_SDEBUG("entering ~TParameter for \"%s\"\n", m_name)
01786     SG_FREE(m_description);
01787     SG_FREE(m_name);
01788 
01789     /* possibly delete content, m_parameter variable */
01790     if (m_was_allocated_from_scratch)
01791     {
01792         SG_SDEBUG("deleting from scratch data\n")
01793 
01794         if (m_delete_data)
01795         {
01796             /* for non-scalar data, delete_cont does the job, rest is handled
01797              * below */
01798             SG_SDEBUG("deleting pure data\n")
01799             if (m_datatype.m_ctype!=CT_SCALAR)
01800                 delete_cont();
01801 
01802             if (m_datatype.m_ctype==CT_SCALAR && m_datatype.m_ptype==PT_SGOBJECT)
01803                 SG_UNREF(*(CSGObject**)m_parameter);
01804         }
01805 
01806         /* free pointer/data */
01807         if (m_parameter)
01808         {
01809             SG_SDEBUG("freeing m_parameter pointer/data at %p\n", m_parameter)
01810             SG_FREE(m_parameter);
01811         }
01812 
01813         /* free lengths */
01814         if (m_datatype.m_length_x)
01815             SG_FREE(m_datatype.m_length_x);
01816 
01817         if (m_datatype.m_length_y)
01818             SG_FREE(m_datatype.m_length_y);
01819     }
01820 
01821 //  SG_SDEBUG("leaving ~TParameter\n")
01822 }
01823 
01824 char*
01825 TParameter::new_prefix(const char* s1, const char* s2)
01826 {
01827     char* tmp = SG_MALLOC(char, strlen(s1)+strlen(s2)+2);
01828 
01829     sprintf(tmp, "%s%s/", s1, s2);
01830 
01831     return tmp;
01832 }
01833 
01834 void
01835 TParameter::print(const char* prefix)
01836 {
01837     string_t buf;
01838     m_datatype.to_string(buf, STRING_LEN);
01839 
01840     SG_SPRINT("\n%s\n%35s %24s :%s\n", prefix, m_description == NULL
01841              || *m_description == '\0' ? "(Parameter)": m_description,
01842              m_name, buf);
01843 
01844     if (m_datatype.m_ptype == PT_SGOBJECT
01845         && m_datatype.m_stype == ST_NONE
01846         && m_datatype.m_ctype == CT_SCALAR
01847         && *(CSGObject**) m_parameter != NULL) {
01848         char* p = new_prefix(prefix, m_name);
01849         (*(CSGObject**) m_parameter)->print_serializable(p);
01850         delete p;
01851     }
01852 }
01853 
01854 void
01855 TParameter::delete_cont()
01856 {
01857     if (*(void**) m_parameter != NULL) {
01858         index_t old_length = m_datatype.m_length_y ? *m_datatype.m_length_y : 0;
01859         switch (m_datatype.m_ctype) {
01860         case CT_NDARRAY:
01861             SG_SNOTIMPLEMENTED
01862             break;
01863         case CT_MATRIX: case CT_SGMATRIX:
01864             old_length *= *m_datatype.m_length_x; break;
01865         case CT_SCALAR: case CT_VECTOR: case CT_SGVECTOR: break;
01866         case CT_UNDEFINED: default:
01867             SG_SERROR("Implementation error: undefined container type\n");
01868             break;
01869         }
01870 
01871         switch (m_datatype.m_stype) {
01872         case ST_NONE:
01873             switch (m_datatype.m_ptype) {
01874             case PT_BOOL:
01875                 SG_FREE(*(bool**) m_parameter); break;
01876             case PT_CHAR:
01877                 SG_FREE(*(char**) m_parameter); break;
01878             case PT_INT8:
01879                 SG_FREE(*(int8_t**) m_parameter); break;
01880             case PT_UINT8:
01881                 SG_FREE(*(uint8_t**) m_parameter); break;
01882             case PT_INT16:
01883                 SG_FREE(*(int16_t**) m_parameter); break;
01884             case PT_UINT16:
01885                 SG_FREE(*(uint16_t**) m_parameter); break;
01886             case PT_INT32:
01887                 SG_FREE(*(int32_t**) m_parameter); break;
01888             case PT_UINT32:
01889                 SG_FREE(*(uint32_t**) m_parameter); break;
01890             case PT_INT64:
01891                 SG_FREE(*(int64_t**) m_parameter); break;
01892             case PT_UINT64:
01893                 SG_FREE(*(uint64_t**) m_parameter); break;
01894             case PT_FLOAT32:
01895                 SG_FREE(*(float32_t**) m_parameter); break;
01896             case PT_FLOAT64:
01897                 SG_FREE(*(float64_t**) m_parameter); break;
01898             case PT_FLOATMAX:
01899                 SG_FREE(*(floatmax_t**) m_parameter); break;
01900             case PT_COMPLEX128:
01901                 SG_FREE(*(complex128_t**) m_parameter); break;
01902             case PT_SGOBJECT:
01903             {
01904                 CSGObject** buf = *(CSGObject***) m_parameter;
01905 
01906                 for (index_t i=0; i<old_length; i++)
01907                     SG_UNREF(buf[i]);
01908 
01909                 SG_FREE(buf);
01910                 break;
01911             }
01912             case PT_UNDEFINED: default:
01913                 SG_SERROR("Implementation error: undefined primitive type\n");
01914                 break;
01915             }
01916             break;
01917         case ST_STRING:
01918         {
01919             for (index_t i=0; i<old_length; i++) {
01920                 SGString<char>* buf = (SGString<char>*) (*(char**)
01921                         m_parameter + i *m_datatype.sizeof_stype());
01922                 if (buf->slen > 0) SG_FREE(buf->string);
01923             break;
01924         }
01925             }
01926 
01927             switch (m_datatype.m_ptype) {
01928             case PT_BOOL:
01929                 SG_FREE(*(SGString<bool>**) m_parameter); break;
01930             case PT_CHAR:
01931                 SG_FREE(*(SGString<char>**) m_parameter); break;
01932             case PT_INT8:
01933                 SG_FREE(*(SGString<int8_t>**) m_parameter); break;
01934             case PT_UINT8:
01935                 SG_FREE(*(SGString<uint8_t>**) m_parameter); break;
01936             case PT_INT16:
01937                 SG_FREE(*(SGString<int16_t>**) m_parameter); break;
01938             case PT_UINT16:
01939                 SG_FREE(*(SGString<uint16_t>**) m_parameter); break;
01940             case PT_INT32:
01941                 SG_FREE(*(SGString<int32_t>**) m_parameter); break;
01942             case PT_UINT32:
01943                 SG_FREE(*(SGString<uint32_t>**) m_parameter); break;
01944             case PT_INT64:
01945                 SG_FREE(*(SGString<int64_t>**) m_parameter); break;
01946             case PT_UINT64:
01947                 SG_FREE(*(SGString<uint64_t>**) m_parameter); break;
01948             case PT_FLOAT32:
01949                 SG_FREE(*(SGString<float32_t>**) m_parameter); break;
01950             case PT_FLOAT64:
01951                 SG_FREE(*(SGString<float64_t>**) m_parameter); break;
01952             case PT_FLOATMAX:
01953                 SG_FREE(*(SGString<floatmax_t>**) m_parameter); break;
01954             case PT_COMPLEX128:
01955                 SG_SERROR("TParameter::delete_cont(): Parameters of strings"
01956                         " of complex128_t are not supported");
01957                 break;
01958             case PT_SGOBJECT:
01959                 SG_SERROR("TParameter::delete_cont(): Implementation "
01960                          "error: Could not delete "
01961                          "String<SGSerializable*>");
01962                 break;
01963             case PT_UNDEFINED: default:
01964                 SG_SERROR("Implementation error: undefined primitive type\n");
01965                 break;
01966             }
01967             break;
01968         case ST_SPARSE:
01969             for (index_t i=0; i<old_length; i++) {
01970                 SGSparseVector<char>* buf = (SGSparseVector<char>*) (*(char**)
01971                         m_parameter + i *m_datatype.sizeof_stype());
01972                 if (buf->num_feat_entries > 0) SG_FREE(buf->features);
01973             }
01974 
01975             switch (m_datatype.m_ptype) {
01976             case PT_BOOL:
01977                 SG_FREE(*(SGSparseVector<bool>**) m_parameter); break;
01978             case PT_CHAR:
01979                 SG_FREE(*(SGSparseVector<char>**) m_parameter); break;
01980             case PT_INT8:
01981                 SG_FREE(*(SGSparseVector<int8_t>**) m_parameter); break;
01982             case PT_UINT8:
01983                 SG_FREE(*(SGSparseVector<uint8_t>**) m_parameter); break;
01984             case PT_INT16:
01985                 SG_FREE(*(SGSparseVector<int16_t>**) m_parameter); break;
01986             case PT_UINT16:
01987                 SG_FREE(*(SGSparseVector<uint16_t>**) m_parameter); break;
01988             case PT_INT32:
01989                 SG_FREE(*(SGSparseVector<int32_t>**) m_parameter); break;
01990             case PT_UINT32:
01991                 SG_FREE(*(SGSparseVector<uint32_t>**) m_parameter); break;
01992             case PT_INT64:
01993                 SG_FREE(*(SGSparseVector<int64_t>**) m_parameter); break;
01994             case PT_UINT64:
01995                 SG_FREE(*(SGSparseVector<uint64_t>**) m_parameter); break;
01996             case PT_FLOAT32:
01997                 SG_FREE(*(SGSparseVector<float32_t>**) m_parameter); break;
01998             case PT_FLOAT64:
01999                 SG_FREE(*(SGSparseVector<float64_t>**) m_parameter); break;
02000             case PT_FLOATMAX:
02001                 SG_FREE(*(SGSparseVector<floatmax_t>**) m_parameter); break;
02002             case PT_COMPLEX128:
02003                 SG_FREE(*(SGSparseVector<complex128_t>**) m_parameter); break;
02004             case PT_SGOBJECT:
02005                 SG_SERROR("TParameter::delete_cont(): Implementation "
02006                          "error: Could not delete "
02007                          "Sparse<SGSerializable*>");
02008                 break;
02009             case PT_UNDEFINED: default:
02010                 SG_SERROR("Implementation error: undefined primitive type\n");
02011                 break;
02012             }
02013             break;
02014         case ST_UNDEFINED: default:
02015             SG_SERROR("Implementation error: undefined structure type\n");
02016             break;
02017         } /* switch (m_datatype.m_stype)  */
02018     } /* if (*(void**) m_parameter != NULL)  */
02019 
02020     *(void**) m_parameter = NULL;
02021 }
02022 
02023 void
02024 TParameter::new_cont(SGVector<index_t> dims)
02025 {
02026     char* s=SG_MALLOC(char, 200);
02027     m_datatype.to_string(s, 200);
02028     SG_SDEBUG("entering TParameter::new_cont for \"%s\" of type %s with",
02029             s, m_name ? m_name : "(nil)");
02030     SG_FREE(s);
02031     delete_cont();
02032 
02033     index_t new_length = dims.product();
02034     if (new_length == 0) return;
02035 
02036     switch (m_datatype.m_stype) {
02037     case ST_NONE:
02038         switch (m_datatype.m_ptype) {
02039         case PT_BOOL:
02040             *(bool**) m_parameter
02041                 = SG_MALLOC(bool, new_length); break;
02042         case PT_CHAR:
02043             *(char**) m_parameter
02044                 = SG_MALLOC(char, new_length); break;
02045         case PT_INT8:
02046             *(int8_t**) m_parameter
02047                 = SG_MALLOC(int8_t, new_length); break;
02048         case PT_UINT8:
02049             *(uint8_t**) m_parameter
02050                 = SG_MALLOC(uint8_t, new_length); break;
02051         case PT_INT16:
02052             *(int16_t**) m_parameter
02053                 = SG_MALLOC(int16_t, new_length); break;
02054         case PT_UINT16:
02055             *(uint16_t**) m_parameter
02056                 = SG_MALLOC(uint16_t, new_length); break;
02057         case PT_INT32:
02058             *(int32_t**) m_parameter
02059                 = SG_MALLOC(int32_t, new_length); break;
02060         case PT_UINT32:
02061             *(uint32_t**) m_parameter
02062                 = SG_MALLOC(uint32_t, new_length); break;
02063         case PT_INT64:
02064             *(int64_t**) m_parameter
02065                 = SG_MALLOC(int64_t, new_length); break;
02066         case PT_UINT64:
02067             *(uint64_t**) m_parameter
02068                 = SG_MALLOC(uint64_t, new_length); break;
02069         case PT_FLOAT32:
02070             *(float32_t**) m_parameter
02071                 = SG_MALLOC(float32_t, new_length); break;
02072         case PT_FLOAT64:
02073             *(float64_t**) m_parameter
02074                 = SG_MALLOC(float64_t, new_length); break;
02075         case PT_FLOATMAX:
02076             *(floatmax_t**) m_parameter
02077                 = SG_MALLOC(floatmax_t, new_length); break;
02078         case PT_COMPLEX128:
02079             *(complex128_t**) m_parameter
02080                 = SG_MALLOC(complex128_t, new_length); break;
02081         case PT_SGOBJECT:
02082             *(CSGObject***) m_parameter
02083                 = SG_CALLOC(CSGObject*, new_length);
02084             break;
02085         case PT_UNDEFINED: default:
02086             SG_SERROR("Implementation error: undefined primitive type\n");
02087             break;
02088         }
02089         break;
02090     case ST_STRING:
02091         switch (m_datatype.m_ptype) {
02092         case PT_BOOL:
02093             *(SGString<bool>**) m_parameter
02094                 = SG_MALLOC(SGString<bool>, new_length); break;
02095         case PT_CHAR:
02096             *(SGString<char>**) m_parameter
02097                 = SG_MALLOC(SGString<char>, new_length); break;
02098         case PT_INT8:
02099             *(SGString<int8_t>**) m_parameter
02100                 = SG_MALLOC(SGString<int8_t>, new_length); break;
02101         case PT_UINT8:
02102             *(SGString<uint8_t>**) m_parameter
02103                 = SG_MALLOC(SGString<uint8_t>, new_length); break;
02104         case PT_INT16:
02105             *(SGString<int16_t>**) m_parameter
02106                 = SG_MALLOC(SGString<int16_t>, new_length); break;
02107         case PT_UINT16:
02108             *(SGString<uint16_t>**) m_parameter
02109                 = SG_MALLOC(SGString<uint16_t>, new_length); break;
02110         case PT_INT32:
02111             *(SGString<int32_t>**) m_parameter
02112                 = SG_MALLOC(SGString<int32_t>, new_length); break;
02113         case PT_UINT32:
02114             *(SGString<uint32_t>**) m_parameter
02115                 = SG_MALLOC(SGString<uint32_t>, new_length); break;
02116         case PT_INT64:
02117             *(SGString<int64_t>**) m_parameter
02118                 = SG_MALLOC(SGString<int64_t>, new_length); break;
02119         case PT_UINT64:
02120             *(SGString<uint64_t>**) m_parameter
02121                 = SG_MALLOC(SGString<uint64_t>, new_length); break;
02122         case PT_FLOAT32:
02123             *(SGString<float32_t>**) m_parameter
02124                 = SG_MALLOC(SGString<float32_t>, new_length); break;
02125         case PT_FLOAT64:
02126             *(SGString<float64_t>**) m_parameter
02127                 = SG_MALLOC(SGString<float64_t>, new_length); break;
02128         case PT_FLOATMAX:
02129             *(SGString<floatmax_t>**) m_parameter
02130                 = SG_MALLOC(SGString<floatmax_t>, new_length); break;
02131         case PT_COMPLEX128:
02132             SG_SERROR("TParameter::new_cont(): Implementation "
02133                      "error: Could not allocate "
02134                      "String<complex128>");
02135             break;
02136         case PT_SGOBJECT:
02137             SG_SERROR("TParameter::new_cont(): Implementation "
02138                      "error: Could not allocate "
02139                      "String<SGSerializable*>");
02140             break;
02141         case PT_UNDEFINED: default:
02142             SG_SERROR("Implementation error: undefined primitive type\n");
02143             break;
02144         }
02145         memset(*(void**) m_parameter, 0, new_length
02146                *m_datatype.sizeof_stype());
02147         break;
02148     case ST_SPARSE:
02149         switch (m_datatype.m_ptype) {
02150         case PT_BOOL:
02151             *(SGSparseVector<bool>**) m_parameter
02152                 = SG_MALLOC(SGSparseVector<bool>, new_length); break;
02153         case PT_CHAR:
02154             *(SGSparseVector<char>**) m_parameter
02155                 = SG_MALLOC(SGSparseVector<char>, new_length); break;
02156         case PT_INT8:
02157             *(SGSparseVector<int8_t>**) m_parameter
02158                 = SG_MALLOC(SGSparseVector<int8_t>, new_length); break;
02159         case PT_UINT8:
02160             *(SGSparseVector<uint8_t>**) m_parameter
02161                 = SG_MALLOC(SGSparseVector<uint8_t>, new_length); break;
02162         case PT_INT16:
02163             *(SGSparseVector<int16_t>**) m_parameter
02164                 = SG_MALLOC(SGSparseVector<int16_t>, new_length); break;
02165         case PT_UINT16:
02166             *(SGSparseVector<uint16_t>**) m_parameter
02167                 = SG_MALLOC(SGSparseVector<uint16_t>, new_length); break;
02168         case PT_INT32:
02169             *(SGSparseVector<int32_t>**) m_parameter
02170                 = SG_MALLOC(SGSparseVector<int32_t>, new_length);
02171             break;
02172         case PT_UINT32:
02173             *(SGSparseVector<uint32_t>**) m_parameter
02174                 = SG_MALLOC(SGSparseVector<uint32_t>, new_length); break;
02175         case PT_INT64:
02176             *(SGSparseVector<int64_t>**) m_parameter
02177                 = SG_MALLOC(SGSparseVector<int64_t>, new_length); break;
02178         case PT_UINT64:
02179             *(SGSparseVector<uint64_t>**) m_parameter
02180                 = SG_MALLOC(SGSparseVector<uint64_t>, new_length); break;
02181         case PT_FLOAT32:
02182             *(SGSparseVector<float32_t>**) m_parameter
02183                 = SG_MALLOC(SGSparseVector<float32_t>, new_length); break;
02184         case PT_FLOAT64:
02185             *(SGSparseVector<float64_t>**) m_parameter
02186                 = SG_MALLOC(SGSparseVector<float64_t>, new_length); break;
02187         case PT_FLOATMAX:
02188             *(SGSparseVector<floatmax_t>**) m_parameter
02189                 = SG_MALLOC(SGSparseVector<floatmax_t>, new_length); break;
02190         case PT_COMPLEX128:
02191             *(SGSparseVector<complex128_t>**) m_parameter
02192                 = SG_MALLOC(SGSparseVector<complex128_t>, new_length); break;
02193         case PT_SGOBJECT:
02194             SG_SERROR("TParameter::new_cont(): Implementation "
02195                      "error: Could not allocate "
02196                      "Sparse<SGSerializable*>");
02197             break;
02198         case PT_UNDEFINED: default:
02199             SG_SERROR("Implementation error: undefined primitive type\n");
02200             break;
02201         }
02202         break;
02203     case ST_UNDEFINED: default:
02204         SG_SERROR("Implementation error: undefined structure type\n");
02205         break;
02206     } /* switch (m_datatype.m_stype)  */
02207 
02208     s=SG_MALLOC(char, 200);
02209     m_datatype.to_string(s, 200);
02210     SG_SDEBUG("leaving TParameter::new_cont for \"%s\" of type %s\n",
02211             s, m_name ? m_name : "(nil)");
02212     SG_FREE(s);
02213 }
02214 
02215 bool
02216 TParameter::new_sgserial(CSGObject** param,
02217                          EPrimitiveType generic,
02218                          const char* sgserializable_name,
02219                          const char* prefix)
02220 {
02221     if (*param != NULL)
02222         SG_UNREF(*param);
02223 
02224     *param = new_sgserializable(sgserializable_name, generic);
02225 
02226     if (*param == NULL) {
02227         string_t buf = {'\0'};
02228 
02229         if (generic != PT_NOT_GENERIC) {
02230             buf[0] = '<';
02231             TSGDataType::ptype_to_string(buf+1, generic,
02232                                          STRING_LEN - 3);
02233             strcat(buf, ">");
02234         }
02235 
02236         SG_SWARNING("TParameter::new_sgserial(): "
02237                    "Class `C%s%s' was not listed during compiling Shogun"
02238                    " :( ...  Can not construct it for `%s%s'!",
02239                    sgserializable_name, buf, prefix, m_name);
02240 
02241         return false;
02242     }
02243 
02244     SG_REF(*param);
02245     return true;
02246 }
02247 
02248 bool
02249 TParameter::save_ptype(CSerializableFile* file, const void* param,
02250                        const char* prefix)
02251 {
02252     if (m_datatype.m_ptype == PT_SGOBJECT) {
02253         const char* sgserial_name = "";
02254         EPrimitiveType generic = PT_NOT_GENERIC;
02255 
02256         if (*(CSGObject**) param != NULL) {
02257             sgserial_name = (*(CSGObject**) param)->get_name();
02258             (*(CSGObject**) param)->is_generic(&generic);
02259         }
02260 
02261         if (!file->write_sgserializable_begin(
02262                 &m_datatype, m_name, prefix, sgserial_name, generic))
02263             return false;
02264         if (*sgserial_name != '\0') {
02265             char* p = new_prefix(prefix, m_name);
02266             bool result = (*(CSGObject**) param)
02267                 ->save_serializable(file, p);
02268             delete p;
02269             if (!result) return false;
02270         }
02271         if (!file->write_sgserializable_end(
02272                 &m_datatype, m_name, prefix, sgserial_name, generic))
02273             return false;
02274     } else
02275         if (!file->write_scalar(&m_datatype, m_name, prefix,
02276                                 param)) return false;
02277 
02278     return true;
02279 }
02280 
02281 bool
02282 TParameter::load_ptype(CSerializableFile* file, void* param,
02283                        const char* prefix)
02284 {
02285     if (m_datatype.m_ptype == PT_SGOBJECT) {
02286         string_t sgserial_name = {'\0'};
02287         EPrimitiveType generic = PT_NOT_GENERIC;
02288 
02289         if (!file->read_sgserializable_begin(
02290                 &m_datatype, m_name, prefix, sgserial_name, &generic))
02291             return false;
02292         if (*sgserial_name != '\0') {
02293             if (!new_sgserial((CSGObject**) param, generic,
02294                               sgserial_name, prefix))
02295                 return false;
02296 
02297             char* p = new_prefix(prefix, m_name);
02298             bool result = (*(CSGObject**) param)
02299                 ->load_serializable(file, p);
02300             delete p;
02301             if (!result) return false;
02302         }
02303         if (!file->read_sgserializable_end(
02304                 &m_datatype, m_name, prefix, sgserial_name, generic))
02305             return false;
02306     } else
02307         if (!file->read_scalar(&m_datatype, m_name, prefix,
02308                                param)) return false;
02309 
02310     return true;
02311 }
02312 
02313 bool
02314 TParameter::save_stype(CSerializableFile* file, const void* param,
02315                        const char* prefix)
02316 {
02317     SGString<char>* str_ptr = (SGString<char>*) param;
02318     SGSparseVector<char>* spr_ptr = (SGSparseVector<char>*) param;
02319     index_t len_real;
02320 
02321     switch (m_datatype.m_stype) {
02322     case ST_NONE:
02323         if (!save_ptype(file, param, prefix)) return false;
02324         break;
02325     case ST_STRING:
02326         len_real = str_ptr->slen;
02327         if (str_ptr->string == NULL && len_real != 0) {
02328             SG_SWARNING("Inconsistency between data structure and "
02329                        "len during saving string `%s%s'!  Continuing"
02330                        " with len=0.\n",
02331                        prefix, m_name);
02332             len_real = 0;
02333         }
02334         if (!file->write_string_begin(
02335                 &m_datatype, m_name, prefix, len_real)) return false;
02336         for (index_t i=0; i<len_real; i++) {
02337             if (!file->write_stringentry_begin(
02338                     &m_datatype, m_name, prefix, i)) return false;
02339             if (!save_ptype(file, (char*) str_ptr->string
02340                             + i *m_datatype.sizeof_ptype(), prefix))
02341                 return false;
02342             if (!file->write_stringentry_end(
02343                     &m_datatype, m_name, prefix, i)) return false;
02344         }
02345         if (!file->write_string_end(
02346                 &m_datatype, m_name, prefix, len_real)) return false;
02347         break;
02348     case ST_SPARSE:
02349         len_real = spr_ptr->num_feat_entries;
02350         if (spr_ptr->features == NULL && len_real != 0) {
02351             SG_SWARNING("Inconsistency between data structure and "
02352                        "len during saving sparse `%s%s'!  Continuing"
02353                        " with len=0.\n",
02354                        prefix, m_name);
02355             len_real = 0;
02356         }
02357         if (!file->write_sparse_begin(
02358                 &m_datatype, m_name, prefix, len_real)) return false;
02359         for (index_t i=0; i<len_real; i++) {
02360             SGSparseVectorEntry<char>* cur = (SGSparseVectorEntry<char>*)
02361                 ((char*) spr_ptr->features + i *TSGDataType
02362 				 ::sizeof_sparseentry(m_datatype.m_ptype));
02363             if (!file->write_sparseentry_begin(
02364                     &m_datatype, m_name, prefix, spr_ptr->features,
02365                     cur->feat_index, i)) return false;
02366             if (!save_ptype(file, (char*) cur + TSGDataType
02367                             ::offset_sparseentry(m_datatype.m_ptype),
02368                             prefix)) return false;
02369             if (!file->write_sparseentry_end(
02370                     &m_datatype, m_name, prefix, spr_ptr->features,
02371                     cur->feat_index, i)) return false;
02372         }
02373         if (!file->write_sparse_end(
02374                 &m_datatype, m_name, prefix, len_real)) return false;
02375         break;
02376     case ST_UNDEFINED: default:
02377         SG_SERROR("Implementation error: undefined structure type\n");
02378         break;
02379     }
02380 
02381     return true;
02382 }
02383 
02384 bool
02385 TParameter::load_stype(CSerializableFile* file, void* param,
02386                        const char* prefix)
02387 {
02388     SGString<char>* str_ptr = (SGString<char>*) param;
02389     SGSparseVector<char>* spr_ptr = (SGSparseVector<char>*) param;
02390     index_t len_real = 0;
02391 
02392     switch (m_datatype.m_stype) {
02393     case ST_NONE:
02394         if (!load_ptype(file, param, prefix)) return false;
02395         break;
02396     case ST_STRING:
02397         if (!file->read_string_begin(
02398                 &m_datatype, m_name, prefix, &len_real))
02399             return false;
02400         str_ptr->string = len_real > 0
02401             ? SG_MALLOC(char, len_real*m_datatype.sizeof_ptype()): NULL;
02402         for (index_t i=0; i<len_real; i++) {
02403             if (!file->read_stringentry_begin(
02404                     &m_datatype, m_name, prefix, i)) return false;
02405             if (!load_ptype(file, (char*) str_ptr->string
02406                             + i *m_datatype.sizeof_ptype(), prefix))
02407                 return false;
02408             if (!file->read_stringentry_end(
02409                     &m_datatype, m_name, prefix, i)) return false;
02410         }
02411         if (!file->read_string_end(
02412                 &m_datatype, m_name, prefix, len_real))
02413             return false;
02414         str_ptr->slen = len_real;
02415         break;
02416     case ST_SPARSE:
02417         if (!file->read_sparse_begin(
02418                 &m_datatype, m_name, prefix, &len_real)) return false;
02419         spr_ptr->features = len_real > 0? (SGSparseVectorEntry<char>*)
02420             SG_MALLOC(char, len_real *TSGDataType::sizeof_sparseentry(
02421                 m_datatype.m_ptype)): NULL;
02422         for (index_t i=0; i<len_real; i++) {
02423             SGSparseVectorEntry<char>* cur = (SGSparseVectorEntry<char>*)
02424                 ((char*) spr_ptr->features + i *TSGDataType
02425 				 ::sizeof_sparseentry(m_datatype.m_ptype));
02426             if (!file->read_sparseentry_begin(
02427                     &m_datatype, m_name, prefix, spr_ptr->features,
02428                     &cur->feat_index, i)) return false;
02429             if (!load_ptype(file, (char*) cur + TSGDataType
02430                             ::offset_sparseentry(m_datatype.m_ptype),
02431                             prefix)) return false;
02432             if (!file->read_sparseentry_end(
02433                     &m_datatype, m_name, prefix, spr_ptr->features,
02434                     &cur->feat_index, i)) return false;
02435         }
02436 
02437         if (!file->read_sparse_end(&m_datatype, m_name, prefix, len_real))
02438             return false;
02439 
02440         spr_ptr->num_feat_entries = len_real;
02441         break;
02442     case ST_UNDEFINED: default:
02443         SG_SERROR("Implementation error: undefined structure type\n");
02444         break;
02445     }
02446 
02447     return true;
02448 }
02449 
02450 void TParameter::get_incremental_hash(
02451         uint32_t& hash, uint32_t& carry, uint32_t& total_length)
02452 {
02453 
02454     switch (m_datatype.m_ctype)
02455     {
02456     case CT_NDARRAY:
02457         SG_SNOTIMPLEMENTED
02458         break;
02459     case CT_SCALAR:
02460     {
02461         uint8_t* data = ((uint8_t*) m_parameter);
02462         uint32_t size = m_datatype.sizeof_stype();
02463         total_length += size;
02464         CHash::IncrementalMurmurHash3(
02465                 &hash, &carry, data, size);
02466         break;
02467     }
02468     case CT_VECTOR: case CT_MATRIX: case CT_SGVECTOR: case CT_SGMATRIX:
02469     {
02470         index_t len_real_y = 0, len_real_x = 0;
02471 
02472         if (m_datatype.m_length_y)
02473             len_real_y = *m_datatype.m_length_y;
02474 
02475         else
02476             len_real_y = 1;
02477 
02478         if (*(void**) m_parameter == NULL && len_real_y != 0)
02479         {
02480             SG_SWARNING("Inconsistency between data structure and "
02481                     "len_y during hashing `%s'!  Continuing with "
02482                     "len_y=0.\n",
02483                     m_name);
02484             len_real_y = 0;
02485         }
02486 
02487         switch (m_datatype.m_ctype)
02488         {
02489         case CT_NDARRAY:
02490             SG_SNOTIMPLEMENTED
02491             break;
02492         case CT_VECTOR: case CT_SGVECTOR:
02493             len_real_x = 1;
02494             break;
02495         case CT_MATRIX: case CT_SGMATRIX:
02496             len_real_x = *m_datatype.m_length_x;
02497 
02498             if (*(void**) m_parameter == NULL && len_real_x != 0)
02499             {
02500                 SG_SWARNING("Inconsistency between data structure and "
02501                         "len_x during hashing %s'!  Continuing "
02502                         "with len_x=0.\n",
02503                         m_name);
02504                 len_real_x = 0;
02505             }
02506 
02507             if (len_real_x *len_real_y == 0)
02508                 len_real_x = len_real_y = 0;
02509 
02510             break;
02511 
02512         case CT_SCALAR: break;
02513         case CT_UNDEFINED: default:
02514             SG_SERROR("Implementation error: undefined container type\n");
02515             break;
02516         }
02517         uint32_t size = (len_real_x*len_real_y)*m_datatype.sizeof_stype();
02518 
02519         total_length += size;
02520 
02521             uint8_t* data = (*(uint8_t**) m_parameter);
02522 
02523         CHash::IncrementalMurmurHash3(
02524                 &hash, &carry, data, size);
02525         break;
02526     }
02527     case CT_UNDEFINED: default:
02528         SG_SERROR("Implementation error: undefined container type\n");
02529         break;
02530     }
02531 }
02532 
02533 bool
02534 TParameter::is_valid()
02535 {
02536     return m_datatype.get_num_elements() > 0;
02537 }
02538 
02539 bool
02540 TParameter::save(CSerializableFile* file, const char* prefix)
02541 {
02542     const int32_t buflen=100;
02543     char* buf=SG_MALLOC(char, buflen);
02544     m_datatype.to_string(buf, buflen);
02545     SG_SINFO("Saving parameter '%s' of type '%s'\n", m_name, buf)
02546     SG_FREE(buf);
02547 
02548     if (!file->write_type_begin(&m_datatype, m_name, prefix))
02549         return false;
02550 
02551     switch (m_datatype.m_ctype) {
02552     case CT_NDARRAY:
02553         SG_SNOTIMPLEMENTED
02554         break;
02555     case CT_SCALAR:
02556         if (!save_stype(file, m_parameter, prefix)) return false;
02557         break;
02558     case CT_VECTOR: case CT_MATRIX: case CT_SGVECTOR: case CT_SGMATRIX:
02559     {
02560         index_t len_real_y = 0, len_real_x = 0;
02561 
02562         len_real_y = *m_datatype.m_length_y;
02563         if (*(void**) m_parameter == NULL && len_real_y != 0) {
02564             SG_SWARNING("Inconsistency between data structure and "
02565                        "len_y during saving `%s%s'!  Continuing with "
02566                        "len_y=0.\n",
02567                        prefix, m_name);
02568             len_real_y = 0;
02569         }
02570 
02571         switch (m_datatype.m_ctype) {
02572         case CT_NDARRAY:
02573             SG_SNOTIMPLEMENTED
02574             break;
02575         case CT_VECTOR: case CT_SGVECTOR:
02576             len_real_x = 1;
02577             break;
02578         case CT_MATRIX: case CT_SGMATRIX:
02579             len_real_x = *m_datatype.m_length_x;
02580             if (*(void**) m_parameter == NULL && len_real_x != 0) {
02581                 SG_SWARNING("Inconsistency between data structure and "
02582                            "len_x during saving `%s%s'!  Continuing "
02583                            "with len_x=0.\n",
02584                            prefix, m_name);
02585                 len_real_x = 0;
02586             }
02587 
02588             if (len_real_x *len_real_y == 0)
02589                 len_real_x = len_real_y = 0;
02590 
02591             break;
02592         case CT_SCALAR: break;
02593         case CT_UNDEFINED: default:
02594             SG_SERROR("Implementation error: undefined container type\n");
02595             break;
02596         }
02597 
02598         if (!file->write_cont_begin(&m_datatype, m_name, prefix,
02599                                     len_real_y, len_real_x))
02600             return false;
02601 
02602         /* ******************************************************** */
02603 
02604         for (index_t x=0; x<len_real_x; x++)
02605             for (index_t y=0; y<len_real_y; y++) {
02606                 if (!file->write_item_begin(
02607                         &m_datatype, m_name, prefix, y, x))
02608                     return false;
02609 
02610                 if (!save_stype(
02611                         file, (*(char**) m_parameter)
02612                         + (x*len_real_y + y)*m_datatype.sizeof_stype(),
02613                         prefix)) return false;
02614                 if (!file->write_item_end(
02615                         &m_datatype, m_name, prefix, y, x))
02616                     return false;
02617             }
02618 
02619         /* ******************************************************** */
02620 
02621         if (!file->write_cont_end(&m_datatype, m_name, prefix,
02622                                   len_real_y, len_real_x))
02623             return false;
02624 
02625         break;
02626     }
02627     case CT_UNDEFINED: default:
02628         SG_SERROR("Implementation error: undefined container type\n");
02629         break;
02630     }
02631 
02632     if (!file->write_type_end(&m_datatype, m_name, prefix))
02633         return false;
02634 
02635     return true;
02636 }
02637 
02638 bool
02639 TParameter::load(CSerializableFile* file, const char* prefix)
02640 {
02641     const int32_t buflen=100;
02642     char* buf=SG_MALLOC(char, buflen);
02643     m_datatype.to_string(buf, buflen);
02644     SG_SDEBUG("Loading parameter '%s' of type '%s'\n", m_name, buf)
02645     SG_FREE(buf);
02646 
02647     if (!file->read_type_begin(&m_datatype, m_name, prefix))
02648         return false;
02649 
02650     switch (m_datatype.m_ctype)
02651     {
02652         case CT_NDARRAY:
02653             SG_SNOTIMPLEMENTED
02654             break;
02655         case CT_SCALAR:
02656             if (!load_stype(file, m_parameter, prefix))
02657                 return false;
02658             break;
02659 
02660         case CT_VECTOR: case CT_MATRIX: case CT_SGVECTOR: case CT_SGMATRIX:
02661         {
02662             SGVector<index_t> dims(2);
02663             dims.zero();
02664 
02665             if (!file->read_cont_begin(&m_datatype, m_name, prefix,
02666                         &dims.vector[1], &dims.vector[0]))
02667                 return false;
02668 
02669             switch (m_datatype.m_ctype)
02670             {
02671                 case CT_NDARRAY:
02672                     SG_SNOTIMPLEMENTED
02673                     break;
02674                 case CT_VECTOR: case CT_SGVECTOR:
02675                     dims[0]=1;
02676                     new_cont(dims);
02677                     break;
02678                 case CT_MATRIX: case CT_SGMATRIX:
02679                     new_cont(dims);
02680                     break;
02681                 case CT_SCALAR:
02682                     break;
02683                 case CT_UNDEFINED: default:
02684                     SG_SERROR("Implementation error: undefined container type\n");
02685                     break;
02686             }
02687 
02688             for (index_t x=0; x<dims[0]; x++)
02689             {
02690                 for (index_t y=0; y<dims[1]; y++)
02691                 {
02692                     if (!file->read_item_begin(
02693                                 &m_datatype, m_name, prefix, y, x))
02694                         return false;
02695 
02696                     if (!load_stype(
02697                                 file, (*(char**) m_parameter)
02698                                 + (x*dims[1] + y)*m_datatype.sizeof_stype(),
02699                                 prefix)) return false;
02700                     if (!file->read_item_end(
02701                                 &m_datatype, m_name, prefix, y, x))
02702                         return false;
02703                 }
02704             }
02705 
02706             switch (m_datatype.m_ctype)
02707             {
02708                 case CT_NDARRAY:
02709                     SG_SNOTIMPLEMENTED
02710                     break;
02711                 case CT_VECTOR: case CT_SGVECTOR:
02712                     *m_datatype.m_length_y = dims[1];
02713                     break;
02714                 case CT_MATRIX: case CT_SGMATRIX:
02715                     *m_datatype.m_length_y = dims[1];
02716                     *m_datatype.m_length_x = dims[0];
02717                     break;
02718                 case CT_SCALAR:
02719                     break;
02720                 case CT_UNDEFINED: default:
02721                     SG_SERROR("Implementation error: undefined container type\n");
02722                     break;
02723             }
02724 
02725             if (!file->read_cont_end(&m_datatype, m_name, prefix,
02726                         dims[1], dims[0]))
02727                 return false;
02728 
02729             break;
02730         }
02731         case CT_UNDEFINED: default:
02732             SG_SERROR("Implementation error: undefined container type\n");
02733             break;
02734     }
02735 
02736     if (!file->read_type_end(&m_datatype, m_name, prefix))
02737         return false;
02738 
02739     return true;
02740 }
02741 
02742 /*
02743   Initializing m_params(1) with small preallocation-size, because Parameter
02744   will be constructed several times for EACH SGObject instance.
02745  */
02746 Parameter::Parameter() : m_params(1)
02747 {
02748     SG_REF(sg_io);
02749 }
02750 
02751 Parameter::~Parameter()
02752 {
02753     for (int32_t i=0; i<get_num_parameters(); i++)
02754         delete m_params.get_element(i);
02755 
02756     SG_UNREF(sg_io);
02757 }
02758 
02759 void
02760 Parameter::add_type(const TSGDataType* type, void* param,
02761                      const char* name, const char* description)
02762 {
02763     if (name == NULL || *name == '\0')
02764         SG_SERROR("FATAL: Parameter::add_type(): `name' is empty!\n")
02765 
02766     for (size_t i=0; i<strlen(name); ++i)
02767     {
02768         if (!std::isalnum(name[i]) && name[i]!='_' && name[i]!='.')
02769         {
02770             SG_SERROR("Character %d of parameter with name \"%s\" is illegal "
02771                     "(only alnum or underscore is allowed)\n",
02772                     i, name);
02773         }
02774     }
02775 
02776     for (int32_t i=0; i<get_num_parameters(); i++)
02777         if (strcmp(m_params.get_element(i)->m_name, name) == 0)
02778             SG_SERROR("FATAL: Parameter::add_type(): "
02779                      "Double parameter `%s'!\n", name);
02780 
02781     m_params.append_element(
02782         new TParameter(type, param, name, description)
02783         );
02784 }
02785 
02786 void
02787 Parameter::print(const char* prefix)
02788 {
02789     for (int32_t i=0; i<get_num_parameters(); i++)
02790         m_params.get_element(i)->print(prefix);
02791 }
02792 
02793 bool
02794 Parameter::save(CSerializableFile* file, const char* prefix)
02795 {
02796     for (int32_t i=0; i<get_num_parameters(); i++)
02797     {
02798         if (!m_params.get_element(i)->save(file, prefix))
02799             return false;
02800     }
02801 
02802     return true;
02803 }
02804 
02805 //bool
02806 //Parameter::load(CSerializableFile* file, const char* prefix)
02807 //{
02808 //  for (int32_t i=0; i<get_num_parameters(); i++)
02809 //      if (!m_params.get_element(i)->load(file, prefix))
02810 //          return false;
02811 //
02812 //  return true;
02813 //}
02814 
02815 void Parameter::set_from_parameters(Parameter* params)
02816 {
02817     /* iterate over parameters in the given list */
02818     for (index_t i=0; i<params->get_num_parameters(); ++i)
02819     {
02820         TParameter* current=params->get_parameter(i);
02821         TSGDataType current_type=current->m_datatype;
02822 
02823         ASSERT(m_params.get_num_elements())
02824 
02825         /* search for own parameter with same name and check types if found */
02826         TParameter* own=NULL;
02827         for (index_t j=0; j<m_params.get_num_elements(); ++j)
02828         {
02829             own=m_params.get_element(j);
02830             if (!strcmp(own->m_name, current->m_name))
02831             {
02832                 if (own->m_datatype==current_type)
02833                 {
02834                     own=m_params.get_element(j);
02835                     break;
02836                 }
02837                 else
02838                 {
02839                     index_t l=200;
02840                     char* given_type=SG_MALLOC(char, l);
02841                     char* own_type=SG_MALLOC(char, l);
02842                     current->m_datatype.to_string(given_type, l);
02843                     own->m_datatype.to_string(own_type, l);
02844                     SG_SERROR("given parameter \"%s\" has a different type (%s)"
02845                             " than existing one (%s)\n", current->m_name,
02846                             given_type, own_type);
02847                     SG_FREE(given_type);
02848                     SG_FREE(own_type);
02849                 }
02850             }
02851             else
02852                 own=NULL;
02853         }
02854 
02855         if (!own)
02856         {
02857             SG_SERROR("parameter with name %s does not exist\n",
02858                     current->m_name);
02859         }
02860 
02861         /* check if parameter contained CSGobjects (update reference counts) */
02862         if (current_type.m_ptype==PT_SGOBJECT)
02863         {
02864             /* PT_SGOBJECT only occurs for ST_NONE */
02865             if (own->m_datatype.m_stype==ST_NONE)
02866             {
02867                 if (own->m_datatype.m_ctype==CT_SCALAR)
02868                 {
02869                     CSGObject** to_unref=(CSGObject**) own->m_parameter;
02870                     CSGObject** to_ref=(CSGObject**) current->m_parameter;
02871 
02872                     if ((*to_ref)!=(*to_unref))
02873                     {
02874                         SG_REF((*to_ref));
02875                         SG_UNREF((*to_unref));
02876                     }
02877 
02878                 }
02879                 else
02880                 {
02881                     /* unref all SGObjects and reference the new ones */
02882                     CSGObject*** to_unref=(CSGObject***) own->m_parameter;
02883                     CSGObject*** to_ref=(CSGObject***) current->m_parameter;
02884 
02885                     for (index_t j=0; j<own->m_datatype.get_num_elements(); ++j)
02886                     {
02887                         if ((*to_ref)[j]!=(*to_unref)[j])
02888                         {
02889                             SG_REF(((*to_ref)[j]));
02890                             SG_UNREF(((*to_unref)[j]));
02891                         }
02892                     }
02893                 }
02894             }
02895             else
02896                 SG_SERROR("primitive type PT_SGOBJECT occurred with structure "
02897                         "type other than ST_NONE");
02898         }
02899 
02900         /* construct pointers to the to be copied parameter data */
02901         void* dest=NULL;
02902         void* source=NULL;
02903         if (current_type.m_ctype==CT_SCALAR)
02904         {
02905             /* for scalar values, just copy content the pointer points to */
02906             dest=own->m_parameter;
02907             source=current->m_parameter;
02908 
02909             /* in case of CSGObject, pointers are not equal if CSGObjects are
02910              * equal, so check. For other values, the pointers are equal and
02911              * the not-copying is handled below before the memcpy call */
02912             if (own->m_datatype.m_ptype==PT_SGOBJECT)
02913             {
02914                 if (*((CSGObject**)dest) == *((CSGObject**)source))
02915                 {
02916                     dest=NULL;
02917                     source=NULL;
02918                 }
02919             }
02920         }
02921         else
02922         {
02923             /* for matrices and vectors, sadly m_parameter has to be
02924              * de-referenced once, because a pointer to the array address is
02925              * saved, but the array address itself has to be copied.
02926              * consequently, for dereferencing, a type distinction is needed */
02927             switch (own->m_datatype.m_ptype)
02928             {
02929             case PT_FLOAT64:
02930                 dest=*((float64_t**) own->m_parameter);
02931                 source=*((float64_t**) current->m_parameter);
02932                 break;
02933             case PT_SGOBJECT:
02934                 dest=*((CSGObject**) own->m_parameter);
02935                 source=*((CSGObject**) current->m_parameter);
02936                 break;
02937             default:
02938                 SG_SNOTIMPLEMENTED
02939                 break;
02940             }
02941         }
02942 
02943         /* copy parameter data, size in memory is equal because of same type */
02944         if (dest!=source)
02945             memcpy(dest, source, own->m_datatype.get_size());
02946     }
02947 }
02948 
02949 void Parameter::add_parameters(Parameter* params)
02950 {
02951     for (index_t i=0; i<params->get_num_parameters(); ++i)
02952     {
02953         TParameter* current=params->get_parameter(i);
02954         add_type(&(current->m_datatype), current->m_parameter, current->m_name,
02955                 current->m_description);
02956     }
02957 }
02958 
02959 bool Parameter::contains_parameter(const char* name)
02960 {
02961     for (index_t i=0; i<m_params.get_num_elements(); ++i)
02962     {
02963         if (!strcmp(name, m_params[i]->m_name))
02964             return true;
02965     }
02966 
02967     return false;
02968 }
02969 
02970 bool TParameter::operator==(const TParameter& other) const
02971 {
02972     bool result=true;
02973     result&=!strcmp(m_name, other.m_name);
02974     return result;
02975 }
02976 
02977 bool TParameter::operator<(const TParameter& other) const
02978 {
02979     return strcmp(m_name, other.m_name)<0;
02980 }
02981 
02982 bool TParameter::operator>(const TParameter& other) const
02983 {
02984     return strcmp(m_name, other.m_name)>0;
02985 }
02986 
02987 void TParameter::allocate_data_from_scratch(SGVector<index_t> dims,
02988         bool new_cont_call)
02989 {
02990     SG_SDEBUG("entering TParameter::allocate_data_from_scratch of "
02991             "\"%s\"\n", m_name);
02992 
02993     /* set flag to delete all this stuff later on */
02994     m_was_allocated_from_scratch=true;
02995 
02996     /* length has to be allocated for matrices/vectors */
02997     switch (m_datatype.m_ctype)
02998     {
02999     case CT_VECTOR: case CT_SGVECTOR:
03000         m_datatype.m_length_y=SG_MALLOC(index_t, 1);
03001         *m_datatype.m_length_y=dims[1];
03002         break;
03003     case CT_MATRIX: case CT_SGMATRIX:
03004         m_datatype.m_length_x=SG_MALLOC(index_t, 1);
03005         m_datatype.m_length_y=SG_MALLOC(index_t, 1);
03006         *m_datatype.m_length_y=dims[1];
03007         *m_datatype.m_length_x=dims[0];
03008         break;
03009     case CT_SCALAR:
03010         m_datatype.m_length_x=NULL;
03011         m_datatype.m_length_y=NULL;
03012         break;
03013     case CT_NDARRAY:
03014         SG_SNOTIMPLEMENTED
03015         break;
03016     case CT_UNDEFINED: default:
03017         SG_SERROR("Implementation error: undefined container type\n");
03018         break;
03019     }
03020 
03021     /* check if there is no data loss */
03022     if (m_parameter)
03023         SG_SERROR("TParameter::allocate_data_from_scratch must not be called "
03024                 "when the underlying TParameter instance already has data.\n");
03025 
03026     /* scalars are treated differently than vectors/matrices. memory has to
03027      * be allocated for the data itself */
03028     if (m_datatype.m_ctype==CT_SCALAR)
03029     {
03030         /* sgobjects are treated differently than the rest */
03031         if (m_datatype.m_ptype!=PT_SGOBJECT)
03032         {
03033             /* for non-sgobject allocate memory because normally they are on
03034              * stack and excluded in the TParameter data allocation.
03035              * Will be deleted by the TParameter destructor */
03036             m_parameter=SG_MALLOC(char, m_datatype.get_size());
03037         }
03038         else
03039         {
03040             /* for sgobjects, allocate memory for pointer and set to NULL
03041              * Will be deleted by the TParameter destructor */
03042             m_parameter=SG_MALLOC(CSGObject**, 1);
03043             *((CSGObject**)m_parameter)=NULL;
03044         }
03045     }
03046     else
03047     {
03048         /* allocate pointer for data pointer */
03049         void** data_p=SG_MALLOC(void*, 1);
03050         *data_p=NULL;
03051 
03052         /* allocate dummy data at the point the above pointer points to
03053          * will be freed by the delete_cont() method of TParameter.
03054          * This is needed because new_cont/delete_cont cannot handle
03055          * non-existing data. Set to NULL to avoid problems */
03056         if (new_cont_call)
03057         {
03058             *data_p=SG_MALLOC(void**, 1);
03059             **(void***)data_p=NULL;
03060         }
03061 
03062         m_parameter=data_p;
03063 
03064         /* perform one data allocation. This may be repeated and therefore
03065          * redundant if load() is called afterwards, however, if one wants
03066          * to write directly to the array data after this call, it is
03067          * necessary */
03068         if (new_cont_call)
03069             new_cont(dims);
03070     }
03071 
03072     SG_SDEBUG("leaving TParameter::allocate_data_from_scratch of "
03073                 "\"%s\"\n", m_name);
03074 }
03075 
03076 void TParameter::copy_data(const TParameter* source)
03077 {
03078     SG_SDEBUG("entering TParameter::copy_data for %s\n", m_name)
03079 
03080     /* assert that type is equal */
03081     ASSERT(m_datatype.m_ctype==source->m_datatype.m_ctype)
03082     ASSERT(m_datatype.m_stype==source->m_datatype.m_stype)
03083     ASSERT(m_datatype.m_ptype==source->m_datatype.m_ptype)
03084 
03085     /* first delete old data if non-scalar */
03086     if (m_datatype.m_ctype!=CT_SCALAR)
03087         delete_cont();
03088 
03089     /* then copy data in case of numeric scalars, or pointer to data else */
03090     if (m_datatype.m_ctype==CT_SCALAR && m_datatype.m_ptype!=PT_SGOBJECT)
03091     {
03092         /* just copy value behind pointer */
03093         SG_SDEBUG("Copying scalar data of size %d from %p to %p\n",
03094                 m_datatype.get_size(), source->m_parameter, m_parameter);
03095         memcpy(m_parameter, source->m_parameter,
03096                 m_datatype.get_size());
03097     }
03098     else
03099     {
03100         /* if this is a sgobject, the old one has to be unrefed */
03101         if (m_datatype.m_ptype==PT_SGOBJECT)
03102         {
03103             if (m_datatype.m_ctype==CT_SCALAR)
03104             {
03105                 SG_UNREF(*((CSGObject**)m_parameter));
03106             }
03107             else
03108             {
03109                 int32_t length=1;
03110                 length*=m_datatype.m_length_x ? *m_datatype.m_length_x : 1;
03111                 length*=m_datatype.m_length_y ? *m_datatype.m_length_y : 1;
03112 
03113                 for (index_t j=0; j<length; ++j)
03114                 {
03115                     SG_UNREF(((CSGObject**)(m_parameter))[j]);
03116                 }
03117             }
03118         }
03119 
03120         /* in this case, data is a pointer pointing to the actual
03121          * data, so copy pointer if non-NULL*/
03122         SG_SDEBUG("Copying non-scalar pointer %p\n", *((void**)source->m_parameter))
03123         *((void**)m_parameter)=*((void**)source->m_parameter);
03124     }
03125 
03126     /* copy lengths */
03127     if (source->m_datatype.m_length_x)
03128         *m_datatype.m_length_x=*source->m_datatype.m_length_x;
03129 
03130     if (source->m_datatype.m_length_y)
03131         *m_datatype.m_length_y=*source->m_datatype.m_length_y;
03132 
03133     SG_SDEBUG("leaving TParameter::copy_data for %s\n", m_name)
03134 }
03135 
03136 bool TParameter::equals(TParameter* other, float64_t accuracy)
03137 {
03138     SG_SDEBUG("entering TParameter::equals()\n");
03139 
03140     if (!other)
03141     {
03142         SG_SDEBUG("leaving TParameter::equals(): other parameter is NULL\n");
03143         return false;
03144     }
03145 
03146     if (strcmp(m_name, other->m_name))
03147     {
03148         SG_SDEBUG("leaving TParameter::equals(): name \"%s\" is different from"
03149                 " other parameter's name \"%s\"\n", m_name, other->m_name);
03150         return false;
03151     }
03152 
03153     SG_SDEBUG("Comparing datatypes\n");
03154     if (!(m_datatype.equals(other->m_datatype)))
03155     {
03156         SG_SDEBUG("leaving TParameter::equals(): type of \"%s\" is different "
03157                 "from other parameter's \"%s\" type\n", m_name, other->m_name);
03158         return false;
03159     }
03160 
03161     /* avoid comparing NULL */
03162     if (!m_parameter && !other->m_parameter)
03163     {
03164         SG_SDEBUG("leaving TParameter::equals(): both parameters are NULL\n");
03165         return true;
03166     }
03167 
03168     if ((!m_parameter && other->m_parameter) || (m_parameter && !other->m_parameter))
03169     {
03170         SG_SDEBUG("leaving TParameter::equals(): param1 is at %p while "
03171                 "param2 is at %p\n", m_parameter, other->m_parameter);
03172         return false;
03173     }
03174 
03175     SG_SDEBUG("Comparing ctype\n");
03176     switch (m_datatype.m_ctype)
03177     {
03178         case CT_SCALAR:
03179         {
03180             SG_SDEBUG("CT_SCALAR\n");
03181             if (!TParameter::compare_stype(m_datatype.m_stype,
03182                     m_datatype.m_ptype, m_parameter,
03183                     other->m_parameter,
03184                     accuracy))
03185             {
03186                 SG_SDEBUG("leaving TParameter::equals(): scalar data differs\n");
03187                 return false;
03188             }
03189             break;
03190         }
03191         case CT_VECTOR: case CT_SGVECTOR:
03192         {
03193             SG_SDEBUG("CT_VECTOR or CT_SGVECTOR\n");
03194 
03195             /* x is number of processed bytes */
03196             index_t x=0;
03197             SG_SDEBUG("length_y: %d\n", *m_datatype.m_length_y)
03198             for (index_t i=0; i<*m_datatype.m_length_y; ++i)
03199             {
03200                 SG_SDEBUG("comparing element %d which is %d bytes from start\n",
03201                         i, x);
03202 
03203                 void* pointer_a=&((*(char**)m_parameter)[x]);
03204                 void* pointer_b=&((*(char**)other->m_parameter)[x]);
03205 
03206                 if (!TParameter::compare_stype(m_datatype.m_stype,
03207                         m_datatype.m_ptype, pointer_a, pointer_b, accuracy))
03208                 {
03209                     SG_SDEBUG("leaving TParameter::equals(): vector element "
03210                             "differs\n");
03211                     return false;
03212                 }
03213 
03214                 x=x+(m_datatype.sizeof_stype());
03215             }
03216 
03217             break;
03218         }
03219         case CT_MATRIX: case CT_SGMATRIX:
03220         {
03221             SG_SDEBUG("CT_MATRIX or CT_SGMATRIX\n");
03222 
03223             /* x is number of processed bytes */
03224             index_t x=0;
03225             SG_SDEBUG("length_y: %d\n", *m_datatype.m_length_y)
03226             SG_SDEBUG("length_x: %d\n", *m_datatype.m_length_x)
03227             int64_t length=0;
03228 
03229             /* For ST_SPARSE, we just need to loop over the rows and compare_stype
03230              * does the comparison for one whole row vector at once. For ST_NONE,
03231              * however, we need to loop over all elements.
03232              */
03233             if (m_datatype.m_stype==ST_SPARSE)
03234                 length=(*m_datatype.m_length_y);
03235             else
03236                 length=(*m_datatype.m_length_y) * (*m_datatype.m_length_x);
03237 
03238             for (index_t i=0; i<length; ++i)
03239             {
03240                 SG_SDEBUG("comparing element %d which is %d byes from start\n",
03241                         i, x);
03242 
03243                 void* pointer_a=&((*(char**)m_parameter)[x]);
03244                 void* pointer_b=&((*(char**)other->m_parameter)[x]);
03245 
03246                 if (!TParameter::compare_stype(m_datatype.m_stype,
03247                         m_datatype.m_ptype, pointer_a, pointer_b, accuracy))
03248                 {
03249                     SG_SDEBUG("leaving TParameter::equals(): vector element "
03250                             "differs\n");
03251                     return false;
03252                 }
03253 
03254                 /* For ST_SPARSE, the iteration is on the pointer of SGSparseVectors */
03255                 if (m_datatype.m_stype==ST_SPARSE)
03256                     x=x+(m_datatype.sizeof_stype());
03257                 else
03258                     x=x+(m_datatype.sizeof_stype());
03259             }
03260 
03261             break;
03262         }
03263         case CT_NDARRAY:
03264         {
03265             SG_SDEBUG("CT_NDARRAY\n");
03266             SG_SERROR("TParameter::equals(): Not yet implemented for "
03267                     "CT_NDARRAY!\n");
03268             break;
03269         }
03270         case CT_UNDEFINED: default:
03271             SG_SERROR("Implementation error: undefined container type\n");
03272             break;
03273     }
03274 
03275     SG_SDEBUG("leaving TParameter::equals(): Parameters are equal\n");
03276     return true;
03277 }
03278 
03279 bool TParameter::compare_ptype(EPrimitiveType ptype, void* data1, void* data2,
03280             floatmax_t accuracy)
03281 {
03282     SG_SDEBUG("entering TParameter::compare_ptype()\n");
03283 
03284     if ((data1 && !data2) || (!data1 && data2))
03285     {
03286         SG_SINFO("leaving TParameter::compare_ptype(): data1 is at %p while "
03287                 "data2 is at %p\n", data1, data2);
03288         return false;
03289     }
03290 
03292     if (!data1 && !data2)
03293     {
03294         SG_SDEBUG("leaving TParameter::compare_ptype(): both data are NULL\n");
03295         return true;
03296     }
03297 
03298     switch (ptype)
03299     {
03300     case PT_BOOL:
03301     {
03302         bool casted1=*((bool*)data1);
03303         bool casted2=*((bool*)data2);
03304 
03305         if (CMath::abs(casted1-casted2)>accuracy)
03306         {
03307             SG_SINFO("leaving TParameter::compare_ptype(): PT_BOOL: "
03308                     "data1=%d, data2=%d\n", casted1, casted2);
03309             return false;
03310         }
03311         break;
03312     }
03313     case PT_CHAR:
03314     {
03315         char casted1=*((char*)data1);
03316         char casted2=*((char*)data2);
03317 
03318         if (CMath::abs(casted1-casted2)>accuracy)
03319         {
03320             SG_SINFO("leaving TParameter::compare_ptype(): PT_CHAR: "
03321                     "data1=%c, data2=%c\n", casted1, casted2);
03322             return false;
03323         }
03324         break;
03325     }
03326     case PT_INT8:
03327     {
03328         int8_t casted1=*((int8_t*)data1);
03329         int8_t casted2=*((int8_t*)data2);
03330 
03331         if (CMath::abs(casted1-casted2)>accuracy)
03332         {
03333             SG_SINFO("leaving TParameter::compare_ptype(): PT_INT8: "
03334                     "data1=%d, data2=%d\n", casted1, casted2);
03335             return false;
03336         }
03337         break;
03338     }
03339     case PT_UINT8:
03340     {
03341         uint8_t casted1=*((uint8_t*)data1);
03342         uint8_t casted2=*((uint8_t*)data2);
03343 
03344         if (CMath::abs(casted1-casted2)>accuracy)
03345         {
03346             SG_SINFO("leaving TParameter::compare_ptype(): PT_UINT8: "
03347                     "data1=%d, data2=%d\n", casted1, casted2);
03348             return false;
03349         }
03350         break;
03351     }
03352     case PT_INT16:
03353     {
03354         int16_t casted1=*((int16_t*)data1);
03355         int16_t casted2=*((int16_t*)data2);
03356 
03357         if (CMath::abs(casted1-casted2)>accuracy)
03358         {
03359             SG_SINFO("leaving TParameter::compare_ptype(): PT_INT16: "
03360                     "data1=%d, data2=%d\n", casted1, casted2);
03361             return false;
03362         }
03363         break;
03364     }
03365     case PT_UINT16:
03366     {
03367         uint16_t casted1=*((uint16_t*)data1);
03368         uint16_t casted2=*((uint16_t*)data2);
03369 
03370         if (CMath::abs(casted1-casted2)>accuracy)
03371         {
03372             SG_SINFO("leaving TParameter::compare_ptype(): PT_UINT16: "
03373                     "data1=%d, data2=%d\n", casted1, casted2);
03374             return false;
03375         }
03376         break;
03377     }
03378     case PT_INT32:
03379     {
03380         int32_t casted1=*((int32_t*)data1);
03381         int32_t casted2=*((int32_t*)data2);
03382 
03383         if (CMath::abs(casted1-casted2)>accuracy)
03384         {
03385             SG_SINFO("leaving TParameter::compare_ptype(): PT_INT32: "
03386                     "data1=%d, data2=%d\n", casted1, casted2);
03387             return false;
03388         }
03389         break;
03390     }
03391     case PT_UINT32:
03392     {
03393         uint32_t casted1=*((uint32_t*)data1);
03394         uint32_t casted2=*((uint32_t*)data2);
03395 
03396         if (CMath::abs(casted1-casted2)>accuracy)
03397         {
03398             SG_SINFO("leaving TParameter::compare_ptype(): PT_UINT32: "
03399                     "data1=%d, data2=%d\n", casted1, casted2);
03400             return false;
03401         }
03402         break;
03403     }
03404     case PT_INT64:
03405     {
03406         int64_t casted1=*((int64_t*)data1);
03407         int64_t casted2=*((int64_t*)data2);
03408 
03409         if (CMath::abs(casted1-casted2)>accuracy)
03410         {
03411             SG_SINFO("leaving TParameter::compare_ptype(): PT_INT64: "
03412                     "data1=%d, data2=%d\n", casted1, casted2);
03413             return false;
03414         }
03415         break;
03416     }
03417     case PT_UINT64:
03418     {
03419         uint64_t casted1=*((uint64_t*)data1);
03420         uint64_t casted2=*((uint64_t*)data2);
03421 
03422         if (CMath::abs(casted1-casted2)>accuracy)
03423         {
03424             SG_SINFO("leaving TParameter::compare_ptype(): PT_UINT64: "
03425                     "data1=%d, data2=%d\n", casted1, casted2);
03426             return false;
03427         }
03428         break;
03429     }
03430     case PT_FLOAT32:
03431     {
03432         float32_t casted1=*((float32_t*)data1);
03433         float32_t casted2=*((float32_t*)data2);
03434 
03435         if (CMath::abs(casted1-casted2)>accuracy)
03436         {
03437             SG_SINFO("leaving TParameter::compare_ptype(): PT_FLOAT32: "
03438                     "data1=%f, data2=%f\n", casted1, casted2);
03439             return false;
03440         }
03441         break;
03442     }
03443     case PT_FLOAT64:
03444     {
03445         float64_t casted1=*((float64_t*)data1);
03446         float64_t casted2=*((float64_t*)data2);
03447 
03448         if (CMath::abs(casted1-casted2)>accuracy)
03449         {
03450             SG_SINFO("leaving TParameter::compare_ptype(): PT_FLOAT64: "
03451                     "data1=%f, data2=%f\n", casted1, casted2);
03452             return false;
03453         }
03454         break;
03455     }
03456     case PT_FLOATMAX:
03457     {
03458         floatmax_t casted1=*((floatmax_t*)data1);
03459         floatmax_t casted2=*((floatmax_t*)data2);
03460         if (CMath::abs(casted1-casted2)>accuracy)
03461         {
03462             SG_SINFO("leaving TParameter::compare_ptype(): PT_FLOATMAX: "
03463                     "data1=%f, data2=%f\n", casted1, casted2);
03464             return false;
03465         }
03466         break;
03467     }
03468     case PT_COMPLEX128:
03469     {
03470         float64_t casted1_real=((complex128_t*)data1)->real();
03471         float64_t casted1_imag=((complex128_t*)data1)->imag();
03472         float64_t casted2_real=((complex128_t*)data2)->real();
03473         float64_t casted2_imag=((complex128_t*)data2)->imag();
03474         if (CMath::abs(casted1_real-casted2_real)>accuracy ||
03475             CMath::abs(casted1_imag-casted2_imag)>accuracy)
03476         {
03477             SG_SINFO("leaving TParameter::compare_ptype(): PT_COMPLEX128: "
03478                     "data1=%f+i%f, data2=%f+i%f\n",
03479                     casted1_real, casted1_imag,
03480                     casted2_real, casted2_imag);
03481             return false;
03482         }
03483         break;
03484     }
03485     case PT_SGOBJECT:
03486     {
03487         CSGObject* casted1=*((CSGObject**)data1);
03488         CSGObject* casted2=*((CSGObject**)data2);
03489 
03490         /* important not to call methods on NULL */
03491         if (!casted1 && ! casted2)
03492         {
03493             SG_SDEBUG("leaving TParameter::compare_ptype(): SGObjects are equal\n");
03494             return true;
03495         }
03496 
03497         /* make sure to not call NULL methods */
03498         if (casted1)
03499         {
03500             if (!(casted1->equals(casted2, accuracy)))
03501             {
03502                 SG_SINFO("leaving TParameter::compare_ptype(): PT_SGOBJECT "
03503                         "equals returned false\n");
03504                 return false;
03505             }
03506         }
03507         else
03508         {
03509             if (!(casted2->equals(casted1, accuracy)))
03510             {
03511                 SG_SINFO("leaving TParameter::compare_ptype(): PT_SGOBJECT "
03512                         "equals returned false\n");
03513                 return false;
03514             }
03515 
03516         }
03517         break;
03518     }
03519     default:
03520         SG_SERROR("TParameter::compare_ptype(): Encountered unknown primitive"
03521                 "-type: %d\n", ptype);
03522         break;
03523     }
03524 
03525     SG_SDEBUG("leaving TParameter::compare_ptype(): Data are equal\n");
03526     return true;
03527 }
03528 
03529 bool TParameter::copy_ptype(EPrimitiveType ptype, void* source, void* target)
03530 {
03531     SG_SDEBUG("entering TParameter::copy_ptype()\n");
03532 
03533     /* rather than using memcpy, use the cumbersome way here and cast all types.
03534      * This makes it so much easier to debug code.
03535      * Copy full stype if this is too slow */
03536     switch (ptype)
03537     {
03538     case PT_BOOL:
03539     {
03540         *((bool*)target)=*((bool*)source);
03541         SG_SDEBUG("after copy of ptype PT_BOOL: source %d, target %d\n",
03542                 *((bool*)source), *((bool*)target));
03543         break;
03544     }
03545     case PT_CHAR:
03546     {
03547         *((char*)target)=*((char*)source);
03548         SG_SDEBUG("after copy of ptype PT_CHAR: source %c, target %c\n",
03549                 *((char*)source), *((char*)target));
03550         break;
03551     }
03552     case PT_INT8:
03553     {
03554         *((int8_t*)target)=*((int8_t*)source);
03555         SG_SDEBUG("after copy of ptype PT_INT8: source %d, target %d\n",
03556                 *((int8_t*)source), *((int8_t*)target));
03557         break;
03558     }
03559     case PT_UINT8:
03560     {
03561         *((uint8_t*)target)=*((uint8_t*)source);
03562         SG_SDEBUG("after copy of ptype PT_UINT8: source %d, target %d\n",
03563                 *((uint8_t*)source), *((uint8_t*)target));
03564         break;
03565     }
03566     case PT_INT16:
03567     {
03568         *((int16_t*)target)=*((int16_t*)source);
03569         SG_SDEBUG("after copy of ptype PT_INT16: source %d, target %d\n",
03570                 *((int16_t*)source), *((int16_t*)target));
03571         break;
03572     }
03573     case PT_UINT16:
03574     {
03575         *((uint16_t*)target)=*((uint16_t*)source);
03576         SG_SDEBUG("after copy of ptype PT_UINT16: source %d, target %d\n",
03577                 *((uint16_t*)source), *((uint16_t*)target));
03578         break;
03579     }
03580     case PT_INT32:
03581     {
03582         *((int32_t*)target)=*((int32_t*)source);
03583         SG_SDEBUG("after copy of ptype PT_INT32: source %d, target %d\n",
03584                 *((int32_t*)source), *((int32_t*)target));
03585         break;
03586     }
03587     case PT_UINT32:
03588     {
03589         *((uint32_t*)target)=*((uint32_t*)source);
03590         SG_SDEBUG("after copy of ptype PT_UINT32: source %d, target %d\n",
03591                 *((uint32_t*)source), *((uint32_t*)target));
03592         break;
03593     }
03594     case PT_INT64:
03595     {
03596         *((int64_t*)target)=*((int64_t*)source);
03597         SG_SDEBUG("after copy of ptype PT_INT64: source %d, target %d\n",
03598                 *((int64_t*)source), *((int64_t*)target));
03599         break;
03600     }
03601     case PT_UINT64:
03602     {
03603         *((uint64_t*)target)=*((uint64_t*)source);
03604         SG_SDEBUG("after copy of ptype PT_UINT64: source %d, target %d\n",
03605                 *((uint64_t*)source), *((uint64_t*)target));
03606         break;
03607     }
03608     case PT_FLOAT32:
03609     {
03610         *((float32_t*)target)=*((float32_t*)source);
03611         SG_SDEBUG("after copy of ptype PT_FLOAT32: source %f, target %f\n",
03612                 *((float32_t*)source), *((float32_t*)target));
03613         break;
03614     }
03615     case PT_FLOAT64:
03616     {
03617         *((float64_t*)target)=*((float64_t*)source);
03618         SG_SDEBUG("after copy of ptype PT_FLOAT64: source %f, target %f\n",
03619                 *((float64_t*)source), *((float64_t*)target));
03620         break;
03621     }
03622     case PT_FLOATMAX:
03623     {
03624         *((floatmax_t*)target)=*((floatmax_t*)source);
03625         SG_SDEBUG("after copy of ptype PT_FLOATMAX: source %Lf, target %Lf\n",
03626                 *((floatmax_t*)source), *((floatmax_t*)target));
03627         break;
03628     }
03629     case PT_COMPLEX128:
03630     {
03631         *((complex128_t*)target)=*((complex128_t*)source);
03632         SG_SDEBUG("after copy of ptype PT_COMPLEX128: "
03633                 "source real %f, target real %f,"
03634                 "source imag %f, target imag %f,"
03635                 "\n",
03636                 ((complex128_t*)source)->real(), ((complex128_t*)target)->real(),
03637                 ((complex128_t*)source)->imag(), ((complex128_t*)target)->imag());
03638         break;
03639     }
03640     case PT_SGOBJECT:
03641     {
03642         CSGObject* casted1=*((CSGObject**)source);
03643         CSGObject* casted2=*((CSGObject**)target);
03644 
03645         /* important not to call methods on NULL */
03646         if (!casted1 && ! casted2)
03647         {
03648             SG_SDEBUG("leaving TParameter::copy_ptype(): Both SGObjects are NULL\n");
03649             return true;
03650         }
03651 
03652         /* make sure to not call NULL methods */
03653         if (casted1)
03654         {
03655             /* in case of overwriting old objects */
03656             SG_UNREF(*((CSGObject**)target));
03657             *((CSGObject**)target) = casted1->clone();
03658         }
03659 
03660         break;
03661     }
03662     default:
03663         SG_SERROR("TParameter::compare_ptype(): Encountered unknown primitive"
03664                 "-type: %d\n", ptype);
03665         return false;
03666         break;
03667     }
03668 
03669     SG_SDEBUG("leaving TParameter::copy_ptype(): Copy successful\n");
03670     return true;
03671 }
03672 
03673 bool TParameter::compare_stype(EStructType stype, EPrimitiveType ptype,
03674         void* data1, void* data2, floatmax_t accuracy)
03675 {
03676     SG_SDEBUG("entering TParameter::compare_stype()\n");
03677 
03678     size_t size_ptype=TSGDataType::sizeof_ptype(ptype);
03679 
03680     /* Avoid comparing NULL */
03681     if (!data1 && !data2)
03682     {
03683         SG_SDEBUG("leaving TParameter::compare_stype(): both data are NULL\n");
03684         return true;
03685     }
03686 
03687     /* If one is NULL, data are not equal */
03688     if ((data1 && !data2) || (!data1 && data2))
03689     {
03690         SG_SINFO("leaving TParameter::compare_stype(): data1 is at %p while "
03691                 "data2 is at %p\n", data1, data2);
03692         return false;
03693     }
03694 
03695     switch (stype)
03696     {
03697         case ST_NONE:
03698         {
03699             SG_SDEBUG("ST_NONE\n");
03700             return TParameter::compare_ptype(ptype, data1, data2, accuracy);
03701             break;
03702         }
03703         case ST_SPARSE:
03704         {
03705             SG_SDEBUG("ST_SPARSE\n");
03706             SGSparseVector<char>* spr_ptr1 = (SGSparseVector<char>*) data1;
03707             SGSparseVector<char>* spr_ptr2 = (SGSparseVector<char>*) data2;
03708 
03709             if (spr_ptr1->num_feat_entries != spr_ptr2->num_feat_entries)
03710             {
03711                 SG_SINFO("leaving TParameter::compare_stype(): Length of "
03712                         "sparse vector1 (%d)  is different of vector 2 (%d)\n",
03713                         spr_ptr1->num_feat_entries, spr_ptr2->num_feat_entries);
03714                 return false;
03715             }
03716 
03717             SG_SDEBUG("Comparing sparse vectors\n");
03718             for (index_t i=0; i<spr_ptr1->num_feat_entries; ++i)
03719             {
03720                 SG_SDEBUG("Comparing sparse entry %d at offset %d\n", i,
03721                         i*TSGDataType::sizeof_sparseentry(ptype));
03722 
03723                 SGSparseVectorEntry<char>* cur1 = (SGSparseVectorEntry<char>*)
03724                                 ((char*) spr_ptr1->features + i*TSGDataType
03725 								 ::sizeof_sparseentry(ptype));
03726                 SGSparseVectorEntry<char>* cur2 = (SGSparseVectorEntry<char>*)
03727                                 ((char*) spr_ptr2->features + i*TSGDataType
03728 								 ::sizeof_sparseentry(ptype));
03729 
03730                 /* sparse entries have an offset of the enty pointer depending
03731                  * on type. Since I cast everything down to char, I need to remove
03732                  * the char offset and add the offset of the ptype */
03733                 index_t char_offset=TSGDataType::offset_sparseentry(PT_CHAR);
03734                 index_t ptype_offset=TSGDataType::offset_sparseentry(ptype);
03735                 void* pointer1=&(cur1->entry)-char_offset+ptype_offset;
03736                 void* pointer2=&(cur2->entry)-char_offset+ptype_offset;
03737 
03738                 if (!TParameter::compare_ptype(ptype, pointer1,
03739                         pointer2, accuracy))
03740                 {
03741                     SG_SINFO("leaving TParameter::compare_stype(): Data of"
03742                             " sparse vector element is different\n");
03743                     return false;
03744                 }
03745 
03746                 /* also compare feature indices */
03747                 if (cur2->feat_index!=cur1->feat_index)
03748                 {
03749                     SG_SINFO("leaving TParameter::compare_stype(): Feature "
03750                             "index of sparse vector element is different. "
03751                             "source: %d, target: %d\n",
03752                             cur1->feat_index, cur2->feat_index);
03753                     return false;
03754                 }
03755             }
03756             break;
03757         }
03758         case ST_STRING:
03759         {
03760             SG_SDEBUG("ST_STRING\n");
03761             SGString<char>* str_ptr1 = (SGString<char>*) data1;
03762             SGString<char>* str_ptr2 = (SGString<char>*) data2;
03763 
03764             if (str_ptr1->slen != str_ptr2->slen)
03765             {
03766                 SG_SINFO("leaving TParameter::compare_stype(): Length of "
03767                         "string1 (%d)  is different of string2 (%d)\n",
03768                         str_ptr1->slen, str_ptr2->slen);
03769                 return false;
03770             }
03771 
03772             SG_SDEBUG("Comparing strings\n");
03773             for (index_t i=0; i<str_ptr1->slen; ++i)
03774             {
03775                 SG_SDEBUG("Comparing string element %d at offset %d\n", i,
03776                         i*size_ptype);
03777                 void* pointer1=str_ptr1->string+i*size_ptype;
03778                 void* pointer2=str_ptr2->string+i*size_ptype;
03779 
03780                 if (!TParameter::compare_ptype(ptype, pointer1,
03781                         pointer2, accuracy))
03782                 {
03783                     SG_SINFO("leaving TParameter::compare_stype(): Data of"
03784                             " string element is different\n");
03785                     return false;
03786                 }
03787             }
03788             break;
03789         }
03790         default:
03791         {
03792             SG_SERROR("TParameter::compare_stype(): Undefined struct type\n");
03793             break;
03794         }
03795     }
03796 
03797     SG_SDEBUG("leaving TParameter::compare_stype(): Data were equal\n");
03798     return true;
03799 }
03800 
03801 bool TParameter::copy_stype(EStructType stype, EPrimitiveType ptype,
03802         void* source, void* target)
03803 {
03804     SG_SDEBUG("entering TParameter::copy_stype()\n");
03805     size_t size_ptype=TSGDataType::sizeof_ptype(ptype);
03806 
03807     /* Heiko Strathmann: While I know that copying the stypes string and sparse
03808      * element wise is slower than doing the full things, it is way easier to
03809      * program and to debug since I already made sure that copy_ptype works as
03810      * intended. In addition, strings and vectors of SGObjects can be treated
03811      * recursively this way (we dont have cases for this currently, June 2013,
03812      * but they can be added without having to modify this code)
03813      *
03814      * Therefore, this code is very close to the the equals code for
03815      * stypes. If it turns out to be too slow (which I doubt), stypes can be
03816      * copied with memcpy over the full memory blocks */
03817 
03818     switch (stype)
03819     {
03820         case ST_NONE:
03821         {
03822             SG_SDEBUG("ST_NONE\n");
03823             return TParameter::copy_ptype(ptype, source, target);
03824             break;
03825         }
03826         case ST_STRING:
03827         {
03828             SG_SDEBUG("ST_STRING\n");
03829             SGString<char>* source_ptr = (SGString<char>*) source;
03830             SGString<char>* target_ptr = (SGString<char>*) target;
03831 
03832             if (source_ptr->slen != target_ptr->slen)
03833             {
03834                 SG_SDEBUG("string lengths different (source: %d vs target: %d),"
03835                         " freeing memory.\n", source_ptr->slen, target_ptr->slen);
03836 
03837                 /* if string have different lengths, free data and make equal */
03838                 SG_FREE(target_ptr->string);
03839                 target_ptr->string=NULL;
03840                 target_ptr->slen=0;
03841             }
03842 
03843             if (!target_ptr->string)
03844             {
03845                 /* allocate memory if data is NULL */
03846                 size_t num_bytes=source_ptr->slen * size_ptype;
03847 
03848                 SG_SDEBUG("target string data NULL, allocating %d bytes.\n",
03849                         num_bytes);
03850                 target_ptr->string=SG_MALLOC(char, num_bytes);
03851                 target_ptr->slen=source_ptr->slen;
03852             }
03853 
03854             SG_SDEBUG("Copying strings\n");
03855             for (index_t i=0; i<source_ptr->slen; ++i)
03856             {
03857                 SG_SDEBUG("Copying string element %d at offset %d\n", i,
03858                         i*size_ptype);
03859                 void* pointer1=source_ptr->string+i*size_ptype;
03860                 void* pointer2=target_ptr->string+i*size_ptype;
03861 
03862                 if (!TParameter::copy_ptype(ptype, pointer1, pointer2))
03863                 {
03864                     SG_SDEBUG("leaving TParameter::copy_stype(): Copy of string"
03865                             " element failed.\n");
03866                     return false;
03867                 }
03868             }
03869             break;
03870         }
03871         case ST_SPARSE:
03872         {
03873             SG_SDEBUG("ST_SPARSE\n");
03874             SGSparseVector<char>* source_ptr = (SGSparseVector<char>*) source;
03875             SGSparseVector<char>* target_ptr = (SGSparseVector<char>*) target;
03876 
03877             if (source_ptr->num_feat_entries != target_ptr->num_feat_entries)
03878             {
03879                 SG_SDEBUG("sparse vector lengths different (source: %d vs target: %d),"
03880                         " freeing memory.\n",
03881                         source_ptr->num_feat_entries, target_ptr->num_feat_entries);
03882 
03883                 /* if string have different lengths, free data and make equal */
03884                 SG_FREE(target_ptr->features);
03885                 target_ptr->features=NULL;
03886                 target_ptr->num_feat_entries=0;
03887             }
03888 
03889             if (!target_ptr->features)
03890             {
03891                 /* allocate memory if data is NULL */
03892                 size_t num_bytes=source_ptr->num_feat_entries *
03893                         TSGDataType::sizeof_sparseentry(ptype);
03894 
03895                 SG_SDEBUG("target sparse data NULL, allocating %d bytes.\n",
03896                         num_bytes);
03897                 target_ptr->features=(SGSparseVectorEntry<char>*)SG_MALLOC(char, num_bytes);
03898                 target_ptr->num_feat_entries=source_ptr->num_feat_entries;
03899             }
03900 
03901             SG_SDEBUG("Copying sparse vectors\n");
03902             for (index_t i=0; i<source_ptr->num_feat_entries; ++i)
03903             {
03904                 SG_SDEBUG("Copying sparse entry %d at offset %d\n", i,
03905                         i*TSGDataType::sizeof_sparseentry(ptype));
03906 
03907                 SGSparseVectorEntry<char>* cur1 = (SGSparseVectorEntry<char>*)
03908                                 ((char*) source_ptr->features + i*TSGDataType
03909 										 ::sizeof_sparseentry(ptype));
03910                 SGSparseVectorEntry<char>* cur2 = (SGSparseVectorEntry<char>*)
03911                                 ((char*) target_ptr->features + i*TSGDataType
03912 										 ::sizeof_sparseentry(ptype));
03913 
03914                 /* sparse entries have an offset of the enty pointer depending
03915                  * on type. Since I cast everything down to char, I need to remove
03916                  * the char offset and add the offset of the ptype */
03917                 index_t char_offset=TSGDataType::offset_sparseentry(PT_CHAR);
03918                 index_t ptype_offset=TSGDataType::offset_sparseentry(ptype);
03919                 void* pointer1=&(cur1->entry)-char_offset+ptype_offset;
03920                 void* pointer2=&(cur2->entry)-char_offset+ptype_offset;
03921 
03922                 if (!TParameter::copy_ptype(ptype, pointer1, pointer2))
03923                 {
03924                     SG_SDEBUG("leaving TParameter::copy_stype(): Copy of sparse"
03925                             " vector element failed\n");
03926                     return false;
03927                 }
03928 
03929                 /* afterwards, copy feature indices, wich are the data before
03930                  * the avove offeet */
03931                 cur2->feat_index=cur1->feat_index;
03932             }
03933             break;
03934         }
03935         default:
03936         {
03937             SG_SERROR("TParameter::copy_stype(): Undefined struct type\n");
03938             return false;
03939             break;
03940         }
03941     }
03942 
03943     SG_SDEBUG("leaving TParameter::copy_stype(): Copy successful\n");
03944     return true;
03945 }
03946 
03947 bool TParameter::copy(TParameter* target)
03948 {
03949     SG_SDEBUG("entering TParameter::copy()\n");
03950 
03951     if (!target)
03952     {
03953         SG_SDEBUG("leaving TParameter::copy(): other parameter is NULL\n");
03954         return false;
03955     }
03956 
03957     if (!m_parameter)
03958     {
03959         SG_SDEBUG("leaving TParameter::copy(): m_parameter of source is NULL\n");
03960         return false;
03961     }
03962 
03963     if (!target->m_parameter)
03964     {
03965         SG_SDEBUG("leaving TParameter::copy(): m_parameter of target is NULL\n");
03966         return false;
03967     }
03968 
03969     if (strcmp(m_name, target->m_name))
03970     {
03971         SG_SDEBUG("leaving TParameter::copy(): name \"%s\" is different from"
03972                 " target parameter's "
03973                 "name \"%s\"\n", m_name, target->m_name);
03974         return false;
03975     }
03976 
03977     SG_SDEBUG("Comparing datatypes without length\n");
03978     if (!(m_datatype.equals_without_length(target->m_datatype)))
03979     {
03980         SG_SDEBUG("leaving TParameter::copy(): type of \"%s\" is different "
03981                 "from target parameter's \"%s\" type\n", m_name, target->m_name);
03982         return false;
03983     }
03984 
03985     switch (m_datatype.m_ctype)
03986     {
03987         case CT_SCALAR:
03988         {
03989             SG_SDEBUG("CT_SCALAR\n");
03990             if (!TParameter::copy_stype(m_datatype.m_stype,
03991                     m_datatype.m_ptype, m_parameter,
03992                     target->m_parameter))
03993             {
03994                 SG_SDEBUG("leaving TParameter::copy(): scalar data copy error\n");
03995                 return false;
03996             }
03997             break;
03998         }
03999         case CT_VECTOR: case CT_SGVECTOR:
04000         {
04001             SG_SDEBUG("CT_VECTOR or CT_SGVECTOR\n");
04002 
04003             /* if sizes are different or memory is not allocated, do that */
04004             if (!m_datatype.equals(target->m_datatype))
04005             {
04006                 SG_SDEBUG("changing size of target vector and freeing memory\n");
04007                 /* first case: different sizes, free target memory */
04008                 SG_FREE(*(char**)target->m_parameter);
04009                 *(char**)target->m_parameter=NULL;
04010 
04011             }
04012 
04013             /* check whether target m_parameter data contains NULL, if yes
04014              * create if the length is non-zero */
04015             if (*(char**)target->m_parameter==NULL && *m_datatype.m_length_y>0)
04016             {
04017                 size_t num_bytes=*m_datatype.m_length_y * m_datatype.sizeof_stype();
04018                 SG_SDEBUG("allocating %d bytes memory for target vector\n", num_bytes);
04019                 *(char**)target->m_parameter=SG_MALLOC(char, num_bytes);
04020 
04021                 /* use length of source */
04022                 *target->m_datatype.m_length_y=*m_datatype.m_length_y;
04023             }
04024 
04025             /* now start actual copying, assume that sizes are equal and memory
04026              * is there */
04027             ASSERT(m_datatype.equals(target->m_datatype));
04028 
04029             /* x is number of processed bytes */
04030             index_t x=0;
04031             SG_SDEBUG("length_y: %d\n", *m_datatype.m_length_y)
04032             for (index_t i=0; i<*m_datatype.m_length_y; ++i)
04033             {
04034                 SG_SDEBUG("copying element %d which is %d byes from start\n",
04035                         i, x);
04036 
04037                 void* pointer_a=&((*(char**)m_parameter)[x]);
04038                 void* pointer_b=&((*(char**)target->m_parameter)[x]);
04039 
04040                 if (!TParameter::copy_stype(m_datatype.m_stype,
04041                         m_datatype.m_ptype, pointer_a, pointer_b))
04042                 {
04043                     SG_SDEBUG("leaving TParameter::copy(): vector element "
04044                             "copy error\n");
04045                     return false;
04046                 }
04047 
04048                 x=x+(m_datatype.sizeof_ptype());
04049             }
04050 
04051             break;
04052         }
04053         case CT_MATRIX: case CT_SGMATRIX:
04054         {
04055             SG_SDEBUG("CT_MATRIX or CT_SGMATRIX\n");
04056 
04057             /* if sizes are different or memory is not allocated, do that */
04058             if (!m_datatype.equals(target->m_datatype))
04059             {
04060                 SG_SDEBUG("changing size of target vector and freeing memory\n");
04061                 /* first case: different sizes, free target memory */
04062                 SG_FREE(*(char**)target->m_parameter);
04063                 *(char**)target->m_parameter=NULL;
04064             }
04065 
04066             /* check whether target m_parameter data contains NULL, if yes, create */
04067             if (*(char**)target->m_parameter==NULL)
04068             {
04069                 SG_SDEBUG("allocating memory for target vector\n");
04070                 size_t num_bytes=0;
04071                 /* for ST_SPARSE allocate only for a vector of m_length_y */
04072                 if (m_datatype.m_stype==ST_SPARSE)
04073                     num_bytes=*m_datatype.m_length_y * m_datatype.sizeof_stype();
04074                 else
04075                     num_bytes=*m_datatype.m_length_y *
04076                         (*m_datatype.m_length_x) * m_datatype.sizeof_stype();
04077                 *(char**)target->m_parameter=SG_MALLOC(char, num_bytes);
04078 
04079                 /* use length of source */
04080                 *target->m_datatype.m_length_y=*m_datatype.m_length_y;
04081                 *target->m_datatype.m_length_x=*m_datatype.m_length_x;
04082         
04083                 SG_SDEBUG("%d bytes are allocated\n", num_bytes);
04084             }
04085 
04086             /* now start actual copying, assume that sizes are equal and memory
04087              * is there */
04088             ASSERT(m_datatype.equals(target->m_datatype));
04089 
04090             /* x is number of processed bytes */
04091             index_t x=0;
04092             SG_SDEBUG("length_y: %d\n", *m_datatype.m_length_y)
04093             SG_SDEBUG("length_x: %d\n", *m_datatype.m_length_x)
04094             int64_t length=0;
04095             /* for ST_SPARSE allocate iterate over a vector of m_length_y */
04096             if (m_datatype.m_stype==ST_SPARSE)
04097                 length=(*m_datatype.m_length_y);
04098             else
04099                 length=(*m_datatype.m_length_y) * (*m_datatype.m_length_x);
04100             for (index_t i=0; i<length; ++i)
04101             {
04102                 SG_SDEBUG("copying element %d which is %d byes from start\n",
04103                         i, x);
04104 
04105                 void* pointer_a=&((*(char**)m_parameter)[x]);
04106                 void* pointer_b=&((*(char**)target->m_parameter)[x]);
04107 
04108                 if (!TParameter::copy_stype(m_datatype.m_stype,
04109                         m_datatype.m_ptype, pointer_a, pointer_b))
04110                 {
04111                     SG_SDEBUG("leaving TParameter::copy(): vector element "
04112                             "differs\n");
04113                     return false;
04114                 }
04115 
04116                 /* For ST_SPARSE, the iteration is on the pointer of SGSparseVectors */
04117                 if (m_datatype.m_stype==ST_SPARSE)
04118                     x=x+(m_datatype.sizeof_stype());
04119                 else
04120                     x=x+(m_datatype.sizeof_ptype());
04121             }
04122 
04123             break;
04124         }
04125         case CT_NDARRAY:
04126         {
04127             SG_SDEBUG("CT_NDARRAY\n");
04128             SG_SERROR("TParameter::copy(): Not yet implemented for "
04129                     "CT_NDARRAY!\n");
04130             break;
04131         }
04132         case CT_UNDEFINED: default:
04133             SG_SERROR("Implementation error: undefined container type\n");
04134             break;
04135     }
04136 
04137     SG_SDEBUG("leaving TParameter::copy(): Copy successful\n");
04138     return true;
04139 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation