Navigation Menu

Skip to content

Commit

Permalink
- replace delete[] w/ SG_FREE
Browse files Browse the repository at this point in the history
- drop SGVector& typemaps
- whitespace fixes
  • Loading branch information
Soeren Sonnenburg committed May 13, 2012
1 parent a108880 commit c71396c
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 480 deletions.
45 changes: 0 additions & 45 deletions src/interfaces/csharp_modular/swig_typemaps.i
Expand Up @@ -85,51 +85,6 @@ TYPEMAP_SGVECTOR(float64_t, double, double)

#undef TYPEMAP_SGVECTOR

%define TYPEMAP_SGVECTOR_REF(SGTYPE, CTYPE, CSHARPTYPE)

%typemap(ctype, out="CTYPE*") shogun::SGVector<SGTYPE>&, const shogun::SGVector<SGTYPE>& %{int size, CTYPE*%}
%typemap(imtype, out="IntPtr", inattributes="int size, [MarshalAs(UnmanagedType.LPArray)]") shogun::SGVector<SGTYPE>&, const shogun::SGVector<SGTYPE>& %{CSHARPTYPE[]%}
%typemap(cstype) shogun::SGVector<SGTYPE>&, const shogun::SGVector<SGTYPE>& %{CSHARPTYPE[]%}

%typemap(in) shogun::SGVector<SGTYPE>& (SGVector<SGTYPE> temp), const shogun::SGVector<SGTYPE>& (SGVector<SGTYPE> temp) {
int32_t i;
SGTYPE *array;

if (!$input) {
SWIG_CSharpSetPendingException(SWIG_CSharpNullReferenceException, "null array");
return $null;
}

array = SG_MALLOC(SGTYPE, size);

if (!array) {
SWIG_CSharpSetPendingException(SWIG_CSharpOutOfMemoryException, "array memory allocation failed");
return $null;
}
for (i = 0; i < size; i++) {
array[i] = (SGTYPE)$input[i];
}

temp = shogun::SGVector<SGTYPE>((SGTYPE *)array, size);
$1 = &temp;
}

%typemap(csin) shogun::SGVector<SGTYPE>&, const shogun::SGVector<SGTYPE>&"$csinput.Length, $csinput"
%enddef

TYPEMAP_SGVECTOR_REF(char, signed char, byte)
TYPEMAP_SGVECTOR_REF(uint8_t, unsigned char, byte)
TYPEMAP_SGVECTOR_REF(int16_t, short, short)
TYPEMAP_SGVECTOR_REF(uint16_t, unsigned short, short)
TYPEMAP_SGVECTOR_REF(int32_t, int, int)
TYPEMAP_SGVECTOR_REF(uint32_t, unsigned int, int)
TYPEMAP_SGVECTOR_REF(int64_t, long, int)
TYPEMAP_SGVECTOR_REF(uint64_t, unsigned long, long)
TYPEMAP_SGVECTOR_REF(long long, long long, long)
TYPEMAP_SGVECTOR_REF(float32_t, float, float)
TYPEMAP_SGVECTOR_REF(float64_t, double, double)

#undef TYPEMAP_SGVECTOR_REF

%define TYPEMAP_SGMATRIX(SGTYPE, CTYPE, CSHARPTYPE)

