Hi, we (Tiziano Zito and I) have recently done a little profiling to improve speed. I have attached the patch for it. (this time the right one i hope)
V-
>From 5d3d1088503f837352a546ba6af28ebb77a287c6 Mon Sep 17 00:00:00 2001 From: Valentin Haenel <[email protected]> Date: Wed, 22 Apr 2009 17:39:58 +0200 Subject: [PATCH] cleaning up some for loops --- mvpa/clfs/libsvmc/_svm.py | 17 +++-------------- 1 files changed, 3 insertions(+), 14 deletions(-) diff --git a/mvpa/clfs/libsvmc/_svm.py b/mvpa/clfs/libsvmc/_svm.py index c8f3c69..6877715 100644 --- a/mvpa/clfs/libsvmc/_svm.py +++ b/mvpa/clfs/libsvmc/_svm.py @@ -180,28 +180,17 @@ def convert2SVMNode(x): """convert a sequence or mapping to an SVMNode array""" import operator - # Find non zero elements - iter_range = [] if type(x) == dict: - for k, v in x.iteritems(): -# all zeros kept due to the precomputed kernel; no good solution yet -# if v != 0: - iter_range.append( k ) + iter_range = list(x).sort() elif operator.isSequenceType(x): - for j in range(len(x)): -# if x[j] != 0: - iter_range.append( j ) + iter_range = range(len(x)) else: raise TypeError, "data must be a mapping or a sequence" - iter_range.sort() data = svmc.svm_node_array(len(iter_range)+1) svmc.svm_node_array_set(data, len(iter_range), -1, 0) - j = 0 - for k in iter_range: - svmc.svm_node_array_set(data, j, k, x[k]) - j = j + 1 + [svmc.svm_node_array_set(data, j, k, x[k]) for j, k in enumerate(iter_range)] return data -- 1.5.6.5
_______________________________________________ Pkg-ExpPsy-PyMVPA mailing list [email protected] http://lists.alioth.debian.org/mailman/listinfo/pkg-exppsy-pymvpa

