Skip to content

Commit

Permalink
get ruby back to work
Browse files Browse the repository at this point in the history
- add configure option --ruby to be able to specify the ruby version to be used
- use rb_cObject instead of ruby_class to fix undefined symbol error
- beautify example
  • Loading branch information
Soeren Sonnenburg committed Nov 23, 2011
1 parent ecdb955 commit bd6dcde
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
11 changes: 8 additions & 3 deletions examples/undocumented/ruby_modular/check.sh
Expand Up @@ -2,28 +2,33 @@

rm -f error.log

if [ -z "${RUBY}" ]
then
RUBY=ruby
fi

if test -z "$1"
then
for e in $(ls -1 *.rb | grep -v ruby | grep -v shogun_helpers)
do
echo -n $e

if ruby $e >/dev/null 2>&1
if $RUBY $e >/dev/null 2>&1
then
echo " OK"
else
echo " ERROR"
echo "================================================================================" >>error.log
echo " error in $e ">>error.log
echo "================================================================================" >>error.log
ruby "$e" >>error.log 2>&1
$RUBY "$e" >>error.log 2>&1
echo "================================================================================" >>error.log
echo >>error.log
echo >>error.log
fi
done
else
ruby $1
$RUBY $1
fi

if test -f error.log
Expand Down
@@ -1,5 +1,6 @@
require 'modshogun'
require 'load'
require 'narray'
require 'pp'

parameter_list = [[1,7],[2,8]]
Expand All @@ -14,12 +15,8 @@ def classifier_custom_kernel_modular(c=1,dim=7)

kernel=Modshogun::CustomKernel.new
kernel.set_full_kernel_matrix_from_full(data)
# *** labels=Labels(lab)
labels=Modshogun::Labels.new(lab)
# labels.set_features(lab)
# *** svm=LibSVM(c, kernel, labels)
svm=Modshogun::LibSVM.new(c, kernel, labels)
# svm.set_features(c, kernel, labels)
svm.train()
predictions =svm.apply()
out=svm.apply().get_labels()
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.template
Expand Up @@ -428,7 +428,7 @@ run-testsuite-ruby_modular:
check-examples-ruby_modular:
cd $(CONFIGPATH)/../examples/undocumented/ruby_modular && \
( $(LIBRARY_PATH)=$(DESTDIR)$(LIBDIR) \
RUBYLIB="$$RUBYLIB:$(DESTDIR)$(RUBY_EXTENSIONS_INSTALL_DIR):." ./check.sh )
RUBY=$(RUBY) RUBYLIB="$$RUBYLIB:$(DESTDIR)$(RUBY_EXTENSIONS_INSTALL_DIR):." ./check.sh )

lib/versionstring.h: $(GITHEAD)
sh $(CONFIGPATH)/.version.sh > $@
Expand Down
34 changes: 20 additions & 14 deletions src/configure
Expand Up @@ -36,6 +36,7 @@ SWIGFLAGS="-w473 -w454 -w312 -w325 -fvirtual"
#-builtin -modern -modernargs
SWIG=swig
DOXYGEN=doxygen
RUBY=ruby
PYTHON=python
PYVER=
KERNELNAME=`uname`
Expand Down Expand Up @@ -681,9 +682,9 @@ test_ruby()
fi

echocheck "Ruby"
if ruby -v >/dev/null 2>&1
if $RUBY -v >/dev/null 2>&1
then
RUBYVER=`ruby -v 2>&1 | head -n 1 | cut -f 2 -d ' '`
RUBYVER=`$RUBY -v 2>&1 | head -n 1 | cut -f 2 -d ' '`
echores "${RUBYVER}"

cat >$TMPRUBY << EOF
Expand All @@ -695,11 +696,11 @@ puts "-I#{Config::expand(CONFIG['vendorlibdir'])}/#{Config::expand(CONFIG['arch'
end
EOF
echocheck "Ruby Developer Files"
if ruby $TMPRUBY >/dev/null 2>&1
if $RUBY $TMPRUBY >/dev/null 2>&1
then
echores "yes"
INCLUDES_RUBY=`ruby $TMPRUBY`
RUBYSO=`ruby -e 'require "mkmf"; puts Config::expand("$(RUBY_SO_NAME)")'`
INCLUDES_RUBY=`$RUBY $TMPRUBY`
RUBYSO=`$RUBY -e 'require "mkmf"; puts Config::expand("$(RUBY_SO_NAME)")'`
if ld -o "$TMPO" -l$RUBYSO >/dev/null 2>&1
then
LINKFLAGS_RUBY="-l$RUBYSO -fPIC -shared -ldl"
Expand All @@ -721,7 +722,7 @@ else
puts "#{Config::expand(CONFIG['rubylibdir'])}/#{Config::expand(CONFIG['arch'])}" if CONFIG['rubylibdir']
end
EOF
RUBY_LIBRARY_DIR=`ruby "$TMPRUBY" 2>/dev/null`
RUBY_LIBRARY_DIR=`$RUBY "$TMPRUBY" 2>/dev/null`

