Skip to content

Commit

Permalink
RF: Uniformize extension handling.
Browse files Browse the repository at this point in the history
Extensions are now named after the lib they are building, e.g.

SMLR build smlrc.so and is therefore named 'smlrc' not 'smlr' and
is now located in 'mvpa/clfs/libsmlrc'.
  • Loading branch information
mih committed Oct 21, 2008
1 parent f236dc8 commit bf83b27
Show file tree
Hide file tree
Showing 20 changed files with 59 additions and 36 deletions.
10 changes: 5 additions & 5 deletions Makefile
Expand Up @@ -44,11 +44,11 @@ build-stamp: 3rd
python setup.py build_ext
python setup.py build_py
# to overcome the issue of not-installed svmc.so
for ext in svm smlr; do \
ln -sf ../../../build/lib.linux-$(ARCH)-$(PYVER)/mvpa/clfs/lib$$ext/$${ext}c.so \
mvpa/clfs/lib$$ext/; \
ln -sf ../../../build/lib.linux-$(ARCH)-$(PYVER)/mvpa/clfs/lib$$ext/$${ext}c.so \
mvpa/clfs/lib$$ext/$${ext}c.dylib; \
for ext in _svmc smlrc ridgetrain; do \
ln -sf ../../../build/lib.linux-$(ARCH)-$(PYVER)/mvpa/clfs/lib$${ext#_*}/$${ext}.so \
mvpa/clfs/lib$${ext#_*}/; \
ln -sf ../../../build/lib.linux-$(ARCH)-$(PYVER)/mvpa/clfs/lib$${ext#_*}/$${ext}.so \
mvpa/clfs/lib$${ext#_*}/$${ext}.dylib; \
done
touch $@

Expand Down
10 changes: 6 additions & 4 deletions Makefile.win
Expand Up @@ -29,10 +29,12 @@ installer: 3rd build


configure-inplace-use:
copy build\\lib.win32-$(PYTHON_VERSION)\\mvpa\\clfs\\libsmlr\\smlrc.pyd \
mvpa\\clfs\\libsmlr
copy build\\lib.win32-$(PYTHON_VERSION)\\mvpa\\clfs\\libsvm\\svmc.pyd \
mvpa\\clfs\\libsvm
copy build\\lib.win32-$(PYTHON_VERSION)\\mvpa\\clfs\\libsmlrc\\smlrc.pyd \
mvpa\\clfs\\libsmlrc
copy build\\lib.win32-$(PYTHON_VERSION)\\mvpa\\clfs\\libsvmc\\_svmc.pyd \
mvpa\\clfs\\libsvmc
copy build\\lib.win32-$(PYTHON_VERSION)\\mvpa\\clfs\\libridgetrain\\ridgetrain.pyd \
mvpa\\clfs\\libridgetrain

#
# Cleaning
Expand Down
2 changes: 1 addition & 1 deletion mvpa/base/externals.py
Expand Up @@ -80,7 +80,7 @@ def __check_weave():


# contains list of available (optional) external classifier extensions
_KNOWN = {'libsvm':'import mvpa.clfs.libsvm._svm as __; x=__.convert2SVMNode',
_KNOWN = {'libsvm':'import mvpa.clfs.libsvmc._svm as __; x=__.convert2SVMNode',
'nifti':'from nifti import NiftiImage as __',
'ctypes':'import ctypes as __',
'shogun':'import shogun as __',
Expand Down
21 changes: 21 additions & 0 deletions mvpa/clfs/libridgetrain/__init__.py
@@ -0,0 +1,21 @@
#emacs: -*- mode: python-mode; py-indent-offset: 4; indent-tabs-mode: nil -*-
#ex: set sts=4 ts=4 sw=4 et:
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
#
# See COPYING file distributed along with the PyMVPA package for the
# copyright and license terms.
#
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
"""Import helper for Fortran extension ridgetrain."""

__docformat__ = 'restructuredtext'


if __debug__:
from mvpa.base import debug
debug('INIT', 'mvpa.clfs.libridgetrain')

from mvpa.clfs.libridgetrain.ridgetrain import ridgetrain

if __debug__:
debug('INIT', 'mvpa.clfs.libridgetrain end')
File renamed without changes.
Expand Up @@ -10,14 +10,14 @@

if __debug__:
from mvpa.base import debug
debug('INIT', 'mvpa.clfs.libsmlr')
debug('INIT', 'mvpa.clfs.libsmlrc')

import numpy as N
import ctypes as C
import os
import sys

from mvpa.clfs.libsmlr.ctypes_helper import extend_args, c_darray
from mvpa.clfs.libsmlrc.ctypes_helper import extend_args, c_darray

# connect to library that's in this directory
if sys.platform == 'win32':
Expand Down Expand Up @@ -54,5 +54,5 @@ def stepwise_regression(*args):
return func(*arglist)

if __debug__:
debug('INIT', 'mvpa.clfs.libsmlr end')
debug('INIT', 'mvpa.clfs.libsmlrc end')

File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -12,9 +12,9 @@

if __debug__:
from mvpa.base import debug
debug('INIT', 'mvpa.clfs.libsvm')
debug('INIT', 'mvpa.clfs.libsvmc')

from mvpa.clfs.libsvm.svm import SVM
from mvpa.clfs.libsvmc.svm import SVM

if __debug__:
debug('INIT', 'mvpa.clfs.libsvm end')
debug('INIT', 'mvpa.clfs.libsvmc end')
4 changes: 2 additions & 2 deletions mvpa/clfs/libsvm/_svm.py → mvpa/clfs/libsvmc/_svm.py
Expand Up @@ -16,8 +16,8 @@

import numpy as N

from mvpa.clfs.libsvm import svmc
from mvpa.clfs.libsvm.svmc import C_SVC, NU_SVC, ONE_CLASS, EPSILON_SVR, \
from mvpa.clfs.libsvmc import _svmc as svmc
from mvpa.clfs.libsvmc._svmc import C_SVC, NU_SVC, ONE_CLASS, EPSILON_SVR, \
NU_SVR, LINEAR, POLY, RBF, SIGMOID, \
PRECOMPUTED

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions mvpa/clfs/libsvm/svm.py → mvpa/clfs/libsvmc/svm.py
Expand Up @@ -22,14 +22,14 @@
from mvpa.clfs._svmbase import _SVM
from mvpa.measures.base import Sensitivity

import _svm as svm
from mvpa.clfs.libsvmc import _svm as svm
from sens import *

if __debug__:
from mvpa.base import debug

# we better expose those since they are mentioned in docstrings
from svmc import \
from mvpa.clfs.libsvmc._svmc import \
C_SVC, NU_SVC, ONE_CLASS, EPSILON_SVR, \
NU_SVR, LINEAR, POLY, RBF, SIGMOID, \
PRECOMPUTED
Expand Down
1 change: 1 addition & 0 deletions mvpa/clfs/libsvm/svmc.i → mvpa/clfs/libsvmc/svmc.i
@@ -1,3 +1,4 @@
//-*-c++-*-
%module svmc
%{
#include "svm.h"
Expand Down
7 changes: 3 additions & 4 deletions mvpa/clfs/ridge.py
Expand Up @@ -15,8 +15,7 @@
from scipy.linalg import lstsq

from mvpa.clfs.base import Classifier

import ridgetrain
from mvpa.clfs.libridgetrain import ridgetrain

class RidgeReg(Classifier):
"""Ridge regression `Classifier`.
Expand Down Expand Up @@ -76,7 +75,7 @@ def _train(self, data):
"""Train the classifier using `data` (`Dataset`).
"""

if self.implementation == "direct":
if self.__implementation == "direct":
# create matrices to solve with additional penalty term
# determine the lambda matrix
if self.__lm is None:
Expand All @@ -102,7 +101,7 @@ def _train(self, data):
Lambda = self.__lm
# We can directly run the training routine
self.w = N.random.randn(data.nfeatures+1)
self.w = ridgetrain.ridgetrain(data.samples,\
self.w = ridgetrain(data.samples,\
data.labels, self.w, Lambda, self.__stopcrit)
else:
raise ValueError, "Unknown implementation '%s'" \
Expand Down
2 changes: 1 addition & 1 deletion mvpa/clfs/smlr.py
Expand Up @@ -23,7 +23,7 @@
_DEFAULT_IMPLEMENTATION = "Python"
if externals.exists('ctypes'):
# Uber-fast C-version of the stepwise regression
from mvpa.clfs.libsmlr import stepwise_regression as _cStepwiseRegression
from mvpa.clfs.libsmlrc import stepwise_regression as _cStepwiseRegression
_DEFAULT_IMPLEMENTATION = "C"
else:
_cStepwiseRegression = None
Expand Down
6 changes: 3 additions & 3 deletions mvpa/clfs/svm.py
Expand Up @@ -43,14 +43,14 @@

if externals.exists('libsvm'):
# By default for now we want simply to import all SVMs from libsvm
from mvpa.clfs import libsvm
_NuSVM = libsvm.SVM
from mvpa.clfs import libsvmc
_NuSVM = libsvmc.SVM
if default_backend == 'libsvm' or SVM is None:
if __debug__ and default_backend != 'libsvm' and SVM is None:
debug('SVM',
'Default SVM backend %s was not found, so using libsvm'
% default_backend)
SVM = libsvm.SVM
SVM = libsvmc.SVM
#from mvpa.clfs.libsvm.svm import *

if SVM is None:
Expand Down
2 changes: 1 addition & 1 deletion mvpa/clfs/warehouse.py
Expand Up @@ -165,7 +165,7 @@ def items(self):
clfs['smlr'][0].descr) ]

if externals.exists('libsvm'):
from mvpa.clfs import libsvm
from mvpa.clfs import libsvmc as libsvm
clfs._known_tags.union_update(libsvm.SVM._KNOWN_IMPLEMENTATIONS.keys())
clfs += [libsvm.SVM(descr="libsvm.LinSVM(C=def)", probability=1),
libsvm.SVM(
Expand Down
12 changes: 6 additions & 6 deletions setup.py
Expand Up @@ -25,8 +25,8 @@

# define the extension modules
libsvmc_ext = Extension(
'mvpa.clfs.libsvm.svmc',
sources = [ 'mvpa/clfs/libsvm/svmc.i' ],
'mvpa.clfs.libsvmc._svmc',
sources = [ 'mvpa/clfs/libsvmc/svmc.i' ],
include_dirs = [ '/usr/include/libsvm-2.0/libsvm', numpy_headers ],
libraries = [ 'svm' ],
language = 'c++',
Expand All @@ -36,8 +36,8 @@
'-I' + numpy_headers ] )

smlrc_ext = Extension(
'mvpa.clfs.libsmlr.smlrc',
sources = [ 'mvpa/clfs/libsmlr/smlr.c' ],
'mvpa.clfs.libsmlrc.smlrc',
sources = [ 'mvpa/clfs/libsmlrc/smlr.c' ],
libraries = ['m'],
# extra_compile_args = ['-O0'],
extra_link_args = extra_link_args,
Expand Down Expand Up @@ -79,8 +79,8 @@
'mvpa.mappers',
'mvpa.clfs',
'mvpa.clfs.sg',
'mvpa.clfs.libsvm',
'mvpa.clfs.libsmlr',
'mvpa.clfs.libsvmc',
'mvpa.clfs.libsmlrc',
'mvpa.algorithms',
'mvpa.measures',
'mvpa.featsel',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_svm.py
Expand Up @@ -160,7 +160,7 @@ def testSillyness(self):
self.failUnlessRaises(TypeError, SVM, C=1.0, nu=2.3)

if externals.exists('libsvm'):
self.failUnlessRaises(TypeError, libsvm.SVM, C=1.0, nu=2.3)
self.failUnlessRaises(TypeError, libsvmc.SVM, C=1.0, nu=2.3)
self.failUnlessRaises(TypeError, LinearNuSVMC, C=2.3)
self.failUnlessRaises(TypeError, LinearCSVMC, nu=2.3)

Expand Down

0 comments on commit bf83b27

Please sign in to comment.