1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653
|
Description: Upstream changes to support big-endian architectures
This patch consists of upstream revisions 2071, 2079, 2080 and 2140.
Author: Greg Landrum
Origin: upstream
Bug-Debian: http://bugs.debian.org/670054
Last-Update: 2012-07-28
--- rdkit-201203.orig/CMakeLists.txt
+++ rdkit-201203/CMakeLists.txt
@@ -26,6 +26,9 @@ option(RDK_INSTALL_STATIC_LIBS "install
option(RDK_BUILD_SLN_SUPPORT "include support for the SLN format" ON )
option(RDK_TEST_MULTITHREADED "run some tests of multithreading" OFF )
+include(TestBigEndian)
+TEST_BIG_ENDIAN(RDK_BIG_ENDIAN)
+
# At build time put runtime binaries in the bin subdirectory
set(RDK_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
set(RDK_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib")
--- rdkit-201203.orig/Code/CMakeLists.txt
+++ rdkit-201203/Code/CMakeLists.txt
@@ -15,7 +15,11 @@ add_subdirectory(GraphMol)
add_subdirectory(Query)
add_subdirectory(DataManip)
-add_subdirectory(SimDivPickers)
+if(RDK_BIG_ENDIAN)
+ message("Skipping build of SimDivPickers on big endian system")
+else(RDK_BIG_ENDIAN)
+ add_subdirectory(SimDivPickers)
+endif(RDK_BIG_ENDIAN)
add_subdirectory(ML)
add_subdirectory(ChemicalFeatures)
--- rdkit-201203.orig/Code/DataStructs/BitVect.cpp
+++ rdkit-201203/Code/DataStructs/BitVect.cpp
@@ -40,7 +40,7 @@ void BitVect::initFromText(const char *d
// earlier versions of the code did not have the version number encoded, so
// we'll use that to distinguish version 0
- ss.read((char *)&size,sizeof(size));
+ RDKit::streamRead(ss,size);
if(size<0){
version = -1*size;
if (version == 16) {
@@ -52,12 +52,12 @@ void BitVect::initFromText(const char *d
else {
throw ValueErrorException("bad version in BitVect pickle");
}
-
- ss.read((char *)&size,sizeof(size));
+ RDKit::streamRead(ss,size);
} else if( !allowOldFormat ) {
throw ValueErrorException("invalid BitVect pickle");
}
- ss.read((char *)&nOn,sizeof(nOn));
+
+ RDKit::streamRead(ss,nOn);
_initForSize(static_cast<int>(size));
// if the either have older version or or version 16 with ints for on bits
@@ -65,13 +65,13 @@ void BitVect::initFromText(const char *d
( (format == 1) && (size >= std::numeric_limits<unsigned short>::max()) ) ) {
boost::uint32_t tmp;
for(unsigned int i=0; i<nOn; i++){
- ss.read((char *)&tmp,sizeof(tmp));
+ RDKit::streamRead(ss,tmp);
setBit(tmp);
}
} else if (format == 1) { // version 16 and on bits stored as short ints
boost::uint16_t tmp;
for(unsigned int i=0; i<nOn; i++){
- ss.read((char *)&tmp,sizeof(tmp));
+ RDKit::streamRead(ss,tmp);
setBit(tmp);
}
} else if (format == 2) { // run length encoded format
--- rdkit-201203.orig/Code/DataStructs/BitOps.cpp
+++ rdkit-201203/Code/DataStructs/BitOps.cpp
@@ -21,18 +21,20 @@
#include <boost/lexical_cast.hpp>
+using namespace RDKit;
+
int getBitId(const char *&text,int format,int size,int curr){
PRECONDITION(text,"no text");
int res=-1;
if( (format==0) ||
( (format == 1) && (size >= std::numeric_limits<unsigned short>::max()) ) ) {
int tmp;
- tmp = *(int *)text;
+ tmp = EndianSwapBytes<LITTLE_ENDIAN_ORDER,HOST_ENDIAN_ORDER>(*(int *)text);
text += sizeof(tmp);
res=tmp;
} else if (format == 1) { // version 16 and on bits sotred as short ints
unsigned short tmp;
- tmp = *(unsigned short *)text;
+ tmp = EndianSwapBytes<LITTLE_ENDIAN_ORDER,HOST_ENDIAN_ORDER>(*(unsigned short *)text);
text += sizeof(tmp);
res=tmp;
} else if (format == 2) { // run length encoded format
@@ -54,7 +56,7 @@ bool AllProbeBitsMatch(const char *probe
int refFormat=0;
int version=0;
- int probeSize = *(int *)probe;
+ int probeSize = EndianSwapBytes<LITTLE_ENDIAN_ORDER,HOST_ENDIAN_ORDER>(*(int *)probe);
probe+=sizeof(probeSize);
if(probeSize<0){
version = -1*probeSize;
@@ -67,11 +69,11 @@ bool AllProbeBitsMatch(const char *probe
else {
throw("Unknown version type for the encode bit vect");
}
- probeSize = *(int *)probe;
+ probeSize = EndianSwapBytes<LITTLE_ENDIAN_ORDER,HOST_ENDIAN_ORDER>(*(int *)probe);
probe+=sizeof(probeSize);
}
- int refSize = *(int *)ref;
+ int refSize = EndianSwapBytes<LITTLE_ENDIAN_ORDER,HOST_ENDIAN_ORDER>(*(int *)ref);
ref+=sizeof(refSize);
if(refSize<0){
version = -1*refSize;
@@ -84,14 +86,14 @@ bool AllProbeBitsMatch(const char *probe
else {
throw("Unknown version type for the encode bit vect");
}
- refSize = *(int *)ref;
+ refSize = EndianSwapBytes<LITTLE_ENDIAN_ORDER,HOST_ENDIAN_ORDER>(*(int *)ref);
ref+=sizeof(refSize);
}
- int nProbeOn = *(int *)probe;
+ int nProbeOn = EndianSwapBytes<LITTLE_ENDIAN_ORDER,HOST_ENDIAN_ORDER>(*(int *)probe);
probe+=sizeof(nProbeOn);
- int nRefOn = *(int *)ref;
+ int nRefOn = EndianSwapBytes<LITTLE_ENDIAN_ORDER,HOST_ENDIAN_ORDER>(*(int *)ref);
ref+=sizeof(nRefOn);
int currProbeBit=0;
@@ -121,7 +123,7 @@ bool AllProbeBitsMatch(const T1 &probe,c
const char *text=pkl.c_str();
int format=0;
int nOn=0,size,version=0;
- size = *(int *)text;
+ size = EndianSwapBytes<LITTLE_ENDIAN_ORDER,HOST_ENDIAN_ORDER>(*(int *)text);
text+=sizeof(size);
if(size<0){
version = -1*size;
@@ -134,10 +136,10 @@ bool AllProbeBitsMatch(const T1 &probe,c
else {
throw("Unknown version type for the encode bit vect");
}
- size = *(int *)text;
+ size = EndianSwapBytes<LITTLE_ENDIAN_ORDER,HOST_ENDIAN_ORDER>(*(int *)text);
text+=sizeof(size);
}
- nOn = *(int *)text;
+ nOn = EndianSwapBytes<LITTLE_ENDIAN_ORDER,HOST_ENDIAN_ORDER>(*(int *)text);
text+=sizeof(nOn);
int currBit=0;
--- rdkit-201203.orig/Code/DataStructs/DiscreteValueVect.cpp
+++ rdkit-201203/Code/DataStructs/DiscreteValueVect.cpp
@@ -1,6 +1,6 @@
// $Id: DiscreteValueVect.cpp 1528 2010-09-26 17:04:37Z glandrum $
//
-// Copyright (C) 2004-2008 Greg Landrum and Rational Discovery LLC
+// Copyright (C) 2004-2012 Greg Landrum and Rational Discovery LLC
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
@@ -143,8 +143,15 @@ namespace RDKit {
streamWrite(ss,tInt);
tInt=d_numInts;
streamWrite(ss,tInt);
+
+#if defined(BOOST_BIG_ENDIAN)
+ boost::uint32_t *td = new boost::uint32_t[d_numInts];
+ for(unsigned int i=0;i<d_numInts;++i) td[i]=EndianSwapBytes<HOST_ENDIAN_ORDER,LITTLE_ENDIAN_ORDER>(d_data.get()[i]);
+ ss.write((const char *)td,d_numInts*sizeof(tInt));
+ delete [] td;
+#else
ss.write((const char *)d_data.get(),d_numInts*sizeof(tInt));
-
+#endif
std::string res(ss.str());
return res;
};
@@ -175,7 +182,15 @@ namespace RDKit {
d_numInts=tInt;
boost::uint32_t *data = new boost::uint32_t[d_numInts];
ss.read((char *)data,d_numInts*sizeof(boost::uint32_t));
+
+#if defined(BOOST_BIG_ENDIAN)
+ boost::uint32_t *td = new boost::uint32_t[d_numInts];
+ for(unsigned int i=0;i<d_numInts;++i) td[i]=EndianSwapBytes<LITTLE_ENDIAN_ORDER,HOST_ENDIAN_ORDER>(data[i]);
+ d_data.reset(td);
+ delete [] data;
+#else
d_data.reset(data);
+#endif
};
--- rdkit-201203.orig/Code/DataStructs/testDatastructs.cpp
+++ rdkit-201203/Code/DataStructs/testDatastructs.cpp
@@ -125,9 +125,13 @@ template<typename T> void Test(T arg){
delete t5;
std::string pkl=t1.toString();
+ BOOST_LOG(rdInfoLog) << " a" << std::endl;
const char *pkl64=Base64Encode(pkl.c_str(),pkl.size());
+ BOOST_LOG(rdInfoLog) << " b" << std::endl;
T t6(t1.getNumBits());
+ BOOST_LOG(rdInfoLog) << " c" << std::endl;
t6.initFromText(pkl64,strlen(pkl64),true);
+ BOOST_LOG(rdInfoLog) << " d" << std::endl;
delete [] pkl64;
TEST_ASSERT(t6==t1);
}
@@ -149,10 +153,14 @@ template<typename T> void TaniTest(T &ar
int idx=0;
for(int i=0;i<4;i++){
T v1(256);
+ BOOST_LOG(rdInfoLog) << " a "<<i << std::endl;
FromDaylightString(v1,fps[i]);
+ BOOST_LOG(rdInfoLog) << " b"<<i << std::endl;
for(int j=i;j<4;j++){
T v2(256);
+ BOOST_LOG(rdInfoLog) << " c " << j << std::endl;
FromDaylightString(v2,fps[j]);
+ BOOST_LOG(rdInfoLog) << " d " << j << std::endl;
double tani=TanimotoSimilarity(v1,v2);
TEST_ASSERT(feq(tani,dists[idx]));
tani = TverskySimilarity(v1,v2,1.,1.);
@@ -1174,15 +1182,9 @@ int main(){
ss.write((const char *)&v1,sizeof(v1));
ss.write((const char *)&v2,sizeof(v2));
-#if 0
- ss.close();
- fstream ss2("blah.bin",ios_base::binary|ios_base::in);
- ss2.read((char *)&v3,sizeof(v3));
- ss2.read((char *)&v4,sizeof(v4));
-#endif
ss.seekp(0,ios_base::beg);
- ss.read((char *)&v3,sizeof(v3));
- ss.read((char *)&v4,sizeof(v4));
+ RDKit::streamRead(ss,v3);
+ RDKit::streamRead(ss,v4);
TXTMSG("v3",v3);
TXTMSG("v4",v4);
@@ -1190,12 +1192,16 @@ int main(){
BOOST_LOG(rdInfoLog) << " SPARSE -----------------------------------" << std::endl;
SparseBitVect sparseFoo(10);
Test(sparseFoo);
+ BOOST_LOG(rdInfoLog) << " 1" << std::endl;
TaniTest(sparseFoo);
+ BOOST_LOG(rdInfoLog) << " 2" << std::endl;
ProbeTest(sparseFoo);
BOOST_LOG(rdInfoLog) << " Explicit ----------------------------------" << std::endl;
ExplicitBitVect explicitFoo(10);
Test(explicitFoo);
+ BOOST_LOG(rdInfoLog) << " 1" << std::endl;
TaniTest(explicitFoo);
+ BOOST_LOG(rdInfoLog) << " 2" << std::endl;
BOOST_LOG(rdInfoLog) << " Done" << std::endl;
BOOST_LOG(rdInfoLog) << " Test DiscreteValue Vectors 1 ----------------------------" << endl;
--- rdkit-201203.orig/Code/DataStructs/SparseBitVect.cpp
+++ rdkit-201203/Code/DataStructs/SparseBitVect.cpp
@@ -317,10 +317,15 @@ std::string SparseBitVect::toString() co
boost::int32_t tInt = ci_BITVECT_VERSION*-1;
RDKit::streamWrite(ss,tInt);
+std::cerr<<"version: "<<tInt<<std::endl;
tInt=d_size;
RDKit::streamWrite(ss,tInt);
+std::cerr<<"size: "<<tInt<<std::endl;
+
tInt=getNumOnBits();
RDKit::streamWrite(ss,tInt);
+std::cerr<<"nOn: "<<tInt<<std::endl;
+
int prev = -1;
unsigned int zeroes;
--- rdkit-201203.orig/Code/RDGeneral/StreamOps.h
+++ rdkit-201203/Code/RDGeneral/StreamOps.h
@@ -16,10 +16,72 @@
#include <sstream>
#include <iostream>
#include <boost/cstdint.hpp>
-
+#include <boost/detail/endian.hpp>
namespace RDKit{
-
+ // this code block for handling endian problems is from :
+ // http://stackoverflow.com/questions/105252/how-do-i-convert-between-big-endian-and-little-endian-values-in-c
+ enum EEndian
+ {
+ LITTLE_ENDIAN_ORDER,
+ BIG_ENDIAN_ORDER,
+#if defined(BOOST_LITTLE_ENDIAN)
+ HOST_ENDIAN_ORDER = LITTLE_ENDIAN_ORDER
+#elif defined(BOOST_BIG_ENDIAN)
+ HOST_ENDIAN_ORDER = BIG_ENDIAN_ORDER
+#else
+#error "Failed to determine the system endian value"
+#endif
+ };
+
+ // this function swap the bytes of values given it's size as a template
+ // parameter (could sizeof be used?).
+ template <class T, unsigned int size>
+ inline T SwapBytes(T value)
+ {
+ union
+ {
+ T value;
+ char bytes[size];
+ } in, out;
+
+ in.value = value;
+
+ for (unsigned int i = 0; i < size / 2; ++i)
+ {
+ out.bytes[i] = in.bytes[size - 1 - i];
+ out.bytes[size - 1 - i] = in.bytes[i];
+ }
+
+ return out.value;
+ }
+
+ // Here is the function you will use. Again there is two compile-time assertion
+ // that use the boost librarie. You could probably comment them out, but if you
+ // do be cautious not to use this function for anything else than integers
+ // types. This function need to be calles like this :
+ //
+ // int x = someValue;
+ // int i = EndianSwapBytes<HOST_ENDIAN_ORDER, BIG_ENDIAN_ORDER>(x);
+ //
+ template<EEndian from, EEndian to, class T>
+ inline T EndianSwapBytes(T value)
+ {
+ // A : La donnée à swapper à une taille de 2, 4 ou 8 octets
+ BOOST_STATIC_ASSERT(sizeof(T)==1 || sizeof(T) == 2 || sizeof(T) == 4 || sizeof(T) == 8);
+ if(sizeof(T)==1) return value;
+
+ // A : La donnée à swapper est d'un type arithmetic
+ //BOOST_STATIC_ASSERT(boost::is_arithmetic<T>::value);
+
+ // Si from et to sont du même type on ne swap pas.
+ if (from == to)
+ return value;
+
+ return SwapBytes<T, sizeof(T)>(value);
+ }
+ // --------------------------------------
+
//! Packs an integer and outputs it to a stream
inline void appendPackedIntToStream(std::stringstream &ss, boost::uint32_t num) {
int nbytes, bix;
@@ -27,7 +89,7 @@ namespace RDKit{
char tc;
CHECK_INVARIANT(num >= 0, "");
- res = num;
+ res=num;
while (1) {
if (res < (1<<7)) {
val = (res<<1);
@@ -53,9 +115,10 @@ namespace RDKit{
break;
}
else {
- CHECK_INVARIANT(0, "ERROR: Integer to big to pack\n");
+ CHECK_INVARIANT(0, "ERROR: Integer too big to pack\n");
}
}
+ //val = EndianSwapBytes<HOST_ENDIAN_ORDER,LITTLE_ENDIAN_ORDER>(val);
for (bix = 0; bix < nbytes; bix++) {
tc = (char) (val & 255);
@@ -100,6 +163,7 @@ namespace RDKit{
offset = (1<<7) + (1<<14) + (1<<21);
}
num = (val >> shift) + offset;
+ //num = EndianSwapBytes<LITTLE_ENDIAN_ORDER,HOST_ENDIAN_ORDER>(num);
return num;
}
@@ -147,18 +211,22 @@ namespace RDKit{
offset = (1<<7) + (1<<14) + (1<<21);
}
num = (val >> shift) + offset;
+ //num = EndianSwapBytes<LITTLE_ENDIAN_ORDER,HOST_ENDIAN_ORDER>(num);
return num;
}
//! does a binary write of an object to a stream
template <typename T>
void streamWrite(std::ostream &ss,const T &val){
- ss.write((const char *)&val,sizeof(T));
+ T tval=EndianSwapBytes<HOST_ENDIAN_ORDER,LITTLE_ENDIAN_ORDER>(val);
+ ss.write((const char *)&tval,sizeof(T));
}
//! does a binary read of an object from a stream
template <typename T>
void streamRead(std::istream &ss,T &loc){
- ss.read((char *)&loc,sizeof(T));
+ T tloc;
+ ss.read((char *)&tloc,sizeof(T));
+ loc = EndianSwapBytes<LITTLE_ENDIAN_ORDER,HOST_ENDIAN_ORDER>(tloc);
}
//! grabs the next line from an instream and returns it.
--- rdkit-201203.orig/Code/ML/CMakeLists.txt
+++ rdkit-201203/Code/ML/CMakeLists.txt
@@ -1,4 +1,8 @@
-add_subdirectory(Cluster)
-add_subdirectory(FeatureSelect)
+if(RDK_BIG_ENDIAN)
+ message("Skipping build of clustering and cmim libraries on big endian system")
+else(RDK_BIG_ENDIAN)
+ add_subdirectory(Cluster)
+ add_subdirectory(FeatureSelect)
+endif(RDK_BIG_ENDIAN)
add_subdirectory(InfoTheory)
add_subdirectory(Data)
--- rdkit-201203.orig/Code/ML/FeatureSelect/Wrap/testCMIM.py
+++ rdkit-201203/Code/ML/FeatureSelect/Wrap/testCMIM.py
@@ -31,13 +31,13 @@ class TestCase(unittest.TestCase):
examples.append([0,bv,1])
r = FS.selectCMIM(examples,2)
- self.failUnless(r==(2,4))
+ self.failUnlessEqual(r,(2,4))
r = FS.selectCMIM(examples,1)
- self.failUnless(r==(2,))
+ self.failUnlessEqual(r,(2,))
r = FS.selectCMIM(examples,3)
- self.failUnless(r==(2,4,-1))
+ self.failUnlessEqual(r,(2,4,-1))
def test1FromList(self) :
examples = []
@@ -63,13 +63,13 @@ class TestCase(unittest.TestCase):
examples.append([0,bv,1])
r = FS.selectCMIM(examples,2)
- self.failUnless(r==(2,4))
+ self.failUnlessEqual(r,(2,4))
r = FS.selectCMIM(examples,1)
- self.failUnless(r==(2,))
+ self.failUnlessEqual(r,(2,))
r = FS.selectCMIM(examples,3)
- self.failUnless(r==(2,4,-1))
+ self.failUnlessEqual(r,(2,4,-1))
if __name__ == '__main__':
--- rdkit-201203.orig/rdkit/DataStructs/VectCollection.py
+++ rdkit-201203/rdkit/DataStructs/VectCollection.py
@@ -230,12 +230,13 @@ class VectCollection(object):
# set up our support for pickling:
#
def __getstate__(self):
- pkl = struct.pack('I',len(self.__vects))
+ pkl = struct.pack('<I',len(self.__vects))
for k,v in self.__vects.iteritems():
- pkl += struct.pack('I',k)
+ pkl += struct.pack('<I',k)
p = v.ToBinary()
l = len(p)
- pkl += struct.pack('I%ds'%(l),l,p)
+ pkl += struct.pack('<I',l)
+ pkl += struct.pack('%ds'%(l),p)
return pkl
def __setstate__(self,pkl):
@@ -245,12 +246,12 @@ class VectCollection(object):
self.__needReset=True
szI = struct.calcsize('I')
offset = 0
- nToRead = struct.unpack('I',pkl[offset:offset+szI])[0]
+ nToRead = struct.unpack('<I',pkl[offset:offset+szI])[0]
offset += szI
for i in range(nToRead):
- k = struct.unpack('I',pkl[offset:offset+szI])[0]
+ k = struct.unpack('<I',pkl[offset:offset+szI])[0]
offset += szI
- l = struct.unpack('I',pkl[offset:offset+szI])[0]
+ l = struct.unpack('<I',pkl[offset:offset+szI])[0]
offset += szI
sz = struct.calcsize('%ds'%l)
bv = DataStructs.ExplicitBitVect(struct.unpack('%ds'%l,pkl[offset:offset+sz])[0])
--- rdkit-201203.orig/rdkit/SimDivFilters/__init__.py
+++ rdkit-201203/rdkit/SimDivFilters/__init__.py
@@ -3,4 +3,8 @@
# All Rights Reserved
#
from rdkit import rdBase
-from rdSimDivPickers import *
+try:
+ import rdSimDivPickers
+ from rdSimDivPickers import *
+except ImportError:
+ rdSimDivPickers=None
--- rdkit-201203.orig/rdkit/ML/test_list.py
+++ rdkit-201203/rdkit/ML/test_list.py
@@ -5,7 +5,7 @@ tests=[
("python","UnitTestAnalyzeComposite.py",{}),
]
-for dir in ['Cluster','Composite','Data','DecTree','Descriptors','FeatureSelect','InfoTheory','KNN','ModelPackage','NaiveBayes','Neural','SLT']:
+for dir in ['Cluster','Composite','Data','DecTree','Descriptors','InfoTheory','KNN','ModelPackage','NaiveBayes','Neural','SLT']:
tests.append(('python','test_list.py',{'dir':dir}))
longTests=[
--- rdkit-201203.orig/rdkit/ML/InfoTheory/BitClusterer.py
+++ rdkit-201203/rdkit/ML/InfoTheory/BitClusterer.py
@@ -3,6 +3,8 @@
#
from rdkit.SimDivFilters import rdSimDivPickers as rdsimdiv
+if rdsimdiv is None:
+ raise ImportError,'rdSimDivPickers not built'
from rdkit import DataStructs
import numpy
--- rdkit-201203.orig/rdkit/ML/InfoTheory/testCorrMatGen.py
+++ rdkit-201203/rdkit/ML/InfoTheory/testCorrMatGen.py
@@ -2,7 +2,11 @@
from rdkit import RDConfig
import unittest
-from rdkit.ML.InfoTheory import rdInfoTheory, BitClusterer
+from rdkit.ML.InfoTheory import rdInfoTheory
+try:
+ from rdkit.ML.InfoTheory import BitClusterer
+except ImportError:
+ BitClusterer=None
from rdkit.ML.Data import DataUtils
from rdkit import DataStructs
import random
@@ -64,6 +68,8 @@ class TestCase(unittest.TestCase):
assert 2*navr/self.nbits == 158.3,2*navr/self.nbits
def test1Cluster(self) :
+ if BitClusterer is None:
+ return
cmg = rdInfoTheory.BitCorrMatGenerator()
cmg.SetBitList(self.blist)
for fp in self.fps:
--- rdkit-201203.orig/rdkit/ML/Cluster/UnitTestCluster.py
+++ rdkit-201203/rdkit/ML/Cluster/UnitTestCluster.py
@@ -14,7 +14,11 @@
from rdkit import RDConfig
import unittest
from rdkit.ML.Cluster import Standardize,ClusterUtils
-from rdkit.ML.Cluster import Clusters,Murtagh
+from rdkit.ML.Cluster import Clusters
+try:
+ from rdkit.ML.Cluster import Murtagh
+except ImportError:
+ Murtagh=None
import numpy
import cPickle
@@ -57,6 +61,7 @@ class TestCase(unittest.TestCase):
assert indices==[8,7,5,6],'bad index order'
def testMurtaghUPGMA(self):
+ if Murtagh is None: return
nPts = 5
sz = 5
dataP = numpy.random.random((nPts,sz))
--- rdkit-201203.orig/rdkit/ML/FeatureSelect/UnitTestCMIM.py
+++ rdkit-201203/rdkit/ML/FeatureSelect/UnitTestCMIM.py
@@ -1,4 +1,7 @@
-from rdkit.ML.FeatureSelect import CMIM
+try:
+ from rdkit.ML.FeatureSelect import CMIM
+except ImportError:
+ CMIM = None
from rdkit import DataStructs as DS
from rdkit import RDConfig
import unittest
@@ -8,6 +11,8 @@ class TestCase(unittest.TestCase):
pass
def test0FromList(self) :
+ if CMIM is None:
+ return
examples = []
bv = DS.ExplicitBitVect(5)
--- rdkit-201203.orig/rdkit/ML/DecTree/BuildSigTree.py
+++ rdkit-201203/rdkit/ML/DecTree/BuildSigTree.py
@@ -12,7 +12,10 @@
import numpy
from rdkit.ML.DecTree import SigTree
from rdkit.ML import InfoTheory
-from rdkit.ML.FeatureSelect import CMIM
+try:
+ from rdkit.ML.FeatureSelect import CMIM
+except ImportError:
+ CMIM=None
from rdkit.DataStructs.VectCollection import VectCollection
import copy
import random
@@ -136,7 +139,7 @@ def BuildSigTree(examples,nPossibleRes,e
nBits = fp.GetNumBits()
ranker = InfoTheory.InfoBitRanker(nBits,nPossibleRes,metric)
if biasList: ranker.SetBiasList(biasList)
- if useCMIM > 0 and not ensemble:
+ if CMIM is not None and useCMIM > 0 and not ensemble:
ensemble = CMIM.SelectFeatures(examples,useCMIM,bvCol=1)
if random:
if ensemble:
--- rdkit-201203.orig/rdkit/ML/NaiveBayes/CrossValidate.py
+++ rdkit-201203/rdkit/ML/NaiveBayes/CrossValidate.py
@@ -9,14 +9,17 @@ and evaluation of individual models
"""
from rdkit.ML.NaiveBayes.ClassificationModel import NaiveBayesClassifier
from rdkit.ML.Data import SplitData
-from rdkit.ML.FeatureSelect import CMIM
+try:
+ from rdkit.ML.FeatureSelect import CMIM
+except ImportError:
+ CMIM=None
def makeNBClassificationModel(trainExamples, attrs, nPossibleValues, nQuantBounds,
mEstimateVal=-1.0,
useSigs=False,
ensemble=None,useCMIM=0,
**kwargs) :
- if useCMIM > 0 and useSigs and not ensemble:
+ if CMIM is not None and useCMIM > 0 and useSigs and not ensemble:
ensemble = CMIM.SelectFeatures(trainExamples,useCMIM,bvCol=1)
if ensemble:
attrs = ensemble
|