Commit ed3cfe4e authored by Karl Wette's avatar Karl Wette

SWIG: add wrappings for LALInference

- add the usual SWIG paraphernalia
- explicitly specify the size of LALInferenceTypeSize[]
- make string constants const char *const to prevent memory leaks
- comment out unimplemented prototypes
Original: 8db54a81f48545ef4443a9924413e58a877ee86f
parent dabe7414
......@@ -18,6 +18,7 @@ SUBDIRS = \
debian \
include \
src \
swig \
test
pkgconfigdir = $(libdir)/pkgconfig
......
......@@ -13,6 +13,9 @@ AC_CONFIG_FILES([ \
include/Makefile \
include/lal/Makefile \
src/Makefile \
swig/Makefile \
swig/octave/Makefile \
swig/python/Makefile \
test/Makefile
])
AM_INIT_AUTOMAKE([1.11 foreign color-tests parallel-tests])
......@@ -60,6 +63,9 @@ LALSUITE_ENABLE_LALINSPIRAL
LALSUITE_ENABLE_LALPULSAR
LALSUITE_ENABLE_LALXML
# enable SWIG wrapping modules
LALSUITE_ENABLE_SWIG
# put version/configure info in config header
lalinference_version_major=`echo "$VERSION" | cut -d. -f1`
lalinference_version_minor=`echo "$VERSION" | cut -d. -f2`
......@@ -150,6 +156,10 @@ LALSUITE_CHECK_LIB([LALPulsar],[1.6.0],[XLALComputeFaFb],[lal/ComputeFstat.h])
# check for lalxml
LALSUITE_CHECK_OPT_LIB([LALXML],[1.1.5],[XLALXMLFilePrintElements],[lal/LALXML.h])
# configure SWIG wrapping modules
LALSUITE_USE_SWIG([XLALInference LALInference XLAL LAL])
LALSUITE_SWIG_DEPENDS([lal],[true])
# add gcc specific flags
LALSUITE_ADD_GCC_FLAGS
......@@ -163,6 +173,8 @@ echo "
LALInference has now been successfully configured:
* LALXML library support is $LALXML_ENABLE_VAL
* SWIG wrapping module for Octave is $SWIG_OCTAVE_ENABLE_VAL
* SWIG wrapping module for Python is $SWIG_PYTHON_ENABLE_VAL
and will be installed under the directory:
......
......@@ -6,6 +6,7 @@ EXTRA_DIST = \
install-sh \
lalsuite_build.m4 \
lalsuite_gccflags.m4 \
lalsuite_swig.m4 \
libtool.m4 \
ltmain.sh \
ltoptions.m4 \
......@@ -13,4 +14,5 @@ EXTRA_DIST = \
ltversion.m4 \
lt~obsolete.m4 \
missing \
test-driver
test-driver \
py-compile
../../gnuscripts/lalsuite_swig.m4
\ No newline at end of file
#!/bin/sh
# py-compile - Compile a Python program
scriptversion=2011-06-08.12; # UTC
# Copyright (C) 2000-2012 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# This file is maintained in Automake, please report
# bugs to <bug-automake@gnu.org> or send patches to
# <automake-patches@gnu.org>.
if [ -z "$PYTHON" ]; then
PYTHON=python
fi
me=py-compile
usage_error ()
{
echo "$me: $*" >&2
echo "Try '$me --help' for more information." >&2
exit 1
}
basedir=
destdir=
while test $# -ne 0; do
case "$1" in
--basedir)
if test $# -lt 2; then
usage_error "option '--basedir' requires an argument"
else
basedir=$2
fi
shift
;;
--destdir)
if test $# -lt 2; then
usage_error "option '--destdir' requires an argument"
else
destdir=$2
fi
shift
;;
-h|--help)
cat <<\EOF
Usage: py-compile [--help] [--version] [--basedir DIR] [--destdir DIR] FILES..."
Byte compile some python scripts FILES. Use --destdir to specify any
leading directory path to the FILES that you don't want to include in the
byte compiled file. Specify --basedir for any additional path information you
do want to be shown in the byte compiled file.
Example:
py-compile --destdir /tmp/pkg-root --basedir /usr/share/test test.py test2.py
Report bugs to <bug-automake@gnu.org>.
EOF
exit $?
;;
-v|--version)
echo "$me $scriptversion"
exit $?
;;
--)
shift
break
;;
-*)
usage_error "unrecognized option '$1'"
;;
*)
break
;;
esac
shift
done
files=$*
if test -z "$files"; then
usage_error "no files given"
fi
# if basedir was given, then it should be prepended to filenames before
# byte compilation.
if [ -z "$basedir" ]; then
pathtrans="path = file"
else
pathtrans="path = os.path.join('$basedir', file)"
fi
# if destdir was given, then it needs to be prepended to the filename to
# byte compile but not go into the compiled file.
if [ -z "$destdir" ]; then
filetrans="filepath = path"
else
filetrans="filepath = os.path.normpath('$destdir' + os.sep + path)"
fi
$PYTHON -c "
import sys, os, py_compile, imp
files = '''$files'''
sys.stdout.write('Byte-compiling python modules...\n')
for file in files.split():
$pathtrans
$filetrans
if not os.path.exists(filepath) or not (len(filepath) >= 3
and filepath[-3:] == '.py'):
continue
sys.stdout.write(file)
sys.stdout.flush()
if hasattr(imp, 'get_tag'):
py_compile.compile(filepath, imp.cache_from_source(filepath), path)
else:
py_compile.compile(filepath, filepath + 'c', path)
sys.stdout.write('\n')" || exit $?
# this will fail for python < 1.5, but that doesn't matter ...
$PYTHON -O -c "
import sys, os, py_compile, imp
# pypy does not use .pyo optimization
if hasattr(sys, 'pypy_translation_info'):
sys.exit(0)
files = '''$files'''
sys.stdout.write('Byte-compiling python modules (optimized versions) ...\n')
for file in files.split():
$pathtrans
$filetrans
if not os.path.exists(filepath) or not (len(filepath) >= 3
and filepath[-3:] == '.py'):
continue
sys.stdout.write(file)
sys.stdout.flush()
if hasattr(imp, 'get_tag'):
py_compile.compile(filepath, imp.cache_from_source(filepath, False), path)
else:
py_compile.compile(filepath, filepath + 'o', path)
sys.stdout.write('\n')" 2>/dev/null || :
# Local Variables:
# mode: shell-script
# sh-indentation: 2
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-time-zone: "UTC"
# time-stamp-end: "; # UTC"
# End:
......@@ -43,18 +43,18 @@
#define UNUSED
#endif
size_t LALInferenceTypeSize[] = {sizeof(INT4),
sizeof(INT8),
sizeof(UINT4),
sizeof(REAL4),
sizeof(REAL8),
sizeof(COMPLEX8),
sizeof(COMPLEX16),
sizeof(gsl_matrix *),
sizeof(REAL8Vector *),
sizeof(UINT4Vector *),
sizeof(CHAR *),
sizeof(void *)
size_t LALInferenceTypeSize[12] = {sizeof(INT4),
sizeof(INT8),
sizeof(UINT4),
sizeof(REAL4),
sizeof(REAL8),
sizeof(COMPLEX8),
sizeof(COMPLEX16),
sizeof(gsl_matrix *),
sizeof(REAL8Vector *),
sizeof(UINT4Vector *),
sizeof(CHAR *),
sizeof(void *)
};
......
......@@ -139,7 +139,7 @@ typedef enum
LALINFERENCE_FRAME_SYSTEM
} LALInferenceFrame;
extern size_t LALInferenceTypeSize[];
extern size_t LALInferenceTypeSize[12];
/** The LALInferenceVariableItem list node structure
* This should only be accessed using the accessor functions below
......
......@@ -41,35 +41,35 @@
#include <lal/LALStdlib.h>
const char *cycleArrayName = "Proposal Cycle";
const char *cycleArrayLengthName = "Proposal Cycle Length";
const char *cycleArrayCounterName = "Proposal Cycle Counter";
const char *const cycleArrayName = "Proposal Cycle";
const char *const cycleArrayLengthName = "Proposal Cycle Length";
const char *const cycleArrayCounterName = "Proposal Cycle Counter";
const char *LALInferenceCurrentProposalName = "Current Proposal";
const char *const LALInferenceCurrentProposalName = "Current Proposal";
/* Proposal Names */
const char *singleAdaptProposalName = "Single";
const char *singleProposalName = "Single";
const char *orbitalPhaseJumpName = "OrbitalPhase";
const char *inclinationDistanceName = "InclinationDistance";
const char *covarianceEigenvectorJumpName = "CovarianceEigenvector";
const char *skyLocWanderJumpName = "SkyLocWander";
const char *differentialEvolutionFullName = "DifferentialEvolutionFull";
const char *differentialEvolutionMassesName = "DifferentialEvolutionMasses";
const char *differentialEvolutionSpinsName = "DifferentialEvolutionSpins";
const char *differentialEvolutionPhysicalSpinsName = "DifferentialEvolutionPhysicalSpins";
const char *differentialEvolutionExtrinsicName = "DifferentialEvolutionExtrinsic";
const char *drawApproxPriorName = "DrawApproxPrior";
const char *skyReflectDetPlaneName = "SkyReflectDetPlane";
const char *skyRingProposalName = "SkyRingProposal";
const char *PSDFitJumpName = "PSDFitJump";
const char *rotateSpinsName = "RotateSpins";
const char *polarizationPhaseJumpName = "PolarizationPhase";
const char *polarizationCorrPhaseJumpName = "CorrPolarizationPhase";
const char *distanceQuasiGibbsProposalName = "DistanceQuasiGibbs";
const char *orbitalPhaseQuasiGibbsProposalName = "OrbitalPhaseQuasiGibbs";
const char *extrinsicParamProposalName = "ExtrinsicParamProposal";
const char *KDNeighborhoodProposalName = "KDNeighborhood";
const char *const singleAdaptProposalName = "Single";
const char *const singleProposalName = "Single";
const char *const orbitalPhaseJumpName = "OrbitalPhase";
const char *const inclinationDistanceName = "InclinationDistance";
const char *const covarianceEigenvectorJumpName = "CovarianceEigenvector";
const char *const skyLocWanderJumpName = "SkyLocWander";
const char *const differentialEvolutionFullName = "DifferentialEvolutionFull";
const char *const differentialEvolutionMassesName = "DifferentialEvolutionMasses";
const char *const differentialEvolutionSpinsName = "DifferentialEvolutionSpins";
const char *const differentialEvolutionPhysicalSpinsName = "DifferentialEvolutionPhysicalSpins";
const char *const differentialEvolutionExtrinsicName = "DifferentialEvolutionExtrinsic";
const char *const drawApproxPriorName = "DrawApproxPrior";
const char *const skyReflectDetPlaneName = "SkyReflectDetPlane";
const char *const skyRingProposalName = "SkyRingProposal";
const char *const PSDFitJumpName = "PSDFitJump";
const char *const rotateSpinsName = "RotateSpins";
const char *const polarizationPhaseJumpName = "PolarizationPhase";
const char *const polarizationCorrPhaseJumpName = "CorrPolarizationPhase";
const char *const distanceQuasiGibbsProposalName = "DistanceQuasiGibbs";
const char *const orbitalPhaseQuasiGibbsProposalName = "OrbitalPhaseQuasiGibbs";
const char *const extrinsicParamProposalName = "ExtrinsicParamProposal";
const char *const KDNeighborhoodProposalName = "KDNeighborhood";
/* Mode hopping fraction for the differential evoultion proposals. */
static const REAL8 modeHoppingFrac = 1.0;
......
......@@ -88,34 +88,34 @@
#define ACCEPTSUFFIX "accepted"
#define PROPOSEDSUFFIX "proposed"
extern const char *cycleArrayName;
extern const char *cycleArrayLengthName;
extern const char *cycleArrayCounterName;
extern const char *const cycleArrayName;
extern const char *const cycleArrayLengthName;
extern const char *const cycleArrayCounterName;
/* Proposal Names */
extern const char *singleAdaptProposalName;
extern const char *singleProposalName;
extern const char *orbitalPhaseJumpName;
extern const char *inclinationDistanceName;
extern const char *covarianceEigenvectorJumpName;
extern const char *skyLocWanderJumpName;
extern const char *differentialEvolutionFullName;
extern const char *differentialEvolutionMassesName;
extern const char *differentialEvolutionSpinsName;
extern const char *differentialEvolutionExtrinsicName;
extern const char *drawApproxPriorName;
extern const char *skyReflectDetPlaneName;
extern const char *rotateSpinsName;
extern const char *polarizationPhaseJumpName;
extern const char *distanceQuasiGibbsProposalName;
extern const char *orbitalPhaseQuasiGibbsProposalName;
extern const char *extrinsicParamProposalName;
extern const char *KDNeighborhoodProposalName;
extern const char *const singleAdaptProposalName;
extern const char *const singleProposalName;
extern const char *const orbitalPhaseJumpName;
extern const char *const inclinationDistanceName;
extern const char *const covarianceEigenvectorJumpName;
extern const char *const skyLocWanderJumpName;
extern const char *const differentialEvolutionFullName;
extern const char *const differentialEvolutionMassesName;
extern const char *const differentialEvolutionSpinsName;
extern const char *const differentialEvolutionExtrinsicName;
extern const char *const drawApproxPriorName;
extern const char *const skyReflectDetPlaneName;
extern const char *const rotateSpinsName;
extern const char *const polarizationPhaseJumpName;
extern const char *const distanceQuasiGibbsProposalName;
extern const char *const orbitalPhaseQuasiGibbsProposalName;
extern const char *const extrinsicParamProposalName;
extern const char *const KDNeighborhoodProposalName;
/** The name of the variable that will store the name of the current
proposal function. */
extern const char *LALInferenceCurrentProposalName;
extern const char *const LALInferenceCurrentProposalName;
/** Adds \a weight copies of the proposal \a prop to the end of the
proposal cycle.
......@@ -141,7 +141,7 @@ LALInferenceDeleteProposalCycle(LALInferenceRunState *runState);
/** A reasonable default proposal. Uses adaptation if the --adapt
command-line flag active. */
void LALInferenceDefaultProposal(LALInferenceRunState *runState, LALInferenceVariables *proposedParams);
void LALInferencetempProposal(LALInferenceRunState *runState, LALInferenceVariables *proposedParams);
/* void LALInferencetempProposal(LALInferenceRunState *runState, LALInferenceVariables *proposedParams); */
/** Proposal for rapid sky localization. Used when --rapidSkyLoc
is specified. */
......@@ -181,8 +181,8 @@ void LALInferenceCovarianceEigenvectorJump(LALInferenceRunState *runState, LALIn
/** Jump around by 0.01 radians in angle on the sky */
void LALInferenceSkyLocWanderJump(LALInferenceRunState *runState, LALInferenceVariables *proposedParams);
void LALInferenceAdaptationProposal(LALInferenceRunState *runState, LALInferenceVariables *proposedParams);
void LALInferenceAdaptationSingleProposal(LALInferenceRunState *runState, LALInferenceVariables *proposedParams);
/* void LALInferenceAdaptationProposal(LALInferenceRunState *runState, LALInferenceVariables *proposedParams); */
/* void LALInferenceAdaptationSingleProposal(LALInferenceRunState *runState, LALInferenceVariables *proposedParams); */
/** Differential evolution, on all non-fixed, non-output parameters. */
void LALInferenceDifferentialEvolutionFull(LALInferenceRunState *state, LALInferenceVariables *proposedParams);
......
......@@ -47,9 +47,9 @@ xmlNodePtr XLALInferenceVariablesArray2VOTTable(const LALInferenceVariables *var
xmlNodePtr XLALInferenceVariables2VOTParamNode(const LALInferenceVariables *const vars);
INT4 XLALVOTDoc2LALInferenceVariablesByName(const xmlDocPtr xmlDocument, const char *name, LALInferenceVariables *bop);
/* INT4 XLALVOTDoc2LALInferenceVariablesByName(const xmlDocPtr xmlDocument, const char *name, LALInferenceVariables *bop); */
xmlNodePtr LALInferenceVariables2VOTParamNodes(LALInferenceVariables *vars);
/* xmlNodePtr LALInferenceVariables2VOTParamNodes(LALInferenceVariables *vars); */
xmlNodePtr LALInferenceVariableItem2VOTParamNode(LALInferenceVariableItem *varitem);
......
......@@ -18,6 +18,7 @@ lalinferenceinclude_HEADERS = \
LALInferenceLibVCSInfo.h \
LALInferenceInit.h \
LALInferenceVCSInfo.h \
lalinferenceswig_test.i \
$(XMLHDR)
lib_LTLIBRARIES = liblalinference.la
......@@ -54,7 +55,9 @@ lalinference-user-env.shell: Makefile $(srcdir)/generate_user_env.awk
@echo "prepend PATH $(bindir)" >>$@
@echo "prepend MANPATH $(mandir)" >>$@
@echo "prepend PKG_CONFIG_PATH $(libdir)/pkgconfig" >>$@
@echo "prepend PYTHONPATH $(pyexecdir)" >>$@
@echo "prepend LAL_DATA_PATH $(pkgdatadir)" >>$@
@printf "$(SWIG_USER_ENV)" >>$@
lalinference-user-env.csh lalinference-user-env.sh: lalinference-user-env.shell $(srcdir)/generate_user_env.awk
$(AM_V_GEN)$(AWK) -f $(srcdir)/generate_user_env.awk -v SED=$(SED) -v package=$(PACKAGE_NAME) -v output=$@ $< || { rm -f $@; exit 1; }
......@@ -75,3 +78,6 @@ gen-LALInferenceVCSInfo.h :
endif
@LAL_HEADER_LINK@
swig_headers = $(lalinferenceinclude_HEADERS)
include $(top_srcdir)/swig/swiglal_header.am
// Tests of SWIG interface code
// Author: Karl Wette, 2011, 2012
// Include LAL test code.
#include <lal/lalswig_test.i>
// Test object parent tracking between modules
typedef struct taglalinferenceswig_test_parent_map {
lalswig_test_struct s;
} lalinferenceswig_test_parent_map_struct;
lalinferenceswig_test_parent_map_struct lalinferenceswig_test_parent_map;
../../lal/swig/.gitignore
\ No newline at end of file
../../lal/swig/Makefile.am
\ No newline at end of file
../../lal/swig/generate_swiglal_iface.py
\ No newline at end of file
# this Makefile.am should NOT be modified; all SWIG configuration should
# be performed in lalsuite_swig.m4, swiglal_common.am, or swiglal_octave.am
CPPFLAGS = $(SWIG_CPPFLAGS)
CFLAGS = $(SWIG_CFLAGS)
CXXFLAGS = $(SWIG_CXXFLAGS)
LDFLAGS = $(SWIG_LDFLAGS)
LIBS = $(SWIG_LIBS)
TEST_EXTENSIONS = .m
include $(top_srcdir)/swig/octave/swiglal_octave.am
if SWIG_BUILD_OCTAVE
octexec_LTLIBRARIES = lalinference.la
lalinference_la_SOURCES = $(swig_lt_sources)
nodist_lalinference_la_SOURCES = $(swig_lt_nodist_sources)
lalinference_la_CPPFLAGS = $(swig_lt_cppflags)
lalinference_la_CFLAGS = $(swig_lt_cflags)
lalinference_la_CXXFLAGS = $(swig_lt_cxxflags)
lalinference_la_LDFLAGS = $(swig_lt_ldflags)
lalinference_la_LIBADD = $(swig_lt_libadd)
lalinference_la_LIBTOOLFLAGS = $(swig_lt_libtoolflags)
endif # SWIG_BUILD_OCTAVE
## Check SWIG Octave module wrapping lalinference
## Author: Karl Wette, 2011, 2012
## check module load
lalinference;
assert(exist("lalinference", "var"));
assert(exist("lalinferencecvar", "var"));
lal;
assert(exist("lal", "var"));
assert(exist("lalcvar", "var"));
lalcvar.lalDebugLevel = 1;
disp("passed module load");
# check object parent tracking
a = lalinference.new_lalinferenceswig_test_parent_map_struct();
for i = 1:7
b = a.s;
c = lalinferencecvar.lalinferenceswig_test_parent_map.s;
lalinferencecvar.lalinferenceswig_test_parent_map.s = lalcvar.lalswig_test_struct_const;
endfor
clear a b c;
CheckMemoryLeaks();
disp("passed object parent tracking");
## passed all tests!
disp("PASSED all tests");
../../../lal/swig/octave/swiglal_octave.am
\ No newline at end of file
# this Makefile.am should NOT be modified; all SWIG configuration should
# be performed in lalsuite_swig.m4, swiglal_common.am, or swiglal_python.am
CPPFLAGS = $(SWIG_CPPFLAGS)
CFLAGS = $(SWIG_CFLAGS)
CXXFLAGS = $(SWIG_CXXFLAGS)
LDFLAGS = $(SWIG_LDFLAGS)
LIBS = $(SWIG_LIBS)
TEST_EXTENSIONS = .py
include $(top_srcdir)/swig/python/swiglal_python.am
if SWIG_BUILD_PYTHON
pkgpyexec_LTLIBRARIES = _lalinference.la
_lalinference_la_SOURCES = $(swig_lt_sources)
nodist__lalinference_la_SOURCES = $(swig_lt_nodist_sources)
_lalinference_la_CPPFLAGS = $(swig_lt_cppflags)
_lalinference_la_CFLAGS = $(swig_lt_cflags)
_lalinference_la_CXXFLAGS = $(swig_lt_cxxflags)
_lalinference_la_LDFLAGS = $(swig_lt_ldflags)
_lalinference_la_LIBADD = $(swig_lt_libadd)
_lalinference_la_LIBTOOLFLAGS = $(swig_lt_libtoolflags)
endif # SWIG_BUILD_PYTHON
# Check SWIG Python module wrapping lalinference
# Author: Karl Wette, 2011, 2012
# check module load
import lal
import lalinference
from lalinference import cvar as lalinferencecvar
from lal import cvar as lalcvar
lalcvar.lalDebugLevel = 1
print("passed module load")
# check object parent tracking
a = lalinference.lalinferenceswig_test_parent_map_struct()
for i in range(0, 7):
b = a.s
c = lalinferencecvar.lalinferenceswig_test_parent_map.s
lalinferencecvar.lalinferenceswig_test_parent_map.s = lalcvar.lalswig_test_struct_const
del a, b, c
lal.CheckMemoryLeaks()
print("passed object parent tracking")
# passed all tests!
print("PASSED all tests")
../../../lal/swig/python/swiglal_python.am
\ No newline at end of file
../../lal/swig/swiglal_common.am
\ No newline at end of file
../../lal/swig/swiglal_header.am
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment