mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-03 21:44:30 +08:00
add support for integer arithmatic ops on SparseIntVects. operator+ et al. do not yet work from python
This commit is contained in:
@@ -260,6 +260,62 @@ namespace RDKit{
|
||||
SparseIntVect<IndexType> res(*this);
|
||||
return res-=other;
|
||||
}
|
||||
SparseIntVect<IndexType> &
|
||||
operator*= (int v) {
|
||||
typename StorageType::iterator iter=d_data.begin();
|
||||
while(iter!=d_data.end()){
|
||||
iter->second *= v;
|
||||
++iter;
|
||||
}
|
||||
return *this;
|
||||
};
|
||||
SparseIntVect<IndexType> &
|
||||
operator* (int v) {
|
||||
SparseIntVect<IndexType> res(*this);
|
||||
return res*=v;
|
||||
};
|
||||
SparseIntVect<IndexType> &
|
||||
operator/= (int v) {
|
||||
typename StorageType::iterator iter=d_data.begin();
|
||||
while(iter!=d_data.end()){
|
||||
iter->second /= v;
|
||||
++iter;
|
||||
}
|
||||
return *this;
|
||||
};
|
||||
SparseIntVect<IndexType> &
|
||||
operator/ (int v) {
|
||||
SparseIntVect<IndexType> res(*this);
|
||||
return res/=v;
|
||||
};
|
||||
SparseIntVect<IndexType> &
|
||||
operator+= (int v) {
|
||||
typename StorageType::iterator iter=d_data.begin();
|
||||
while(iter!=d_data.end()){
|
||||
iter->second += v;
|
||||
++iter;
|
||||
}
|
||||
return *this;
|
||||
};
|
||||
SparseIntVect<IndexType> &
|
||||
operator+ (int v) {
|
||||
SparseIntVect<IndexType> res(*this);
|
||||
return res+=v;
|
||||
};
|
||||
SparseIntVect<IndexType> &
|
||||
operator-= (int v) {
|
||||
typename StorageType::iterator iter=d_data.begin();
|
||||
while(iter!=d_data.end()){
|
||||
iter->second -= v;
|
||||
++iter;
|
||||
}
|
||||
return *this;
|
||||
};
|
||||
SparseIntVect<IndexType> &
|
||||
operator- (int v) {
|
||||
SparseIntVect<IndexType> res(*this);
|
||||
return res-=v;
|
||||
};
|
||||
|
||||
bool operator==(const SparseIntVect<IndexType> &v2) const{
|
||||
if(d_length!=v2.d_length){
|
||||
|
||||
@@ -131,6 +131,14 @@ struct sparseIntVec_wrapper {
|
||||
.def(python::self += python::self)
|
||||
.def(python::self == python::self)
|
||||
.def(python::self != python::self)
|
||||
//.def(python::self - int())
|
||||
.def(python::self -= int())
|
||||
//.def(python::self + int())
|
||||
.def(python::self += int())
|
||||
//.def(python::self / int())
|
||||
.def(python::self /= int())
|
||||
//.def(python::self * int())
|
||||
.def(python::self *= int())
|
||||
.def("GetTotalVal", &SparseIntVect<IndexType>::getTotalVal,
|
||||
(python::args("useAbs")=false),
|
||||
"Get the sum of the values in the vector, basically L1 norm")
|
||||
|
||||
Reference in New Issue
Block a user