diff --git a/src/shogun/base/Parameter.cpp b/src/shogun/base/Parameter.cpp index 205b4848202..3289fbca45f 100644 --- a/src/shogun/base/Parameter.cpp +++ b/src/shogun/base/Parameter.cpp @@ -2957,499 +2957,3 @@ bool TParameter::operator>(const TParameter& other) const return strcmp(m_name, other.m_name)>0; } -bool TParameter::copy_ptype(EPrimitiveType ptype, void* source, void* target) -{ - SG_SDEBUG("entering TParameter::copy_ptype()\n"); - - /* rather than using sg_memcpy, use the cumbersome way here and cast all types. - * This makes it so much easier to debug code. - * Copy full stype if this is too slow */ - switch (ptype) - { - case PT_BOOL: - { - *((bool*)target)=*((bool*)source); - SG_SDEBUG("after copy of ptype PT_BOOL: source %d, target %d\n", - *((bool*)source), *((bool*)target)); - break; - } - case PT_CHAR: - { - *((char*)target)=*((char*)source); - SG_SDEBUG("after copy of ptype PT_CHAR: source %c, target %c\n", - *((char*)source), *((char*)target)); - break; - } - case PT_INT8: - { - *((int8_t*)target)=*((int8_t*)source); - SG_SDEBUG("after copy of ptype PT_INT8: source %d, target %d\n", - *((int8_t*)source), *((int8_t*)target)); - break; - } - case PT_UINT8: - { - *((uint8_t*)target)=*((uint8_t*)source); - SG_SDEBUG("after copy of ptype PT_UINT8: source %d, target %d\n", - *((uint8_t*)source), *((uint8_t*)target)); - break; - } - case PT_INT16: - { - *((int16_t*)target)=*((int16_t*)source); - SG_SDEBUG("after copy of ptype PT_INT16: source %d, target %d\n", - *((int16_t*)source), *((int16_t*)target)); - break; - } - case PT_UINT16: - { - *((uint16_t*)target)=*((uint16_t*)source); - SG_SDEBUG("after copy of ptype PT_UINT16: source %d, target %d\n", - *((uint16_t*)source), *((uint16_t*)target)); - break; - } - case PT_INT32: - { - *((int32_t*)target)=*((int32_t*)source); - SG_SDEBUG("after copy of ptype PT_INT32: source %d, target %d\n", - *((int32_t*)source), *((int32_t*)target)); - break; - } - case PT_UINT32: - { - *((uint32_t*)target)=*((uint32_t*)source); - SG_SDEBUG("after copy of ptype PT_UINT32: source %d, target %d\n", - *((uint32_t*)source), *((uint32_t*)target)); - break; - } - case PT_INT64: - { - *((int64_t*)target)=*((int64_t*)source); - SG_SDEBUG("after copy of ptype PT_INT64: source %d, target %d\n", - *((int64_t*)source), *((int64_t*)target)); - break; - } - case PT_UINT64: - { - *((uint64_t*)target)=*((uint64_t*)source); - SG_SDEBUG("after copy of ptype PT_UINT64: source %d, target %d\n", - *((uint64_t*)source), *((uint64_t*)target)); - break; - } - case PT_FLOAT32: - { - *((float32_t*)target)=*((float32_t*)source); - SG_SDEBUG("after copy of ptype PT_FLOAT32: source %f, target %f\n", - *((float32_t*)source), *((float32_t*)target)); - break; - } - case PT_FLOAT64: - { - *((float64_t*)target)=*((float64_t*)source); - SG_SDEBUG("after copy of ptype PT_FLOAT64: source %f, target %f\n", - *((float64_t*)source), *((float64_t*)target)); - break; - } - case PT_FLOATMAX: - { - *((floatmax_t*)target)=*((floatmax_t*)source); - SG_SDEBUG("after copy of ptype PT_FLOATMAX: source %Lf, target %Lf\n", - *((floatmax_t*)source), *((floatmax_t*)target)); - break; - } - case PT_COMPLEX128: - { - *((complex128_t*)target)=*((complex128_t*)source); - SG_SDEBUG("after copy of ptype PT_COMPLEX128: " - "source real %f, target real %f," - "source imag %f, target imag %f," - "\n", - ((complex128_t*)source)->real(), ((complex128_t*)target)->real(), - ((complex128_t*)source)->imag(), ((complex128_t*)target)->imag()); - break; - } - case PT_SGOBJECT: - { - CSGObject* casted1=*((CSGObject**)source); - CSGObject* casted2=*((CSGObject**)target); - - /* important not to call methods on NULL */ - if (!casted1 && ! casted2) - { - SG_SDEBUG("leaving TParameter::copy_ptype(): Both SGObjects are NULL\n"); - return true; - } - - /* make sure to not call NULL methods */ - if (casted1) - { - /* in case of overwriting old objects */ - SG_UNREF(*((CSGObject**)target)); - *((CSGObject**)target) = casted1->clone(); - } - - break; - } - default: - SG_SERROR( - "TParameter::copy_ptype(): Encountered unknown primitive" - "-type: %d\n", - ptype); - return false; - break; - } - - SG_SDEBUG("leaving TParameter::copy_ptype(): Copy successful\n"); - return true; -} - -bool TParameter::copy_stype(EStructType stype, EPrimitiveType ptype, - void* source, void* target) -{ - SG_SDEBUG("entering TParameter::copy_stype()\n"); - size_t size_ptype=TSGDataType::sizeof_ptype(ptype); - - /* Heiko Strathmann: While I know that copying the stypes string and sparse - * element wise is slower than doing the full things, it is way easier to - * program and to debug since I already made sure that copy_ptype works as - * intended. In addition, strings and vectors of SGObjects can be treated - * recursively this way (we dont have cases for this currently, June 2013, - * but they can be added without having to modify this code) - * - * Therefore, this code is very close to the the equals code for - * stypes. If it turns out to be too slow (which I doubt), stypes can be - * copied with sg_memcpy over the full memory blocks */ - - switch (stype) - { - case ST_NONE: - { - SG_SDEBUG("ST_NONE\n"); - return TParameter::copy_ptype(ptype, source, target); - break; - } - case ST_STRING: - { - SG_SDEBUG("ST_STRING\n"); - SGString* source_ptr = (SGString*) source; - SGString* target_ptr = (SGString*) target; - - if (source_ptr->slen != target_ptr->slen) - { - SG_SDEBUG("string lengths different (source: %d vs target: %d)," - " freeing memory.\n", source_ptr->slen, target_ptr->slen); - - /* if string have different lengths, free data and make equal */ - SG_FREE(target_ptr->string); - target_ptr->string=NULL; - target_ptr->slen=0; - } - - if (!target_ptr->string) - { - /* allocate memory if data is NULL */ - size_t num_bytes=source_ptr->slen * size_ptype; - - SG_SDEBUG("target string data NULL, allocating %d bytes.\n", - num_bytes); - target_ptr->string=SG_MALLOC(char, num_bytes); - target_ptr->slen=source_ptr->slen; - } - - SG_SDEBUG("Copying strings\n"); - for (index_t i=0; islen; ++i) - { - SG_SDEBUG("Copying string element %d at offset %d\n", i, - i*size_ptype); - void* pointer1=source_ptr->string+i*size_ptype; - void* pointer2=target_ptr->string+i*size_ptype; - - if (!TParameter::copy_ptype(ptype, pointer1, pointer2)) - { - SG_SDEBUG("leaving TParameter::copy_stype(): Copy of string" - " element failed.\n"); - return false; - } - } - break; - } - case ST_SPARSE: - { - SG_SDEBUG("ST_SPARSE\n"); - SGSparseVector* source_ptr = (SGSparseVector*) source; - SGSparseVector* target_ptr = (SGSparseVector*) target; - - if (source_ptr->num_feat_entries != target_ptr->num_feat_entries) - { - SG_SDEBUG("sparse vector lengths different (source: %d vs target: %d)," - " freeing memory.\n", - source_ptr->num_feat_entries, target_ptr->num_feat_entries); - - /* if string have different lengths, free data and make equal */ - SG_FREE(target_ptr->features); - target_ptr->features=NULL; - target_ptr->num_feat_entries=0; - } - - if (!target_ptr->features) - { - /* allocate memory if data is NULL */ - size_t num_bytes=source_ptr->num_feat_entries * - TSGDataType::sizeof_sparseentry(ptype); - - SG_SDEBUG("target sparse data NULL, allocating %d bytes.\n", - num_bytes); - target_ptr->features=(SGSparseVectorEntry*)SG_MALLOC(char, num_bytes); - target_ptr->num_feat_entries=source_ptr->num_feat_entries; - } - - SG_SDEBUG("Copying sparse vectors\n"); - for (index_t i=0; inum_feat_entries; ++i) - { - SG_SDEBUG("Copying sparse entry %d at offset %d\n", i, - i*TSGDataType::sizeof_sparseentry(ptype)); - - SGSparseVectorEntry* cur1 = (SGSparseVectorEntry*) - ((char*) source_ptr->features + i*TSGDataType - ::sizeof_sparseentry(ptype)); - SGSparseVectorEntry* cur2 = (SGSparseVectorEntry*) - ((char*) target_ptr->features + i*TSGDataType - ::sizeof_sparseentry(ptype)); - - /* sparse entries have an offset of the enty pointer depending - * on type. Since I cast everything down to char, I need to remove - * the char offset and add the offset of the ptype */ - index_t char_offset=TSGDataType::offset_sparseentry(PT_CHAR); - index_t ptype_offset=TSGDataType::offset_sparseentry(ptype); - void* pointer1=&(cur1->entry)-char_offset+ptype_offset; - void* pointer2=&(cur2->entry)-char_offset+ptype_offset; - - if (!TParameter::copy_ptype(ptype, pointer1, pointer2)) - { - SG_SDEBUG("leaving TParameter::copy_stype(): Copy of sparse" - " vector element failed\n"); - return false; - } - - /* afterwards, copy feature indices, wich are the data before - * the avove offeet */ - cur2->feat_index=cur1->feat_index; - } - break; - } - default: - { - SG_SERROR("TParameter::copy_stype(): Undefined struct type\n"); - return false; - break; - } - } - - SG_SDEBUG("leaving TParameter::copy_stype(): Copy successful\n"); - return true; -} - -bool TParameter::copy(TParameter* target) -{ - SG_SDEBUG("entering TParameter::copy()\n"); - - if (!target) - { - SG_SDEBUG("leaving TParameter::copy(): other parameter is NULL\n"); - return false; - } - - if (!m_parameter) - { - SG_SDEBUG("leaving TParameter::copy(): m_parameter of source is NULL\n"); - return false; - } - - if (!target->m_parameter) - { - SG_SDEBUG("leaving TParameter::copy(): m_parameter of target is NULL\n"); - return false; - } - - if (strcmp(m_name, target->m_name)) - { - SG_SDEBUG("leaving TParameter::copy(): name \"%s\" is different from" - " target parameter's " - "name \"%s\"\n", m_name, target->m_name); - return false; - } - - SG_SDEBUG("Comparing datatypes without length\n"); - if (!(m_datatype.equals_without_length(target->m_datatype))) - { - SG_SDEBUG("leaving TParameter::copy(): type of \"%s\" is different " - "from target parameter's \"%s\" type\n", m_name, target->m_name); - return false; - } - - switch (m_datatype.m_ctype) - { - case CT_SCALAR: - { - SG_SDEBUG("CT_SCALAR\n"); - if (!TParameter::copy_stype(m_datatype.m_stype, - m_datatype.m_ptype, m_parameter, - target->m_parameter)) - { - SG_SDEBUG("leaving TParameter::copy(): scalar data copy error\n"); - return false; - } - break; - } - case CT_VECTOR: case CT_SGVECTOR: - { - SG_SDEBUG("CT_VECTOR or CT_SGVECTOR\n"); - - /* if sizes are different or memory is not allocated, do that */ - if (!m_datatype.equals(target->m_datatype)) - { - SG_SDEBUG("changing size of target vector and freeing memory\n"); - /* first case: different sizes, free target memory */ - SG_FREE(*(char**)target->m_parameter); - *(char**)target->m_parameter=NULL; - - } - - /* check whether target m_parameter data contains NULL, if yes - * create if the length is non-zero */ - if (*(char**)target->m_parameter==NULL && *m_datatype.m_length_y>0) - { - size_t num_bytes=*m_datatype.m_length_y * m_datatype.sizeof_stype(); - SG_SDEBUG("allocating %d bytes memory for target vector\n", num_bytes); - - *(char**)target->m_parameter=SG_MALLOC(char, num_bytes); - /* check whether ptype is SGOBJECT, if yes we need to initialize - the memory with NULL for the way copy_ptype handles it */ - if (m_datatype.m_ptype==PT_SGOBJECT || m_datatype.m_stype==ST_STRING) - memset(*(void**)target->m_parameter, 0, num_bytes); - - /* use length of source */ - *target->m_datatype.m_length_y=*m_datatype.m_length_y; - } - - /* now start actual copying, assume that sizes are equal and memory - * is there */ - ASSERT(m_datatype.equals(target->m_datatype)); - - /* x is number of processed bytes */ - index_t x=0; - SG_SDEBUG("length_y: %d\n", *m_datatype.m_length_y) - for (index_t i=0; i<*m_datatype.m_length_y; ++i) - { - SG_SDEBUG("copying element %d which is %d bytes from start\n", - i, x); - - void* pointer_a=&((*(char**)m_parameter)[x]); - void* pointer_b=&((*(char**)target->m_parameter)[x]); - - if (!TParameter::copy_stype(m_datatype.m_stype, - m_datatype.m_ptype, pointer_a, pointer_b)) - { - SG_SDEBUG("leaving TParameter::copy(): vector element " - "copy error\n"); - return false; - } - - x=x+(m_datatype.sizeof_stype()); - } - - break; - } - case CT_MATRIX: case CT_SGMATRIX: - { - SG_SDEBUG("CT_MATRIX or CT_SGMATRIX\n"); - - /* if sizes are different or memory is not allocated, do that */ - if (!m_datatype.equals(target->m_datatype)) - { - SG_SDEBUG("changing size of target vector and freeing memory\n"); - /* first case: different sizes, free target memory */ - SG_FREE(*(char**)target->m_parameter); - *(char**)target->m_parameter=NULL; - } - - /* check whether target m_parameter data contains NULL, if yes, create */ - if (*(char**)target->m_parameter==NULL) - { - SG_SDEBUG("allocating memory for target vector\n"); - size_t num_bytes=0; - /* for ST_SPARSE allocate only for a vector of m_length_y */ - if (m_datatype.m_stype==ST_SPARSE) - num_bytes=*m_datatype.m_length_y * m_datatype.sizeof_stype(); - else - num_bytes=*m_datatype.m_length_y * - (*m_datatype.m_length_x) * m_datatype.sizeof_stype(); - - *(char**)target->m_parameter=SG_MALLOC(char, num_bytes); - - /* check whether ptype is SGOBJECT, if yes we need to initialize - the memory with NULL for the way copy_ptype handles it */ - if (m_datatype.m_ptype==PT_SGOBJECT) - memset(*(void**)target->m_parameter, 0, num_bytes); - - /* use length of source */ - *target->m_datatype.m_length_y=*m_datatype.m_length_y; - *target->m_datatype.m_length_x=*m_datatype.m_length_x; - - SG_SDEBUG("%d bytes are allocated\n", num_bytes); - } - - /* now start actual copying, assume that sizes are equal and memory - * is there */ - ASSERT(m_datatype.equals(target->m_datatype)); - - /* x is number of processed bytes */ - index_t x=0; - SG_SDEBUG("length_y: %d\n", *m_datatype.m_length_y) - SG_SDEBUG("length_x: %d\n", *m_datatype.m_length_x) - int64_t length=0; - /* for ST_SPARSE allocate iterate over a vector of m_length_y */ - if (m_datatype.m_stype==ST_SPARSE) - length=(*m_datatype.m_length_y); - else - length=(*m_datatype.m_length_y) * (*m_datatype.m_length_x); - for (index_t i=0; im_parameter)[x]); - - if (!TParameter::copy_stype(m_datatype.m_stype, - m_datatype.m_ptype, pointer_a, pointer_b)) - { - SG_SDEBUG("leaving TParameter::copy(): vector element " - "differs\n"); - return false; - } - - /* For ST_SPARSE, the iteration is on the pointer of SGSparseVectors */ - if (m_datatype.m_stype==ST_SPARSE) - x=x+(m_datatype.sizeof_stype()); - else - x=x+(m_datatype.sizeof_ptype()); - } - - break; - } - case CT_NDARRAY: - { - SG_SDEBUG("CT_NDARRAY\n"); - SG_SERROR("TParameter::copy(): Not yet implemented for " - "CT_NDARRAY!\n"); - break; - } - case CT_UNDEFINED: default: - SG_SERROR("Implementation error: undefined container type\n"); - break; - } - - SG_SDEBUG("leaving TParameter::copy(): Copy successful\n"); - return true; -} diff --git a/src/shogun/base/Parameter.h b/src/shogun/base/Parameter.h index 52c2930458b..6377fd20d5d 100644 --- a/src/shogun/base/Parameter.h +++ b/src/shogun/base/Parameter.h @@ -56,31 +56,6 @@ struct TParameter */ bool load(CSerializableFile* file, const char* prefix=""); - /** copy primitive type from source to target - * - * @param ptype the primitive type - * @param source from where to copy - * @param target where to copy to - */ - static bool copy_ptype(EPrimitiveType ptype, void* source, void* target); - - /** copy structured type from source to target - * - * @param stype the structured type - * @param ptype the primitive type that the structured objects use - * @param source from where to copy - * @param target where to copy to - */ - static bool copy_stype(EStructType stype, EPrimitiveType ptype, - void* source, void* target); - - /** copy this to parameter target - * - * @param target where this should be copied to - */ - bool copy(TParameter* target); - - /** operator for comparison, (by string m_name) */ bool operator==(const TParameter& other) const; diff --git a/src/shogun/base/SGObject.cpp b/src/shogun/base/SGObject.cpp index 28273cf768b..140c1d90532 100644 --- a/src/shogun/base/SGObject.cpp +++ b/src/shogun/base/SGObject.cpp @@ -702,37 +702,6 @@ CSGObject* CSGObject::clone() return clone; } -bool CSGObject::clone_parameters(CSGObject* other) -{ - REQUIRE(other, "Provided instance must be non-empty.\n"); - index_t num_parameters = m_parameters->get_num_parameters(); - - REQUIRE(other->m_parameters->get_num_parameters() == num_parameters, - "Number of parameters of provided instance (%d) must match this instance (%d).\n", - other->m_parameters->get_num_parameters(), num_parameters); - REQUIRE(!strcmp(other->get_name(), get_name()), - "Name of provided instance (%s) must match this instance (%s).\n", - other->get_name(), get_name()); - - for (index_t i=0; im_parameters->get_parameter(i)->m_name, i); - - if (!other->m_parameters->get_parameter(i)->copy(m_parameters->get_parameter(i))) - { - SG_WARNING("Cloning parameter \"%s\" (at index %d) of provided instance %s" - " into parameter \"%s\" of this instance %s failed.\n", - other->m_parameters->get_parameter(i)->m_name, i, - other->get_name(), m_parameters->get_parameter(i)->m_name, - get_name()); - return false; - } - } - - return true; -} - void CSGObject::create_parameter( const BaseTag& _tag, const AnyParameter& parameter) { diff --git a/src/shogun/base/SGObject.h b/src/shogun/base/SGObject.h index cdb73304ab7..d76e0df399d 100644 --- a/src/shogun/base/SGObject.h +++ b/src/shogun/base/SGObject.h @@ -698,15 +698,6 @@ class CSGObject */ virtual CSGObject* create_empty() const; - /** Iteratively clones all parameters of the provided instance into this instance. - * This will fail if the objects have different sets of registered parameters, - * or if they have a different type as defined by get_name(). - * - * @param other object whose parameters are to be cloned into this instance - * @return true if cloning was successful - */ - bool clone_parameters(CSGObject* other); - private: void set_global_objects(); void unset_global_objects(); diff --git a/src/shogun/lib/DataType.cpp b/src/shogun/lib/DataType.cpp index d2d88914d42..d01ad197d1e 100644 --- a/src/shogun/lib/DataType.cpp +++ b/src/shogun/lib/DataType.cpp @@ -87,83 +87,6 @@ TSGDataType::operator==(const TSGDataType& a) return result; } -bool TSGDataType::equals_without_length(TSGDataType other) -{ - if (m_ctype!=other.m_ctype) - { - SG_SDEBUG("leaving TSGDataType::equals_without_length(): container types are " - "different\n"); - return false; - } - - if (m_stype!=other.m_stype) - { - SG_SDEBUG("leaving TSGDataType::equals_without_length(): struct types are " - "different\n"); - return false; - } - - if (m_ptype!=other.m_ptype) - { - SG_SDEBUG("leaving TSGDataType::equals_without_length(): primitive types are " - "different\n"); - return false; - } - - SG_SDEBUG("leaving TSGDataType::equals_without_length(): data types " - "without lengths are equal\n"); - return true; -} - -bool TSGDataType::equals(TSGDataType other) -{ - SG_SDEBUG("entering TSGDataType::equals()\n"); - - if (!equals_without_length(other)) - { - SG_SDEBUG("leaving TSGDataType::equals(): Data types without lengths " - "are not equal\n"); - return false; - } - - if ((!m_length_y && other.m_length_y) || (m_length_y && !other.m_length_y)) - { - SG_SDEBUG("leaving TSGDataType::equals(): length_y is at %p while " - "other's length_y is at %p\n", m_length_y, other.m_length_y); - return false; - } - - if (m_length_y && other.m_length_y) - { - if (*m_length_y!=*other.m_length_y) - { - SG_SDEBUG("leaving TSGDataType::equals(): length_y=%d while " - "other's length_y=%d\n", *m_length_y, *other.m_length_y); - return false; - } - } - - if ((!m_length_x && other.m_length_x) || (m_length_x && !other.m_length_x)) - { - SG_SDEBUG("leaving TSGDataType::equals(): m_length_x is at %p while " - "other's m_length_x is at %p\n", m_length_x, other.m_length_x); - return false; - } - - if (m_length_x && other.m_length_x) - { - if (*m_length_x!=*other.m_length_x) - { - SG_SDEBUG("leaving TSGDataType::equals(): m_length_x=%d while " - "other's m_length_x=%d\n", *m_length_x, *other.m_length_x); - return false; - } - } - - SG_SDEBUG("leaving TSGDataType::equals(): datatypes are equal\n"); - return true; -} - void TSGDataType::to_string(char* dest, size_t n) const { diff --git a/src/shogun/lib/DataType.h b/src/shogun/lib/DataType.h index 2f89d2d91c1..b511b5ca1b3 100644 --- a/src/shogun/lib/DataType.h +++ b/src/shogun/lib/DataType.h @@ -106,19 +106,6 @@ struct TSGDataType EPrimitiveType ptype, index_t* length_y, index_t* length_x); - /** Compares the content of the data types, including the length fields if - * non-NULL - * @return other type to compare with - * @return true if equals, false otherwise - */ - bool equals(TSGDataType other); - - /** Compares the content of the data types, excluding the length fields - * @return other type to compare with - * @return true if equals, false otherwise - */ - bool equals_without_length(TSGDataType other); - /** equality */ bool operator==(const TSGDataType& a); /** inequality diff --git a/tests/unit/base/Parameter_unittest.cc b/tests/unit/base/Parameter_unittest.cc deleted file mode 100644 index 53cd5ec9e80..00000000000 --- a/tests/unit/base/Parameter_unittest.cc +++ /dev/null @@ -1,848 +0,0 @@ -/* - * This software is distributed under BSD 3-clause license (see LICENSE file). - * - * Authors: Heiko Strathmann, Soumyajit De, Bjoern Esser - */ - -#include -#include -#include -#include -#include - -using namespace shogun; - -TEST(TParameter,copy_ptype_BOOL) -{ - bool a=true; - bool b=false; - EXPECT_TRUE(TParameter::copy_ptype(PT_BOOL, &a, &b)); - EXPECT_EQ(a, b); - EXPECT_EQ(b, 1); -} - -TEST(TParameter,copy_ptype_CHAR) -{ - char a=1; - char b=2; - EXPECT_TRUE(TParameter::copy_ptype(PT_CHAR, &a, &b)); - EXPECT_EQ(a, b); - EXPECT_EQ(b, 1); -} - -TEST(TParameter,copy_ptype_INT8) -{ - int8_t a=1; - int8_t b=2; - EXPECT_TRUE(TParameter::copy_ptype(PT_INT8, &a, &b)); - EXPECT_EQ(a, b); - EXPECT_EQ(b, 1); -} - -TEST(TParameter,copy_ptype_UINT8) -{ - uint8_t a=1; - uint8_t b=2; - EXPECT_TRUE(TParameter::copy_ptype(PT_UINT8, &a, &b)); - EXPECT_EQ(a, b); -} - -TEST(TParameter,copy_ptype_INT16) -{ - int16_t a=1; - int16_t b=2; - EXPECT_TRUE(TParameter::copy_ptype(PT_INT16, &a, &b)); - EXPECT_EQ(a, b); - EXPECT_EQ(b, 1); -} - -TEST(TParameter,copy_ptype_UINT16) -{ - uint16_t a=1; - uint16_t b=2; - EXPECT_TRUE(TParameter::copy_ptype(PT_UINT16, &a, &b)); - EXPECT_EQ(a, b); -} - -TEST(TParameter,copy_ptype_INT32) -{ - int32_t a=1; - int32_t b=2; - EXPECT_TRUE(TParameter::copy_ptype(PT_INT32, &a, &b)); - EXPECT_EQ(a, b); - EXPECT_EQ(b, 1); -} - -TEST(TParameter,copy_ptype_UINT32) -{ - uint32_t a=1; - uint32_t b=2; - EXPECT_TRUE(TParameter::copy_ptype(PT_UINT32, &a, &b)); - EXPECT_EQ(a, b); -} - -TEST(TParameter,copy_ptype_INT64) -{ - int64_t a=1; - int64_t b=2; - EXPECT_TRUE(TParameter::copy_ptype(PT_INT64, &a, &b)); - EXPECT_EQ(a, b); - EXPECT_EQ(b, 1); -} - -TEST(TParameter,copy_ptype_UINT64) -{ - uint64_t a=1; - uint64_t b=2; - EXPECT_TRUE(TParameter::copy_ptype(PT_UINT64, &a, &b)); - EXPECT_EQ(a, b); -} - -TEST(TParameter,copy_ptype_FLOAT32) -{ - float32_t a=1; - float32_t b=2; - EXPECT_TRUE(TParameter::copy_ptype(PT_FLOAT32, &a, &b)); - EXPECT_EQ(a, b); - EXPECT_EQ(b, 1); -} - -TEST(TParameter,copy_ptype_FLOAT64) -{ - float64_t a=1; - float64_t b=2; - EXPECT_TRUE(TParameter::copy_ptype(PT_FLOAT64, &a, &b)); - EXPECT_EQ(a, b); - EXPECT_EQ(b, 1); -} - -TEST(TParameter,copy_ptype_FLOATMAX) -{ - floatmax_t a=1; - floatmax_t b=2; - EXPECT_TRUE(TParameter::copy_ptype(PT_FLOATMAX, &a, &b)); - EXPECT_EQ(a, b); - EXPECT_EQ(b, 1); -} - -TEST(TParameter,copy_ptype_COMPLEX128) -{ - complex128_t a(1.0, 1.0); - complex128_t b(2.0, 2.0); - EXPECT_TRUE(TParameter::copy_ptype(PT_COMPLEX128, &a, &b)); - EXPECT_EQ(a, b); - EXPECT_EQ(b, complex128_t(1.0,1.0)); -} - -TEST(TParameter,copy_stype_NONE) -{ - int32_t a=1; - int32_t b=2; - - TSGDataType type(CT_SCALAR, ST_NONE, PT_INT32); - TParameter* param1=new TParameter(&type, &a, "", ""); - TParameter* param2=new TParameter(&type, &b, "", ""); - - EXPECT_TRUE(TParameter::copy_stype(ST_NONE, PT_INT32, param1->m_parameter, param2->m_parameter)); - EXPECT_EQ(a,b); - EXPECT_EQ(b, 1); - - delete param1; - delete param2; -} - -TEST(TParameter,copy_target_null) -{ - int32_t a=2; - - TSGDataType type(CT_SCALAR, ST_NONE, PT_INT32); - TParameter* param1=new TParameter(&type, &a, "", ""); - - EXPECT_FALSE(param1->copy(NULL)); - - delete param1; -} - -TEST(TParameter,copy_different_name) -{ - int32_t a=1; - int32_t b=2; - - TSGDataType type(CT_SCALAR, ST_NONE, PT_INT32); - TParameter* param1=new TParameter(&type, &a, "a", ""); - TParameter* param2=new TParameter(&type, &b, "b", ""); - - EXPECT_FALSE(param1->copy(param2)); - - delete param1; - delete param2; -} - -TEST(TParameter,copy_own_parameter_null) -{ - int32_t b=2; - - TSGDataType type(CT_SCALAR, ST_NONE, PT_INT32); - TParameter* param1=new TParameter(&type, NULL, "", ""); - TParameter* param2=new TParameter(&type, &b, "", ""); - - EXPECT_FALSE(param1->copy(param2)); - - delete param1; - delete param2; -} - -TEST(TParameter,copy_target_parameter_null) -{ - int32_t a=1; - - TSGDataType type(CT_SCALAR, ST_NONE, PT_INT32); - TParameter* param1=new TParameter(&type, &a, "", ""); - TParameter* param2=new TParameter(&type, NULL, "", ""); - - EXPECT_FALSE(param1->copy(param2)); - - delete param1; - delete param2; -} - -TEST(TParameter,copy_SCALAR) -{ - int32_t a=1; - int32_t b=2; - - TSGDataType type(CT_SCALAR, ST_NONE, PT_INT32); - TParameter* param1=new TParameter(&type, &a, "", ""); - TParameter* param2=new TParameter(&type, &b, "", ""); - - EXPECT_TRUE(param1->copy(param2)); - EXPECT_EQ(a,b); - EXPECT_EQ(b, 1); - - delete param1; - delete param2; -} - -TEST(TParameter,copy_VECTOR_SCALAR_same_size) -{ - SGVector a(2); - SGVector b(2); - - a[0]=1; - a[1]=1; - b[0]=2; - b[1]=2; - - TSGDataType type(CT_SGVECTOR, ST_NONE, PT_FLOAT64, &a.vlen); - TParameter* param1=new TParameter(&type, &a.vector, "", ""); - TParameter* param2=new TParameter(&type, &b.vector, "", ""); - - EXPECT_TRUE(param1->copy(param2)); - - for (index_t i=0; i a(2); - SGVector b(3); - - a[0]=1; - a[1]=1; - b[0]=2; - b[1]=2; - b[2]=2; - - TSGDataType type_a(CT_SGVECTOR, ST_NONE, PT_FLOAT64, &a.vlen); - TSGDataType type_b(CT_SGVECTOR, ST_NONE, PT_FLOAT64, &b.vlen); - TParameter* param1=new TParameter(&type_a, &a.vector, "", ""); - TParameter* param2=new TParameter(&type_b, &b.vector, "", ""); - - EXPECT_TRUE(param1->copy(param2)); - - EXPECT_EQ(a.vlen, 2); - EXPECT_EQ(b.vlen, a.vlen); - for (index_t i=0; i a(2); - SGVector b; - - a[0]=1; - a[1]=1; - - TSGDataType type_a(CT_SGVECTOR, ST_NONE, PT_FLOAT64, &a.vlen); - TSGDataType type_b(CT_SGVECTOR, ST_NONE, PT_FLOAT64, &b.vlen); - TParameter* param1=new TParameter(&type_a, &a.vector, "", ""); - TParameter* param2=new TParameter(&type_b, &b.vector, "", ""); - - EXPECT_TRUE(param1->copy(param2)); - - EXPECT_EQ(a.vlen, 2); - EXPECT_EQ(b.vlen, a.vlen); - for (index_t i=0; i a; - SGVector b; - - TSGDataType type_a(CT_SGVECTOR, ST_NONE, PT_FLOAT64, &a.vlen); - TSGDataType type_b(CT_SGVECTOR, ST_NONE, PT_FLOAT64, &b.vlen); - TParameter* param1=new TParameter(&type_a, &a.vector, "", ""); - TParameter* param2=new TParameter(&type_b, &b.vector, "", ""); - - EXPECT_TRUE(param1->copy(param2)); - EXPECT_EQ(a.vlen, 0); - EXPECT_EQ(b.vlen, a.vlen); - - delete param1; - delete param2; -} - -TEST(TParameter,copy_MATRIX_SCALAR_source_and_target_empty) -{ - SGMatrix a; - SGMatrix b; - - TSGDataType type_a(CT_SGMATRIX, ST_NONE, PT_FLOAT64, &a.num_rows, &a.num_cols); - TSGDataType type_b(CT_SGMATRIX, ST_NONE, PT_FLOAT64, &b.num_rows, &b.num_cols); - TParameter* param1=new TParameter(&type_a, &a.matrix, "", ""); - TParameter* param2=new TParameter(&type_b, &b.matrix, "", ""); - - EXPECT_TRUE(param1->copy(param2)); - - EXPECT_EQ(a.num_rows, 0); - EXPECT_EQ(a.num_cols, 0); - EXPECT_EQ(b.num_rows, a.num_rows); - EXPECT_EQ(b.num_cols, a.num_cols); - - delete param1; - delete param2; -} - -TEST(TParameter,copy_MATRIX_SCALAR_target_empty) -{ - SGMatrix a(2,2); - SGMatrix b; - - a(0,0)=1; - a(0,1)=1; - a(1,0)=1; - a(1,1)=1; - - TSGDataType type_a(CT_SGMATRIX, ST_NONE, PT_FLOAT64, &a.num_rows, &a.num_cols); - TSGDataType type_b(CT_SGMATRIX, ST_NONE, PT_FLOAT64, &b.num_rows, &b.num_cols); - TParameter* param1=new TParameter(&type_a, &a.matrix, "", ""); - TParameter* param2=new TParameter(&type_b, &b.matrix, "", ""); - - EXPECT_TRUE(param1->copy(param2)); - - EXPECT_EQ(a.num_rows, 2); - EXPECT_EQ(a.num_cols, 2); - EXPECT_EQ(b.num_rows, a.num_rows); - EXPECT_EQ(b.num_cols, a.num_cols); - - for (index_t i=0; i a(2,2); - SGMatrix b(3,3); - - a(0,0)=1; - a(0,1)=1; - a(1,0)=1; - a(1,1)=1; - - b(0,0)=2; - b(0,1)=2; - b(0,2)=2; - b(1,0)=2; - b(1,1)=2; - b(1,2)=2; - b(2,0)=2; - b(2,1)=2; - b(2,2)=2; - - TSGDataType type_a(CT_SGMATRIX, ST_NONE, PT_FLOAT64, &a.num_rows, &a.num_cols); - TSGDataType type_b(CT_SGMATRIX, ST_NONE, PT_FLOAT64, &b.num_rows, &b.num_cols); - TParameter* param1=new TParameter(&type_a, &a.matrix, "", ""); - TParameter* param2=new TParameter(&type_b, &b.matrix, "", ""); - - EXPECT_TRUE(param1->copy(param2)); - - EXPECT_EQ(a.num_rows, 2); - EXPECT_EQ(a.num_cols, 2); - EXPECT_EQ(b.num_rows, a.num_rows); - EXPECT_EQ(b.num_cols, a.num_cols); - - for (index_t i=0; i a(2,2); - SGMatrix b(2,2); - - a(0,0)=1; - a(0,1)=1; - a(1,0)=1; - a(1,1)=1; - - b(0,0)=2; - b(0,1)=2; - b(1,0)=2; - b(1,1)=2; - - TSGDataType type_a(CT_SGMATRIX, ST_NONE, PT_FLOAT64, &a.num_rows, &a.num_cols); - TSGDataType type_b(CT_SGMATRIX, ST_NONE, PT_FLOAT64, &b.num_rows, &b.num_cols); - TParameter* param1=new TParameter(&type_a, &a.matrix, "", ""); - TParameter* param2=new TParameter(&type_b, &b.matrix, "", ""); - - EXPECT_TRUE(param1->copy(param2)); - - EXPECT_EQ(a.num_rows, 2); - EXPECT_EQ(a.num_cols, 2); - EXPECT_EQ(b.num_rows, a.num_rows); - EXPECT_EQ(b.num_cols, a.num_cols); - - for (index_t i=0; i a(2); - SGVector b(2); - - a.set_const(1); - b.set_const(2); - - SGString str1(a); - SGString str2(b); - - TSGDataType type(CT_SCALAR, ST_STRING, PT_FLOAT64); - TParameter* param1=new TParameter(&type, &str1.string, "", ""); - TParameter* param2=new TParameter(&type, &str2.string, "", ""); - - EXPECT_TRUE(param1->copy(param2)); - - EXPECT_EQ(a.vlen, 2); - EXPECT_EQ(a.vlen, b.vlen); - EXPECT_EQ(a[0], b[0]); - EXPECT_EQ(a[1], b[1]); - - delete param1; - delete param2; -} - -TEST(TParameter,copy_STRING_SCALAR_different_length) -{ - SGVector a(2); - SGVector b(3); - - a.set_const(1); - b.set_const(2); - - SGString str1(a); - SGString str2(b); - - TSGDataType type_a(CT_SCALAR, ST_STRING, PT_FLOAT64); - TSGDataType type_b(CT_SCALAR, ST_STRING, PT_FLOAT64); - TParameter* param1=new TParameter(&type_a, &str1.string, "", ""); - TParameter* param2=new TParameter(&type_b, &str2.string, "", ""); - - EXPECT_TRUE(param1->copy(param2)); - - /* to avoid memory errors when cleaning up, string is changed but vector - * still points to old array, which cannot be freed anymore. */ - b.vector=str2.string; - b.vlen=str2.slen; - - EXPECT_EQ(str1.slen, str2.slen); - EXPECT_EQ(str1.slen, 2); - EXPECT_EQ(a[0], b[0]); - EXPECT_EQ(a[1], b[1]); - - delete param1; - delete param2; -} - -TEST(TParameter,copy_STRING_SCALAR_target_empty) -{ - SGVector a(2); - SGVector b; - - a.set_const(1); - - SGString str1(a); - SGString str2(b); - - TSGDataType type_a(CT_SCALAR, ST_STRING, PT_FLOAT64); - TSGDataType type_b(CT_SCALAR, ST_STRING, PT_FLOAT64); - TParameter* param1=new TParameter(&type_a, &str1.string, "", ""); - TParameter* param2=new TParameter(&type_b, &str2.string, "", ""); - - EXPECT_TRUE(param1->copy(param2)); - - /* to avoid memory errors when cleaning up, string is changed but vector - * still points to old array, which cannot be freed anymore. */ - b.vector=str2.string; - b.vlen=str2.slen; - - EXPECT_EQ(str1.slen, str2.slen); - EXPECT_EQ(str1.slen, 2); - EXPECT_EQ(a[0], b[0]); - EXPECT_EQ(a[1], b[1]); - - delete param1; - delete param2; -} - -TEST(TParameter,copy_STRING_SCALAR_source_and_target_empty) -{ - SGVector a; - SGVector b; - - SGString str1(a); - SGString str2(b); - - TSGDataType type_a(CT_SCALAR, ST_STRING, PT_FLOAT64); - TSGDataType type_b(CT_SCALAR, ST_STRING, PT_FLOAT64); - TParameter* param1=new TParameter(&type_a, &str1.string, "", ""); - TParameter* param2=new TParameter(&type_b, &str2.string, "", ""); - - EXPECT_TRUE(param1->copy(param2)); - - /* to avoid memory errors when cleaning up, string is changed but vector - * still points to old array, which cannot be freed anymore. */ - b.vector=str2.string; - b.vlen=str2.slen; - - EXPECT_EQ(str1.slen, str2.slen); - EXPECT_EQ(str1.slen, 0); - - delete param1; - delete param2; -} - -TEST(TParameter,copy_SPARSE_SCALAR_same_length) -{ - SGMatrix a(2,1); - SGMatrix b(2,1); - - a.set_const(1); - b.set_const(2); - - CSparseFeatures* s1=new CSparseFeatures(a); - CSparseFeatures* s2=new CSparseFeatures(b); - - SGSparseVector vec1=s1->get_sparse_feature_vector(0); - vec1.features[1].feat_index=2; - SGSparseVector vec2=s2->get_sparse_feature_vector(0); - - TSGDataType type(CT_SCALAR, ST_SPARSE, PT_FLOAT64); - TParameter* param1=new TParameter(&type, &vec1, "", ""); - TParameter* param2=new TParameter(&type, &vec2, "", ""); - - EXPECT_TRUE(param1->copy(param2)); - - EXPECT_EQ(vec1.num_feat_entries, vec2.num_feat_entries); - EXPECT_EQ(vec1.num_feat_entries, 2); - EXPECT_EQ(vec1.features[0].feat_index, vec2.features[0].feat_index); - EXPECT_EQ(vec1.features[1].feat_index, vec2.features[1].feat_index); - EXPECT_EQ(vec1.features[0].entry, vec2.features[0].entry); - EXPECT_EQ(vec1.features[1].entry, vec2.features[1].entry); - - delete param1; - delete param2; - s1->free_sparse_feature_vector(0); - s2->free_sparse_feature_vector(0); - SG_UNREF(s1); - SG_UNREF(s2); -} - -TEST(TParameter,copy_SPARSE_SCALAR_different_length) -{ - SGMatrix a(2,1); - SGMatrix b(3,1); - - a.set_const(1); - b.set_const(2); - - CSparseFeatures* s1=new CSparseFeatures(a); - CSparseFeatures* s2=new CSparseFeatures(b); - - SGSparseVector vec1=s1->get_sparse_feature_vector(0); - SGSparseVector vec2=s2->get_sparse_feature_vector(0); - - TSGDataType type(CT_SCALAR, ST_SPARSE, PT_FLOAT64); - TParameter* param1=new TParameter(&type, &vec1, "", ""); - TParameter* param2=new TParameter(&type, &vec2, "", ""); - - EXPECT_TRUE(param1->copy(param2)); - - EXPECT_EQ(vec1.num_feat_entries, vec2.num_feat_entries); - EXPECT_EQ(vec2.num_feat_entries, 2); - EXPECT_EQ(vec1.features[0].feat_index, vec2.features[0].feat_index); - EXPECT_EQ(vec1.features[1].feat_index, vec2.features[1].feat_index); - EXPECT_EQ(vec1.features[0].entry, vec2.features[0].entry); - EXPECT_EQ(vec1.features[1].entry, vec2.features[1].entry); - - delete param1; - delete param2; - s1->free_sparse_feature_vector(0); - s2->free_sparse_feature_vector(0); - SG_UNREF(s1); - SG_UNREF(s2); -} - -TEST(TParameter,copy_SPARSE_SCALAR_target_empty) -{ - SGMatrix a(2,1); - SGMatrix b(3,1); - - a.set_const(1); - b.set_const(2); - - CSparseFeatures* s1=new CSparseFeatures(a); - CSparseFeatures* s2=new CSparseFeatures(b); - - SGSparseVector vec1=s1->get_sparse_feature_vector(0); - SGSparseVector vec2=s2->get_sparse_feature_vector(0); - void* temp=vec2.features; - vec2.features=NULL; - vec2.num_feat_entries=0; - - TSGDataType type(CT_SCALAR, ST_SPARSE, PT_FLOAT64); - TParameter* param1=new TParameter(&type, &vec1, "", ""); - TParameter* param2=new TParameter(&type, &vec2, "", ""); - - EXPECT_TRUE(param1->copy(param2)); - - EXPECT_EQ(vec1.num_feat_entries, vec2.num_feat_entries); - EXPECT_EQ(vec2.num_feat_entries, 2); - EXPECT_EQ(vec1.features[0].feat_index, vec2.features[0].feat_index); - EXPECT_EQ(vec1.features[1].feat_index, vec2.features[1].feat_index); - EXPECT_EQ(vec1.features[0].entry, vec2.features[0].entry); - EXPECT_EQ(vec1.features[1].entry, vec2.features[1].entry); - - delete param1; - delete param2; - SG_FREE(temp); - s1->free_sparse_feature_vector(0); - s2->free_sparse_feature_vector(0); - SG_UNREF(s1); - SG_UNREF(s2); -} - -TEST(TParameter,copy_SPARSE_SCALAR_source_and_target_empty) -{ - SGMatrix a(2,1); - SGMatrix b(3,1); - - a.set_const(1); - b.set_const(2); - - CSparseFeatures* s1=new CSparseFeatures(a); - CSparseFeatures* s2=new CSparseFeatures(b); - - SGSparseVector vec1=s1->get_sparse_feature_vector(0); - SGSparseVector vec2=s2->get_sparse_feature_vector(0); - void* temp1=vec1.features; - void* temp2=vec2.features; - vec2.features=NULL; - vec1.features=NULL; - vec1.num_feat_entries=0; - vec2.num_feat_entries=0; - - TSGDataType type(CT_SCALAR, ST_SPARSE, PT_FLOAT64); - TParameter* param1=new TParameter(&type, &vec1, "", ""); - TParameter* param2=new TParameter(&type, &vec2, "", ""); - - param1->copy(param2); - - EXPECT_EQ(vec1.num_feat_entries, vec2.num_feat_entries); - EXPECT_EQ(vec2.num_feat_entries, 0); - - delete param1; - delete param2; - SG_FREE(temp1); - SG_FREE(temp2); - s1->free_sparse_feature_vector(0); - s2->free_sparse_feature_vector(0); - SG_UNREF(s1); - SG_UNREF(s2); -} - -TEST(TParameter,copy_SGMATRIX_SPARSE_same_size) -{ - SGMatrix a(2,2); - SGMatrix b(2,2); - - a.set_const(1); - b.set_const(2); - - CSparseFeatures* s1=new CSparseFeatures(a); - CSparseFeatures* s2=new CSparseFeatures(b); - - SGSparseMatrix mat1=s1->get_sparse_feature_matrix(); - SGSparseMatrix mat2=s2->get_sparse_feature_matrix(); - - TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOAT64, - &mat1.num_vectors, &mat1.num_features); - TParameter* param1=new TParameter(&type, &mat1.sparse_matrix, "", ""); - TParameter* param2=new TParameter(&type, &mat2.sparse_matrix, "", ""); - - // float64_t accuracy=0.1; - // EXPECT_FALSE(param1->equals(param2, accuracy)); - EXPECT_TRUE(param1->copy(param2)); - // EXPECT_TRUE(param1->equals(param2, accuracy)); - - EXPECT_EQ(mat1[0].num_feat_entries, mat2[0].num_feat_entries); - EXPECT_EQ(mat1[0].features[0].feat_index, mat2[0].features[0].feat_index); - EXPECT_EQ(mat1[0].features[1].feat_index, mat2[0].features[1].feat_index); - EXPECT_EQ(mat1[0].features[0].entry, mat2[0].features[0].entry); - EXPECT_EQ(mat1[0].features[1].entry, mat2[0].features[1].entry); - EXPECT_EQ(mat1[1].num_feat_entries, mat2[1].num_feat_entries); - EXPECT_EQ(mat1[1].features[0].feat_index, mat2[1].features[0].feat_index); - EXPECT_EQ(mat1[1].features[1].feat_index, mat2[1].features[1].feat_index); - EXPECT_EQ(mat1[1].features[0].entry, mat2[1].features[0].entry); - EXPECT_EQ(mat1[1].features[1].entry, mat2[1].features[1].entry); - - delete param1; - delete param2; - SG_UNREF(s1); - SG_UNREF(s2); -} - -TEST(TParameter,copy_SGMATRIX_SPARSE_different_size) -{ - SGMatrix a(2,2); - SGMatrix b(2,3); - - a.set_const(1); - b.set_const(2); - - - CSparseFeatures* s1=new CSparseFeatures(a); - CSparseFeatures* s2=new CSparseFeatures(b); - - SGSparseMatrix mat1=s1->get_sparse_feature_matrix(); - SGSparseMatrix mat2=s2->get_sparse_feature_matrix(); - - TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOAT64, - &mat1.num_vectors, &mat1.num_features); - TParameter* param1=new TParameter(&type, &mat1.sparse_matrix, "", ""); - TParameter* param2=new TParameter(&type, &mat2.sparse_matrix, "", ""); - - // float64_t accuracy=0.1; - // EXPECT_FALSE(param1->equals(param2, accuracy)); - EXPECT_TRUE(param1->copy(param2)); - // EXPECT_TRUE(param1->equals(param2, accuracy)); - - EXPECT_EQ(mat1[0].num_feat_entries, mat2[0].num_feat_entries); - EXPECT_EQ(mat1[0].features[0].feat_index, mat2[0].features[0].feat_index); - EXPECT_EQ(mat1[0].features[1].feat_index, mat2[0].features[1].feat_index); - EXPECT_EQ(mat1[0].features[0].entry, mat2[0].features[0].entry); - EXPECT_EQ(mat1[0].features[1].entry, mat2[0].features[1].entry); - EXPECT_EQ(mat1[1].num_feat_entries, mat2[1].num_feat_entries); - EXPECT_EQ(mat1[1].features[0].feat_index, mat2[1].features[0].feat_index); - EXPECT_EQ(mat1[1].features[1].feat_index, mat2[1].features[1].feat_index); - EXPECT_EQ(mat1[1].features[0].entry, mat2[1].features[0].entry); - EXPECT_EQ(mat1[1].features[1].entry, mat2[1].features[1].entry); - - delete param1; - delete param2; - SG_UNREF(s1); - SG_UNREF(s2); -} - -TEST(TParameter,copy_SGMATRIX_SPARSE_target_empty) -{ - SGMatrix a(2,2); - - a.set_const(1); - - - CSparseFeatures* s1=new CSparseFeatures(a); - SGSparseMatrix mat1=s1->get_sparse_feature_matrix(); - SGSparseMatrix mat2(2,2); - - TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOAT64, - &mat1.num_vectors, &mat1.num_features); - TParameter* param1=new TParameter(&type, &mat1.sparse_matrix, "", ""); - TParameter* param2=new TParameter(&type, &mat2.sparse_matrix, "", ""); - - // float64_t accuracy=0.1; - // EXPECT_FALSE(param1->equals(param2, accuracy)); - EXPECT_TRUE(param1->copy(param2)); - // EXPECT_TRUE(param1->equals(param2, accuracy)); - - delete param1; - delete param2; - SG_UNREF(s1); -} - -TEST(TParameter,copy_SGMATRIX_SPARSE_source_and_target_empty) -{ - SGSparseMatrix mat1(2,2); - SGSparseMatrix mat2(2,2); - TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOAT64, - &mat1.num_vectors, &mat1.num_features); - TParameter* param1=new TParameter(&type, &mat1.sparse_matrix, "", ""); - TParameter* param2=new TParameter(&type, &mat2.sparse_matrix, "", ""); - - // float64_t accuracy=0.1; - EXPECT_TRUE(param1->copy(param2)); - // EXPECT_TRUE(param1->equals(param2, accuracy)); - - delete param1; - delete param2; -}