Skip to content

Commit

Permalink
Merge pull request #703 from gsomix/buffer_protocol
Browse files Browse the repository at this point in the history
Python buffer protocol for Labels and SGVector
  • Loading branch information
Soeren Sonnenburg committed Aug 10, 2012
2 parents baebab2 + 6c5b634 commit 9ddf049
Show file tree
Hide file tree
Showing 8 changed files with 1,087 additions and 186 deletions.

This file was deleted.

12 changes: 11 additions & 1 deletion src/interfaces/modular/Features.i
Expand Up @@ -33,6 +33,7 @@

#ifndef SWIGPYTHON
#define PYPROTO_DENSEFEATURES(class_name, type_name, format_str, typecode)
#define PYPROTO_DENSELABELS(class_type, class_name, type_name, format_str, typecode)
#endif

/* Remove C Prefix */
Expand All @@ -49,10 +50,19 @@
%rename(CombinedFeatures) CCombinedFeatures;
%rename(CombinedDotFeatures) CCombinedDotFeatures;
%rename(Labels) CLabels;

PYPROTO_DENSELABELS(CDenseLabels, DenseLabels, float64_t, "d\0", NPY_FLOAT64)
%rename(DenseLabels) CDenseLabels;

PYPROTO_DENSELABELS(CBinaryLabels, BinaryLabels, float64_t, "d\0", NPY_FLOAT64)
%rename(BinaryLabels) CBinaryLabels;

PYPROTO_DENSELABELS(CMulticlassLabels, MulticlassLabels, float64_t, "d\0", NPY_FLOAT64)
%rename(MulticlassLabels) CMulticlassLabels;

PYPROTO_DENSELABELS(CRegressionLabels, RegressionLabels, float64_t, "d\0", NPY_FLOAT64)
%rename(RegressionLabels) CRegressionLabels;

%rename(StructuredLabels) CStructuredLabels;
%rename(MulticlassMultipleOutputLabels) CMulticlassMultipleOutputLabels;
%rename(RealFileFeatures) CRealFileFeatures;
Expand Down Expand Up @@ -346,7 +356,7 @@ namespace shogun
#endif

#ifdef USE_FLOAT32
PYPROTO_DENSEFEATURES(ShortRealFeatures, float64_t, "f\0", NPY_FLOAT32)
PYPROTO_DENSEFEATURES(ShortRealFeatures, float32_t, "f\0", NPY_FLOAT32)
%template(ShortRealFeatures) CDenseFeatures<float32_t>;
#endif

Expand Down
10 changes: 10 additions & 0 deletions src/interfaces/modular/Library.i
Expand Up @@ -6,8 +6,13 @@
*
* Written (W) 2009 Soeren Sonnenburg
* Copyright (C) 2009 Fraunhofer Institute FIRST and Max-Planck-Society
* Copyright (c) 2012 Evgeniy Andreev (gsomix)
*/

#ifndef SWIGPYTHON
#define PYPROTO_SGVECTOR(class_name, type_name, format_str, typecode)
#endif

%rename(Cache) CCache;
%rename(ListElement) CListElement;
%rename(List) CList;
Expand Down Expand Up @@ -236,6 +241,9 @@ namespace shogun
SERIALIZABLE_DUMMY(SGString<floatmax_t>);
#endif

%ignore SGVector<float64_t>::operator+=;
%ignore SGVector<float64_t>::operator+;

#ifdef USE_BOOL
%template(BoolVector) SGVector<bool>;
SERIALIZABLE_DUMMY(SGVector<bool>);
Expand Down Expand Up @@ -273,10 +281,12 @@ namespace shogun
SERIALIZABLE_DUMMY(SGVector<uint64_t>);
#endif
#ifdef USE_FLOAT32
PYPROTO_SGVECTOR(ShortRealVector, float32_t, "f\0", NPY_FLOAT32)
%template(ShortRealVector) SGVector<float32_t>;
SERIALIZABLE_DUMMY(SGVector<float32_t>);
#endif
#ifdef USE_FLOAT64
PYPROTO_SGVECTOR(RealVector, float64_t, "d\0", NPY_FLOAT64)
%template(RealVector) SGVector<float64_t>;
SERIALIZABLE_DUMMY(SGVector<float64_t>);
#endif
Expand Down

0 comments on commit 9ddf049

Please sign in to comment.