Expand Down
83 changes: 0 additions & 83 deletions src/interfaces/java_modular/swig_typemaps.i
Expand Up @@ -163,89 +163,6 @@ TYPEMAP_SGVECTOR(float64_t, double, Double, jdouble, "()[D", "org/jblas/DoubleMa

#undef TYPEMAP_SGVECTOR

/* Two dimensional input/output arrays (references) */
%define TYPEMAP_SGVECTOR_REF(SGTYPE, JTYPE, JAVATYPE, JNITYPE, TOARRAY, CLASSDESC, CONSTRUCTOR)

%typemap(jni) shogun::SGVector<SGTYPE>&, const shogun::SGVector<SGTYPE>& %{jobject%}
%typemap(jtype) shogun::SGVector<SGTYPE>&, const shogun::SGVector<SGTYPE>& %{##JAVATYPE##Matrix%}
%typemap(jstype) shogun::SGVector<SGTYPE>&, const shogun::SGVector<SGTYPE>& %{##JAVATYPE##Matrix%}

%typemap(in) shogun::SGVector<SGTYPE>& (SGVector<SGTYPE> temp), const shogun::SGVector<SGTYPE>& (SGVector<SGTYPE> temp)
{
jclass cls;
jmethodID mid;
SGTYPE *array;
##JNITYPE##Array jarr;
JNITYPE *carr;
int32_t i, cols;
bool isVector;

if (!$input) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array");
return $null;
}

cls = JCALL1(GetObjectClass, jenv, $input);
if (!cls)
return $null;

mid = JCALL3(GetMethodID, jenv, cls, "isVector", "()Z");
if (!mid)
return $null;

isVector = (int32_t)JCALL2(CallIntMethod, jenv, $input, mid);
if (!isVector) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "vector expected");
return $null;
}

mid = JCALL3(GetMethodID, jenv, cls, "getColumns", "()I");
if (!mid)
return $null;

cols = (int32_t)JCALL2(CallIntMethod, jenv, $input, mid);
if (cols < 1) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null vector");
return $null;
}

mid = JCALL3(GetMethodID, jenv, cls, "toArray", TOARRAY);
if (!mid)
return $null;

jarr = (##JNITYPE##Array)JCALL2(CallObjectMethod, jenv, $input, mid);
carr = JCALL2(Get##JAVATYPE##ArrayElements, jenv, jarr, 0);
array = SG_MALLOC(SGTYPE, cols);
for (i = 0; i < cols; i++) {
array[i] = (SGTYPE)carr[i];
}

JCALL3(Release##JAVATYPE##ArrayElements, jenv, jarr, carr, 0);

temp = shogun::SGVector<SGTYPE>((SGTYPE *)array, cols);
$1 = &temp;
}

%typemap(javain) shogun::SGVector<SGTYPE>&, const shogun::SGVector<SGTYPE>& "$javainput"

%enddef

/*Define concrete examples of the TYPEMAP_SGVECTOR_REF macros */
TYPEMAP_SGVECTOR_REF(bool, boolean, Double, jdouble, "()[D", "org/jblas/DoubleMatrix", "(II[D)V")
TYPEMAP_SGVECTOR_REF(char, byte, Double, jdouble, "()[D", "org/jblas/DoubleMatrix", "(II[D)V")
TYPEMAP_SGVECTOR_REF(uint8_t, byte, Double, jdouble, "()[D", "org/jblas/DoubleMatrix", "(II[D)V")
TYPEMAP_SGVECTOR_REF(int16_t, short, Double, jdouble, "()[D", "org/jblas/DoubleMatrix", "(II[D)V")
TYPEMAP_SGVECTOR_REF(uint16_t, int, Double, jdouble, "()[D", "org/jblas/DoubleMatrix", "(II[D)V")
TYPEMAP_SGVECTOR_REF(int32_t, int, Double, jdouble, "()[D", "org/jblas/DoubleMatrix", "(II[D)V")
TYPEMAP_SGVECTOR_REF(uint32_t, long, Double, jdouble, "()[D", "org/jblas/DoubleMatrix", "(II[D)V")
TYPEMAP_SGVECTOR_REF(int64_t, int, Double, jdouble, "()[D", "org/jblas/DoubleMatrix", "(II[D)V")
TYPEMAP_SGVECTOR_REF(uint64_t, long, Double, jdouble, "()[D", "org/jblas/DoubleMatrix", "(II[D)V")
TYPEMAP_SGVECTOR_REF(long long, long, Double, jdouble, "()[D", "org/jblas/DoubleMatrix", "(II[D)V")
TYPEMAP_SGVECTOR_REF(float32_t, float, Float, jfloat, "()[F", "org/jblas/FloatMatrix","(II[F)V")
TYPEMAP_SGVECTOR_REF(float64_t, double, Double, jdouble, "()[D", "org/jblas/DoubleMatrix", "(II[D)V")

#undef TYPEMAP_SGVECTOR_REF

#else
#ifdef HAVE_UJMP
/* Two dimensional input/output arrays */
Expand Down

0 comments on commit c71396c

Please sign in to comment.