Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New typemap for in-place arrays of arbitrary number of dimensions:
(DATA_TYPE* INPLACE_ARRAY_FLAT, DIM_TYPE DIM_FLAT) Added unittests, updated documentation.
- Loading branch information
Tom Krauss
committed
May 25, 2015
1 parent
0844302
commit a49ad15
Showing
10 changed files
with
406 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <stdlib.h> | ||
#include <math.h> | ||
#include <iostream> | ||
#include "Flat.h" | ||
|
||
// The following macro defines a family of functions that work with 1D | ||
// arrays with the forms | ||
// | ||
// void SNAMEProcess(TYPE * array, int size); | ||
// | ||
// for any specified type TYPE (for example: short, unsigned int, long | ||
// long, etc.) with given short name SNAME (for example: short, uint, | ||
// longLong, etc.). The macro is then expanded for the given | ||
// TYPE/SNAME pairs. The resulting functions are for testing numpy | ||
// interfaces for: | ||
// | ||
// * in-place arrays (arbitrary number of dimensions) with a fixed number of elements | ||
// | ||
#define TEST_FUNCS(TYPE, SNAME) \ | ||
\ | ||
void SNAME ## Process(TYPE * array, int size) { \ | ||
for (int i=0; i<size; ++i) array[i] += 1; \ | ||
} | ||
|
||
TEST_FUNCS(signed char , schar ) | ||
TEST_FUNCS(unsigned char , uchar ) | ||
TEST_FUNCS(short , short ) | ||
TEST_FUNCS(unsigned short , ushort ) | ||
TEST_FUNCS(int , int ) | ||
TEST_FUNCS(unsigned int , uint ) | ||
TEST_FUNCS(long , long ) | ||
TEST_FUNCS(unsigned long , ulong ) | ||
TEST_FUNCS(long long , longLong ) | ||
TEST_FUNCS(unsigned long long, ulongLong) | ||
TEST_FUNCS(float , float ) | ||
TEST_FUNCS(double , double ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#ifndef FLAT_H | ||
#define FLAT_H | ||
|
||
// The following macro defines the prototypes for a family of | ||
// functions that work with arrays with the forms | ||
// | ||
// void SNAMEProcess(TYPE * array, int size); | ||
// | ||
// for any specified type TYPE (for example: short, unsigned int, long | ||
// long, etc.) with given short name SNAME (for example: short, uint, | ||
// longLong, etc.). The macro is then expanded for the given | ||
// TYPE/SNAME pairs. The resulting functions are for testing numpy | ||
// interfaces for: | ||
// | ||
// * in-place arrays (arbitrary number of dimensions) with a fixed number of elements | ||
// | ||
#define TEST_FUNC_PROTOS(TYPE, SNAME) \ | ||
\ | ||
void SNAME ## Process(TYPE * array, int size); \ | ||
|
||
TEST_FUNC_PROTOS(signed char , schar ) | ||
TEST_FUNC_PROTOS(unsigned char , uchar ) | ||
TEST_FUNC_PROTOS(short , short ) | ||
TEST_FUNC_PROTOS(unsigned short , ushort ) | ||
TEST_FUNC_PROTOS(int , int ) | ||
TEST_FUNC_PROTOS(unsigned int , uint ) | ||
TEST_FUNC_PROTOS(long , long ) | ||
TEST_FUNC_PROTOS(unsigned long , ulong ) | ||
TEST_FUNC_PROTOS(long long , longLong ) | ||
TEST_FUNC_PROTOS(unsigned long long, ulongLong) | ||
TEST_FUNC_PROTOS(float , float ) | ||
TEST_FUNC_PROTOS(double , double ) | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// -*- c++ -*- | ||
%module Flat | ||
|
||
%{ | ||
#define SWIG_FILE_WITH_INIT | ||
#include "Flat.h" | ||
%} | ||
|
||
// Get the NumPy typemaps | ||
%include "../numpy.i" | ||
|
||
%init %{ | ||
import_array(); | ||
%} | ||
|
||
%define %apply_numpy_typemaps(TYPE) | ||
|
||
%apply (TYPE* INPLACE_ARRAY_FLAT, int DIM_FLAT) {(TYPE* array, int size)}; | ||
|
||
%enddef /* %apply_numpy_typemaps() macro */ | ||
|
||
%apply_numpy_typemaps(signed char ) | ||
%apply_numpy_typemaps(unsigned char ) | ||
%apply_numpy_typemaps(short ) | ||
%apply_numpy_typemaps(unsigned short ) | ||
%apply_numpy_typemaps(int ) | ||
%apply_numpy_typemaps(unsigned int ) | ||
%apply_numpy_typemaps(long ) | ||
%apply_numpy_typemaps(unsigned long ) | ||
%apply_numpy_typemaps(long long ) | ||
%apply_numpy_typemaps(unsigned long long) | ||
%apply_numpy_typemaps(float ) | ||
%apply_numpy_typemaps(double ) | ||
|
||
// Include the header file to be wrapped | ||
%include "Flat.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.