cat >$TMPRUBY << EOF
require('mkmf')
Expand All @@ -731,8 +732,8 @@ else
puts "#{Config::expand(CONFIG['vendorlibdir'])}/#{Config::expand(CONFIG['arch'])}" if CONFIG['vendorlibdir']
end
EOF
RUBY_VENDOR_LIBRARY_DIR=`ruby "$TMPRUBY" 2>/dev/null`
RUBY_EXTENSIONS_INSTALL_DIR=$_libdir/$_rubydir/`ruby -e 'require "mkmf"; puts Config::expand("$(ruby_version)") + "/" + Config::expand("$(arch)")'`
RUBY_VENDOR_LIBRARY_DIR=`$RUBY "$TMPRUBY" 2>/dev/null`
RUBY_EXTENSIONS_INSTALL_DIR=$_libdir/$_rubydir/`$RUBY -e 'require "mkmf"; puts Config::expand("$(ruby_version)") + "/" + Config::expand("$(arch)")'`
test_ruby_narray
else
if test "$_ruby_modular" = yes
Expand Down Expand Up @@ -1208,12 +1209,12 @@ Installation directories:
--destdir=DIR use this as the root dir to install shogun to [/]
--prefix=DIR use this prefix for installing shogun [/usr/local]
--bindir=DIR use this prefix for installing shogun binary
[PREFIX/bin]
[PREFIX/bin]
--datadir=DIR use this prefix for installing machine independent
data files (fonts, skins) [PREFIX/share/shogun]
data files (fonts, skins) [PREFIX/share/shogun]
--mandir=DIR use this prefix for installing manpages [PREFIX/man]
--confdir=DIR use this prefix for installing configuration files
[same as datadir]
[same as datadir]
--libdir=DIR use this prefix for object code libraries [PREFIX/lib]
--incdir=DIR use this prefix for include files [PREFIX/include]
--pydir=DIR use this prefix for python files [PREFIX/auto-detected]
Expand Down Expand Up @@ -1281,17 +1282,18 @@ Miscellaneous options:
--enable-path-debug enable viterbi path debugging [disabled]
--enable-profile compile profiling information into shogun [disable]
--enable-static build a statically linked binary (to the extend possible);
set further linking options with --enable-static="-lm -lglpk"
set further linking options with --enable-static="-lm -lglpk"
--python=python use this python executable [python]
--ruby=ruby use this ruby executable [ruby]
--cc=COMPILER use this C compiler to build shogun [autodetected]
--cxx=COMPILER use this C++ compiler to build shogun [autodetected]
--cflags=OPTIONS use these C compiler options
--cxxflags=OPTIONS use these C++ compiler options
--ldflags=OPTIONS use these additional linker options
--target=PLATFORM target platform (i386-linux, arm-linux, etc)
--install-path=PATH the path to a custom install program (useful if
your OS uses a GNU-incompatible install utility by
default and you want to point to the GNU version)
your OS uses a GNU-incompatible install utility by
default and you want to point to the GNU version)
--includes=DIR include DIR when searching for includes
--libs=DIR include DIR when searching for libraries on linking
EOF
Expand Down Expand Up @@ -1383,6 +1385,9 @@ EOF
--python=*)
PYTHON=`echo $ac_option | cut -d '=' -f 2`
;;
--ruby=*)
RUBY=`echo $ac_option | cut -d '=' -f 2`
;;
--cc=*)
CC=`echo $ac_option | cut -d '=' -f 2`
;;
Expand Down Expand Up @@ -4639,6 +4644,7 @@ MAKEDEPENDOPTS = ${MAKEDEPENDOPTS}
SWIG = ${SWIG}
SEDMI = ${SEDMI}
PYTHON = ${PYTHON}
RUBY = ${RUBY}
PYVER = ${PYVER}
DOXYGEN = ${DOXYGEN}
USE_DOXYGEN = ${USE_DOXYGEN}
Expand Down
3 changes: 1 addition & 2 deletions src/interfaces/modular/SGBase.i
Expand Up @@ -141,9 +141,8 @@ public void readExternal(java.io.ObjectInput in) throws java.io.IOException, jav
#endif

#ifdef SWIGRUBY
extern VALUE ruby_class;
rb_require("narray");
cNArray = rb_const_get(ruby_class, rb_intern("NArray"));
cNArray = rb_const_get(rb_cObject, rb_intern("NArray"));

char* error=NULL;

Expand Down

0 comments on commit bd6dcde

Please sign in to comment.