From e552db5ee55fa35369d050222eccc34dc68ca794 Mon Sep 17 00:00:00 2001 From: Viktor Gal Date: Fri, 7 Jul 2017 22:54:34 +0800 Subject: [PATCH] Add Serializable object and drop Wrapped classes refactor R installation --- examples/meta/generator/translate.py | 24 ++-- src/interfaces/r/CMakeLists.txt | 26 ++++ src/interfaces/r/DESCRIPTION.in | 26 ++++ src/interfaces/r/NAMESPACE | 1 + src/interfaces/r/r-install.sh | 33 ----- src/interfaces/swig/Library.i | 13 +- src/interfaces/swig/Library_includes.i | 1 - .../WrappedSGMatrix.h => io/Serializable.h} | 79 +++++----- src/shogun/lib/DynamicObjectArray.h | 12 ++ src/shogun/lib/WrappedBasic.h | 125 ---------------- src/shogun/lib/WrappedObjectArray.h | 135 ------------------ src/shogun/lib/WrappedSGVector.h | 111 -------------- tests/meta/tester.cpp | 6 +- 13 files changed, 127 insertions(+), 465 deletions(-) create mode 100644 src/interfaces/r/DESCRIPTION.in create mode 100644 src/interfaces/r/NAMESPACE rename src/shogun/{lib/WrappedSGMatrix.h => io/Serializable.h} (53%) delete mode 100644 src/shogun/lib/WrappedBasic.h delete mode 100644 src/shogun/lib/WrappedObjectArray.h delete mode 100644 src/shogun/lib/WrappedSGVector.h diff --git a/examples/meta/generator/translate.py b/examples/meta/generator/translate.py index 2637f7e5519..ce6eed7280c 100644 --- a/examples/meta/generator/translate.py +++ b/examples/meta/generator/translate.py @@ -178,8 +178,8 @@ def injectVarsStoring(self, statementList, programName, varsToStore): """ Injects statements at the end of the program that perform variable storing """ - storage = "__sg_storage" - storageFile = "__sg_storage_file" + storage = "sg_storage" + storageFile = "sg_storage_file" # TODO: handle directories storageFilename = { @@ -188,7 +188,7 @@ def injectVarsStoring(self, statementList, programName, varsToStore): # 'w' storageFilemode = {"Expr": {"CharLiteral": 'w'}} storageComment = {"Comment": " Serialize output for integration testing (automatically generated)"} - storageInit = {"Init": [{"ObjectType": "WrappedObjectArray"}, + storageInit = {"Init": [{"ObjectType": "DynamicObjectArray"}, {"Identifier": storage}, {"ArgumentList": []}]} storageFileInit = { @@ -214,16 +214,20 @@ def injectVarsStoring(self, statementList, programName, varsToStore): # i.e. one key # python2/3 compatible key accessing sgType = vartypeAST[list(vartypeAST.keys())[0]] - assert sgType in getBasicTypesToStore() or sgType in getSGTypesToStore() - if sgType in getBasicTypesToStore(): - methodNameSuffix = sgType - elif sgType in getSGTypesToStore(): - methodNameSuffix = getSGTypeToStoreMethodName(sgType) - + + if "cpp" in self.targetDict["FileExtension"]: + methodNameSuffix = "<%s>" % self.targetDict["Type"][sgType] + else: + if sgType in getBasicTypesToStore(): + methodNameSuffix = sgType + elif sgType in getSGTypesToStore(): + methodNameSuffix = getSGTypeToStoreMethodName(sgType) + methodNameSuffix = "_%s" % methodNameSuffix + methodCall = { "MethodCall": [{"Identifier": storage}, - {"Identifier": "append_wrapped_%s" % methodNameSuffix}, + {"Identifier": "append_element%s" % methodNameSuffix}, {"ArgumentList": [varnameIdentifierExpr, varnameExpr]}] } diff --git a/src/interfaces/r/CMakeLists.txt b/src/interfaces/r/CMakeLists.txt index 244829f7dcd..a75d5f88f60 100644 --- a/src/interfaces/r/CMakeLists.txt +++ b/src/interfaces/r/CMakeLists.txt @@ -11,6 +11,28 @@ ENDIF() GENERATE_INTERFACE_TARGET(r ${CMAKE_CURRENT_SOURCE_DIR} ${R_LIBRARIES}) set_target_properties(interface_r PROPERTIES PREFIX "") +EXECUTE_PROCESS(COMMAND ${R_EXECUTABLE} --slave -e "with(R.version, cat(sprintf('%s.%s', major, minor)))" + OUTPUT_VARIABLE R_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +EXECUTE_PROCESS(COMMAND ${R_EXECUTABLE} --slave -e "cat(R.version\\$platform)" + OUTPUT_VARIABLE PLATFORM + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +EXECUTE_PROCESS(COMMAND ${R_EXECUTABLE} --slave -e "cat(.Platform\\$OS.type)" + OUTPUT_VARIABLE OSTYPE + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "from time import gmtime, strftime; print(strftime("%Y-%m-%d %H:%M:%S", gmtime()))" + OUTPUT_VARIABLE DATE + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/DESCRIPTION.in ${CMAKE_CURRENT_BINARY_DIR}/DESCRIPTION @ONLY) + ADD_CUSTOM_COMMAND(TARGET interface_r POST_BUILD COMMAND echo 'wd="${CMAKE_CURRENT_BINARY_DIR}" \; setwd( wd ) \; f="shogun.R" \; fdata="shogun.RData" \; source( f ) \; save( list=ls( all=TRUE ) , file=fdata , compress=TRUE ) \; q( save="no" ) \;' | ${R_EXECUTABLE} --silent --no-save @@ -26,6 +48,10 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/shogun.RData DESTINATION ${R_COMPONENT_LIB_PATH}/shogun/R COMPONENT r) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/DESCRIPTION ${CMAKE_CURRENT_BINARY_DIR}/NAMESPACE + DESTINATION ${R_COMPONENT_LIB_PATH}/shogun + COMPONENT r) + install(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}/${R_COMPONENT_LIB_PATH}/shogun/Meta)") install(CODE "EXECUTE_PROCESS(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/r-install.sh \$ENV{DESTDIR}/${R_COMPONENT_LIB_PATH} shogun so saveRDS WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})") diff --git a/src/interfaces/r/DESCRIPTION.in b/src/interfaces/r/DESCRIPTION.in new file mode 100644 index 00000000000..48dc93c7a74 --- /dev/null +++ b/src/interfaces/r/DESCRIPTION.in @@ -0,0 +1,26 @@ +Package: shogun +Version: @VERSION@ +Date: @DATE@ +Title: The SHOGUN Machine Learning Toolbox +Author: Shogun Team +Maintainer: Shogun Team +Depends: R (>= 2.10.0) +Suggests: +Description: SHOGUN - is a new machine learning toolbox with focus on large + scale kernel methods and especially on Support Vector Machines (SVM) with focus + to bioinformatics. It provides a generic SVM object interfacing to several + different SVM implementations. Each of the SVMs can be combined with a variety + of the many kernels implemented. It can deal with weighted linear combination + of a number of sub-kernels, each of which not necessarily working on the same + domain, where an optimal sub-kernel weighting can be learned using Multiple + Kernel Learning. Apart from SVM 2-class classification and regression + problems, a number of linear methods like Linear Discriminant Analysis (LDA), + Linear Programming Machine (LPM), (Kernel) Perceptrons and also algorithms to + train hidden markov models are implemented. The input feature-objects can be + dense, sparse or strings and of type int/short/double/char and can be converted + into different feature types. Chains of preprocessors (e.g. substracting the + mean) can be attached to each feature object allowing for on-the-fly + pre-processing. +License: GPL Version 3 or later. +URL: http://www.shogun-toolbox.org +Built: @R_VERSION@; @PLATFORM@; @OSTYPE@; diff --git a/src/interfaces/r/NAMESPACE b/src/interfaces/r/NAMESPACE new file mode 100644 index 00000000000..f9b852d1486 --- /dev/null +++ b/src/interfaces/r/NAMESPACE @@ -0,0 +1 @@ +useDynLib(shogun, .registration = TRUE) diff --git a/src/interfaces/r/r-install.sh b/src/interfaces/r/r-install.sh index c173fb513ad..1c8a58de95f 100755 --- a/src/interfaces/r/r-install.sh +++ b/src/interfaces/r/r-install.sh @@ -9,35 +9,6 @@ DATE="`date '+%Y-%m-%d %H:%M:%S'`" PKGFILE="$1/$2/Meta/package.rds" SAVERDS="$4" -cat >"$1/$2/DESCRIPTION" < -Depends: R (>= 2.10.0) -Suggests: -Description: SHOGUN - is a new machine learning toolbox with focus on large - scale kernel methods and especially on Support Vector Machines (SVM) with focus - to bioinformatics. It provides a generic SVM object interfacing to several - different SVM implementations. Each of the SVMs can be combined with a variety - of the many kernels implemented. It can deal with weighted linear combination - of a number of sub-kernels, each of which not necessarily working on the same - domain, where an optimal sub-kernel weighting can be learned using Multiple - Kernel Learning. Apart from SVM 2-class classification and regression - problems, a number of linear methods like Linear Discriminant Analysis (LDA), - Linear Programming Machine (LPM), (Kernel) Perceptrons and also algorithms to - train hidden markov models are implemented. The input feature-objects can be - dense, sparse or strings and of type int/short/double/char and can be converted - into different feature types. Chains of preprocessors (e.g. substracting the - mean) can be attached to each feature object allowing for on-the-fly - pre-processing. -License: GPL Version 3 or later. -URL: http://www.shogun-toolbox.org -Built: $RVERSION; $PLATFORM; $OSTYPE; -EOF - echo "x=structure(list(DESCRIPTION = c(Package='$2',\ Version=\"$VERSION\",\ Date=\"$DATE\",\ @@ -58,10 +29,6 @@ echo "x=structure(list(DESCRIPTION = c(Package='$2',\ # R-MODULAR echo "Installing modular shogun interface for R" -cat >"$1/$2/NAMESPACE" <"$1/$2/R/$2" < %include %include -%include +namespace shogun +{ + /* Specialize DynamicObjectArray::append_element function */ + %template(append_element_real) CDynamicObjectArray::append_element; + %template(append_element_float) CDynamicObjectArray::append_element; + %template(append_element_int) CDynamicObjectArray::append_element; + %template(append_element_real_vector) CDynamicObjectArray::append_element>; + %template(append_element_float_vector) CDynamicObjectArray::append_element>; + %template(append_element_real_matrix) CDynamicObjectArray::append_element>; + %template(append_element_float_matrix) CDynamicObjectArray::append_element>; +} %include %include %include diff --git a/src/interfaces/swig/Library_includes.i b/src/interfaces/swig/Library_includes.i index 3c7287a5ec8..7a8fbdcedf8 100644 --- a/src/interfaces/swig/Library_includes.i +++ b/src/interfaces/swig/Library_includes.i @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include diff --git a/src/shogun/lib/WrappedSGMatrix.h b/src/shogun/io/Serializable.h similarity index 53% rename from src/shogun/lib/WrappedSGMatrix.h rename to src/shogun/io/Serializable.h index d5182f75a92..df28cd8f3b2 100644 --- a/src/shogun/lib/WrappedSGMatrix.h +++ b/src/shogun/io/Serializable.h @@ -2,7 +2,7 @@ * -*- coding: utf-8 -*- * vim: set fileencoding=utf-8 * - * Copyright (c) 2016, Shogun-Toolbox e.V. + * Copyright (c) 2017, Shogun-Toolbox e.V. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,81 +31,70 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * Authors: Heiko Strathmann */ -#ifdef USE_META_INTEGRATION_TESTS -#ifndef WRAPPED_SGMATRIX_H__ -#define WRAPPED_SGMATRIX_H__ +#ifndef SHOGUN_SERIALIZABLE_H__ +#define SHOGUN_SERIALIZABLE_H__ #include -#include -#include - namespace shogun { -/** @brief Simple wrapper class that allows to store any Shogun SGMatrix - * in a CSGObject, and therefore to make it serializable. Using a template - * argument that is not a Shogun parameter will cause a compile error when - * trying to register the passed value as a parameter in the constructors. +template +struct extract_value_type +{ + typedef T value_type; +}; + +template class X, typename T, typename ...Args> +struct extract_value_type> +{ + typedef T value_type; +}; + +/** @brief A trait that makes a none SGObject SG-serializable + * This only works with classes derived of SGReferencedData (SGVector, SGMatrix etc) + * and fundamental types (std::is_arithmetic) */ -template class CWrappedSGMatrix: public CSGObject +template class CSerializable: public CSGObject { public: /** Default constructor. Do not use. */ - CWrappedSGMatrix() : CSGObject() + CSerializable() : CSGObject() { - set_generic(); - register_params(); + init(); } /** Constructor. - * @param value Value to wrap as CSGObject. + * @param value Value to serialize as CSGObject. * @param value_name Name under which value is registered. */ - CWrappedSGMatrix(SGMatrix value, const char* value_name="") + CSerializable(T value, const char* value_name="") { - set_generic(); - register_params(); + init(); m_value = value; m_value_name = value_name; } /** @return name of the CSGObject, without C prefix */ - virtual const char* get_name() const { return "WrappedSGMatrix"; } + virtual const char* get_name() const { return "Serializable"; } private: - void register_params() + void init() { - m_value_name = "Unnamed"; - m_value = SGMatrix(); - - SG_ADD(&m_value, "value", "Wrapped value", MS_NOT_AVAILABLE); + set_generic::value_type>(); + m_value_name = "Unnamed"; + + SG_ADD(&m_value, "value", "Serialized value", MS_NOT_AVAILABLE); } protected: - /** Wrapped value. */ - SGMatrix m_value; + /** Serialized value. */ + T m_value; - /** Name of wrapped value */ + /** Name of serialized value */ const char* m_value_name; }; -template class CWrappedSGMatrix; -template class CWrappedSGMatrix; -template class CWrappedSGMatrix; -template class CWrappedSGMatrix; -template class CWrappedSGMatrix; -template class CWrappedSGMatrix; -template class CWrappedSGMatrix; -template class CWrappedSGMatrix; -template class CWrappedSGMatrix; -template class CWrappedSGMatrix; -template class CWrappedSGMatrix; -template class CWrappedSGMatrix; -template class CWrappedSGMatrix; - }; -#endif // WRAPPED_SGMATRIX_H__ -#endif // USE_META_INTEGRATION_TESTS +#endif // SHOGUN_SERIALIZABLE_H_ diff --git a/src/shogun/lib/DynamicObjectArray.h b/src/shogun/lib/DynamicObjectArray.h index 7209c058576..cad8360b578 100644 --- a/src/shogun/lib/DynamicObjectArray.h +++ b/src/shogun/lib/DynamicObjectArray.h @@ -17,6 +17,7 @@ #include #include #include +#include namespace shogun { @@ -277,6 +278,17 @@ class CDynamicObjectArray : public CSGObject return success; } + template + inline bool append_element(typename std::enable_if>::value, T>::type e, const char* name="") + { + auto serializedElement = new CSerializable(e, name); + bool success = m_array.append_element(serializedElement); + if (success) + SG_REF(serializedElement); + + return success; + } + /** append array element to the end of array * * @param e element to append diff --git a/src/shogun/lib/WrappedBasic.h b/src/shogun/lib/WrappedBasic.h deleted file mode 100644 index a3614d98aef..00000000000 --- a/src/shogun/lib/WrappedBasic.h +++ /dev/null @@ -1,125 +0,0 @@ -/* - * -*- coding: utf-8 -*- - * vim: set fileencoding=utf-8 - * - * Copyright (c) 2016, Shogun-Toolbox e.V. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * Authors: Heiko Strathmann - */ -#ifdef USE_META_INTEGRATION_TESTS -#ifndef WRAPPED_BASIC_H__ -#define WRAPPED_BASIC_H__ - -#include -#include - -namespace -{ - template - T default_value() - { - return T(); - } - - template <> - char default_value() - { - return '0'; - } -} - -namespace shogun -{ - -/** @brief Simple wrapper class that allows to store any Shogun basic parameter - * (i.e. float64_t, int64_t, char, etc) in a CSGObject, and therefore to - * make it serializable. Using a template argument that is not a Shogun - * parameter will cause a compile error when trying to register the passed - * value as a parameter in the constructors. - */ -template class CWrappedBasic: public CSGObject -{ -public: - /** Default constructor. Do not use. */ - CWrappedBasic() : CSGObject() - { - set_generic(); - register_params(); - } - - /** Constructor. - * @param value Value to wrap as CSGObject. - * @param value_name Name under which value is registered. - */ - CWrappedBasic(T value, const char* value_name="") - { - set_generic(); - register_params(); - m_value = value; - m_value_name = value_name; - } - - /** @return name of the CSGObject, without C prefix */ - virtual const char* get_name() const { return "WrappedBasic"; } - -private: - void register_params() - { - m_value_name = "Unnamed"; - m_value = ::default_value(); - - SG_ADD(&m_value, "value", "Wrapped value", MS_NOT_AVAILABLE); - } - -protected: - /** Wrapped value. */ - T m_value; - - /** Name of wrapped value */ - const char* m_value_name; -}; - -template class CWrappedBasic; -template class CWrappedBasic; -template class CWrappedBasic; -template class CWrappedBasic; -template class CWrappedBasic; -template class CWrappedBasic; -template class CWrappedBasic; -template class CWrappedBasic; -template class CWrappedBasic; -template class CWrappedBasic; -template class CWrappedBasic; -template class CWrappedBasic; -template class CWrappedBasic; - -}; -#endif // WRAPPED_BASIC_H__ -#endif // USE_META_INTEGRATION_TESTS diff --git a/src/shogun/lib/WrappedObjectArray.h b/src/shogun/lib/WrappedObjectArray.h deleted file mode 100644 index 33603cdda49..00000000000 --- a/src/shogun/lib/WrappedObjectArray.h +++ /dev/null @@ -1,135 +0,0 @@ -/* - * -*- coding: utf-8 -*- - * vim: set fileencoding=utf-8 - * - * Copyright (c) 2016, Shogun-Toolbox e.V. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * Authors: Heiko Strathmann - */ - -#include - -#ifdef USE_META_INTEGRATION_TESTS - -#ifndef WRAPPED_OBJECT_ARRAY_H__ -#define WRAPPED_OBJECT_ARRAY_H__ - -#include -#include -#include -#include - - -namespace shogun -{ - -/** @brief Specialization of CDynamicObjectArray that adds methods to append - * wrapped elements to make them serializable. Objects are wrapped through the - * classes CWrappedBasic, CWrappedSGVector, CWrappedSGMatrix. - */ -class CWrappedObjectArray : public CDynamicObjectArray -{ -public: - CWrappedObjectArray(): CDynamicObjectArray() { } - - /** Works as CDynamicObjectArray::append_element, but accepts basic Shogun types, - * which are wrapped through CWrappedBasicObject. - * - * @param data Data element to append, after being wrapped. - * @param data_name Name of wrapped data element. - */ - template bool append_wrapped(T data, const char* data_name="") - { - return this->append_element(new CWrappedBasic(data, data_name)); - } - - /** Works as CDynamicObjectArray::append_element, but accepts SGVector, - * which are wrapped through CWrappedSGVectorObject. - * - * @param data Data element to append, after being wrapped. - * @param data_name Name of wrapped data element. - */ - template bool append_wrapped(SGVector data, const char* data_name="") - { - return this->append_element(new CWrappedSGVector(data, - data_name)); - } - - /** Works as CDynamicObjectArray::append_element, but accepts SGMatrix, - * which are wrapped through CWrappedSGVectorObject. - * - * @param data Data element to append, after being wrapped. - * @param data_name Name of wrapped data element. - */ - template bool append_wrapped(SGMatrix data, const char* data_name="") - { - return this->append_element(new CWrappedSGMatrix(data, - data_name)); - } - - /** @return name of the CSGObject, without C prefix */ - virtual const char* get_name() const { return "WrappedObjectArray"; } - -#define APPEND_WRAPPED_TEMPLATE(META_TYPE, SG_TYPE) \ - /** Explicit instantiation of append_wrapped \ - * \ - * @param data Data element to append, after being wrapped. \ - * @param data_name Name of wrapped data element. \ - */ \ - bool append_wrapped_##META_TYPE(SG_TYPE data, const char* data_name="") \ -{ \ - return this->append_wrapped(data, data_name); \ -} - - APPEND_WRAPPED_TEMPLATE(real, float64_t) - APPEND_WRAPPED_TEMPLATE(float, float32_t) - APPEND_WRAPPED_TEMPLATE(int, int32_t) - APPEND_WRAPPED_TEMPLATE(real_vector, SGVector) - APPEND_WRAPPED_TEMPLATE(float_vector, SGVector) - APPEND_WRAPPED_TEMPLATE(real_matrix, SGMatrix) - APPEND_WRAPPED_TEMPLATE(float_matrix, SGMatrix) - - /** Explicit instantiation of append_wrapped, for single element containers - * (Octave converts single element arrays to scalars and our typemaps take - * that for real) - * - * @param data Data element to append, after being wrapped. - * @param data_name Name of wrapped data element. - */ - bool append_wrapped_real_vector(float64_t data, const char* data_name="") - { - SGVector wrap(1); - wrap[0] = data; - return this->append_wrapped(wrap, data_name); - } -}; -} -#endif // WRAPPED_OBJECT_ARRAY_H__ -#endif // USE_META_INTEGRATION_TESTS diff --git a/src/shogun/lib/WrappedSGVector.h b/src/shogun/lib/WrappedSGVector.h deleted file mode 100644 index 8ada66676e0..00000000000 --- a/src/shogun/lib/WrappedSGVector.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * -*- coding: utf-8 -*- - * vim: set fileencoding=utf-8 - * - * Copyright (c) 2016, Shogun-Toolbox e.V. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * Authors: Heiko Strathmann - */ -#ifdef USE_META_INTEGRATION_TESTS -#ifndef WRAPPED_SGVECTOR_H__ -#define WRAPPED_SGVECTOR_H__ - -#include -#include -#include - - -namespace shogun -{ - -/** @brief Simple wrapper class that allows to store any Shogun SGVector - * in a CSGObject, and therefore to make it serializable. Using a template - * argument that is not a Shogun parameter will cause a compile error when - * trying to register the passed value as a parameter in the constructors. - */ -template class CWrappedSGVector: public CSGObject -{ -public: - /** Default constructor. Do not use. */ - CWrappedSGVector() : CSGObject() - { - set_generic(); - register_params(); - } - - /** Constructor. - * @param value Value to wrap as CSGObject. - * @param value_name Name under which value is registered. - */ - CWrappedSGVector(SGVector value, const char* value_name="") - { - set_generic(); - register_params(); - m_value = value; - m_value_name = value_name; - } - - /** @return name of the CSGObject, without C prefix */ - virtual const char* get_name() const { return "WrappedSGVector"; } - -private: - void register_params() - { - m_value_name = "Unnamed"; - m_value = SGVector(); - - SG_ADD(&m_value, "value", "Wrapped value", MS_NOT_AVAILABLE); - } - -protected: - /** Wrapped value. */ - SGVector m_value; - - /** Name of wrapped value */ - const char* m_value_name; -}; - -template class CWrappedSGVector; -template class CWrappedSGVector; -template class CWrappedSGVector; -template class CWrappedSGVector; -template class CWrappedSGVector; -template class CWrappedSGVector; -template class CWrappedSGVector; -template class CWrappedSGVector; -template class CWrappedSGVector; -template class CWrappedSGVector; -template class CWrappedSGVector; -template class CWrappedSGVector; -template class CWrappedSGVector; - -}; -#endif // WRAPPED_SGVECTOR_H__ -#endif // USE_META_INTEGRATION_TESTS diff --git a/tests/meta/tester.cpp b/tests/meta/tester.cpp index 607ad992530..8ce1aa631e2 100644 --- a/tests/meta/tester.cpp +++ b/tests/meta/tester.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include @@ -33,8 +33,8 @@ int main(int argc, const char *argv[]) SG_REF(f); SG_REF(f_ref); - CWrappedObjectArray* a = new CWrappedObjectArray(); - CWrappedObjectArray* a_ref = new CWrappedObjectArray(); + CDynamicObjectArray* a = new CDynamicObjectArray(); + CDynamicObjectArray* a_ref = new CDynamicObjectArray(); SG_REF(a); SG_REF(a_ref);