string PySparseTensor::__getstate__() const { #if 1 stringstream s; tensor_.toStream(s); return s.str(); #else stringstream s; PyTensorIndex bounds = tensor_.getBounds(); size_t n = bounds.size(); s << n << " "; for(size_t i=0; i<n; ++i) s << bounds[i] << " "; s << "\n"; size_t nz = tensor_.getNNonZeros(); s << nz << "\n"; STBase::const_iterator i = tensor_.begin(); STBase::const_iterator end = tensor_.end(); for(; i!=end; ++i) { const PyTensorIndex &key = i->first; const nta::Real &value = i->second; for(size_t j=0; j<n; ++j) s << key[j] << " "; s << value << "\n"; } return s.str(); #endif }
PySparseTensor getComplementBounds(const PyTensorIndex &dims) const { PyTensorIndex process(tensor_.getBounds()); nta::UInt32 n = dims.size(); for(nta::UInt32 i=0; i<n; ++i) process[dims[i]] = 0; n = process.size(); PyTensorIndex remain(n - dims.size(), (const nta::UInt32 *) 0); nta::UInt32 cur = 0; for(nta::UInt32 i=0; i<n; ++i) { nta::UInt32 keep = process[i]; if(keep) remain[cur++] = keep; } return remain; }