Space Vatican

Ramblings of a curious coder

Ruby Bindings for Liblinear

There are already some ruby bindings but I’ve written my own.

I mostly did this for fun, but I think swig sometimes gives you slightly unnatural feeling interfaces, because you’re focussing too much on mapping C++ classes to your ruby classes. For example some liblinear methods take a struct param argument. liblinear-ruby-swig mirrors this by proving an LParameter class that maps onto this:

1
2
  param = LParameter.new(:C => 1, :eps => 0.01)
  model = LModel.new(problem, param)

but I’d rather write:

1
  model = RubyLinear::Model.new problem, :c => 1, :eps => 0.01

I imagine that SWIG must incur some sort of overhead but I would have thought that was pretty negligible for something like liblinear where most of the heavy lifting happens in the library being wrapped.