Skip to content

Instantly share code, notes, and snippets.

template<class T> class SGVector : public SGReferencedData
{
// If have ViennaCL: declare a pointer to GPU memory
// So only one GPU object is created for one SGVector
#ifdef HAVE_VIENNACL
typedef viennacl::backend::mem_handle VCLMemoryArray;
public:
shared_pointer<VCLMemoryArray> GPUptr(nullptr);
bool on_GPU():
@OXPHOS
OXPHOS / cereal_test.cpp
Created May 15, 2016 04:43
Serialization
#include <cereal/types/unordered_map.hpp>
#include <cereal/types/memory.hpp>
#include <cereal/archives/json.hpp>
#include <fstream>
struct MyRecord
{
uint8_t x = 10, y = 100;
float z = 3.2;

Goal

Replace current Shogun serialization method with Cereal libarary

Include Cereal library

Cereal library is a header only library so no build or make is required. However, Shogun needs to make sure Cereal library is ready for use.

Thus, CMakeList needs to check and download Cereal if necessary:

IF (Cereal)
namespace linalg
{
    // Always return CPU T type
    template<class T>
    T dot(SGVector<T> a, SGVector<T> b)
    {
        Base<T> base_a = factory(a); // Factory: use ifdef to check if GPUbackend exists and GPU is turned on
        Base<T> base_b = factory(b);
        return base_a.dot(base_b)
    }
#include <shogun/lib/config.h>
#include <shogun/lib/SGVector.h>
#include <memory>
#include <shogun/mathematics/eigen3.h>
class linalg_new
{
shared_ptr<CPUBackend> cpu_backend;
shared_ptr<GPUBackend> gpu_backend;
# Cereal Serialization Library
FIND_PACKAGE(Cereal)
IF(NOT CEREAL_FOUND)
include(external/Cereal)
LIST(APPEND INCLUDES ${CEREAL_INCLUDE_DIR})
ELSE()
LIST(APPEND INCLUDES ${CEREAL_INCLUDE_DIR})
ENDIF()
@OXPHOS
OXPHOS / qda.sg
Last active May 28, 2016 11:27
with ruby pda.get_cov() error
CSVFile f_feats_train("../../data/classifier_4class_2d_linear_features_train.dat")
CSVFile f_feats_test("../../data/classifier_4class_2d_linear_features_test.dat")
CSVFile f_labels_train("../../data/classifier_4class_2d_linear_labels_train.dat")
CSVFile f_labels_test("../../data/classifier_4class_2d_linear_labels_test.dat")
#![create_features]
RealFeatures features_train(f_feats_train)
RealFeatures features_test(f_feats_test)
MulticlassLabels labels_train(f_labels_train)
MulticlassLabels labels_test(f_labels_test)
@OXPHOS
OXPHOS / qda.sg
Created May 27, 2016 14:38
with '0' error when making cookbook
CSVFile f_feats_train("../../data/classifier_4class_2d_linear_features_train.dat")
CSVFile f_feats_test("../../data/classifier_4class_2d_linear_features_test.dat")
CSVFile f_labels_train("../../data/classifier_4class_2d_linear_labels_train.dat")
CSVFile f_labels_test("../../data/classifier_4class_2d_linear_labels_test.dat")
#![create_features]
RealFeatures features_train(f_feats_train)
RealFeatures features_test(f_feats_test)
MulticlassLabels labels_train(f_labels_train)
MulticlassLabels labels_test(f_labels_test)
#include <shogun/lib/config.h>
#include <shogun/mathematics/linalg/linalgRefactor.h>
#include <shogun/lib/SGVector.h>
#include <shogun/mathematics/eigen3.h>
#include <iostream>
#include <memory>
template <class T> CPU_Vector<T>::CPU_Vector(const SGVector<T> &vector)
{
CPUptr = const_cast<SGVector<T>*>(&vector);
@OXPHOS
OXPHOS / errors
Last active May 31, 2016 15:47
unique_ptr error
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2457:27: error:
implicit instantiation of undefined member 'GPU_Vector<int>::GPUArray'
static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2658:13: note:
in instantiation of member function 'std::__1::default_delete<GPU_Vector<int>::GPUArray>::operator()' requested
here
__ptr_.second()(__tmp);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2626:46: note: