/*!
* Returns a textual and human readable representation of \a this instance of
* DataArrayDouble. This text is shown when a DataArrayDouble is printed in Python.
- * \return std::string - text describing \a this DataArrayDouble.
+ * \return std::string - text describing \a this DataArrayDouble.
+ *
+ * \sa reprNotTooLong, reprZip
*/
std::string DataArrayDouble::repr() const
{
return ret.str();
}
+/*!
+ * This method is close to repr method except that when \a this has more than 1000 tuples, all tuples are not
+ * printed out to avoid to consume too much space in interpretor.
+ * \sa repr
+ */
+std::string DataArrayDouble::reprNotTooLong() const
+{
+ std::ostringstream ret;
+ reprNotTooLongStream(ret);
+ return ret.str();
+}
+
void DataArrayDouble::writeVTK(std::ostream& ofs, int indent, const std::string& nameInFile, DataArrayByte *byteArr) const
{
static const char SPACE[4]={' ',' ',' ',' '};
reprZipWithoutNameStream(stream);
}
+void DataArrayDouble::reprNotTooLongStream(std::ostream& stream) const
+{
+ stream << "Name of double array : \"" << _name << "\"\n";
+ reprNotTooLongWithoutNameStream(stream);
+}
+
void DataArrayDouble::reprWithoutNameStream(std::ostream& stream) const
{
DataArray::reprWithoutNameStream(stream);
_mem.reprZip(getNumberOfComponents(),stream);
}
+void DataArrayDouble::reprNotTooLongWithoutNameStream(std::ostream& stream) const
+{
+ DataArray::reprWithoutNameStream(stream);
+ stream.precision(17);
+ _mem.reprNotTooLong(getNumberOfComponents(),stream);
+}
+
void DataArrayDouble::reprCppStream(const std::string& varName, std::ostream& stream) const
{
int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents();
/*!
* Returns a textual and human readable representation of \a this instance of
* DataArrayInt. This text is shown when a DataArrayInt is printed in Python.
- * \return std::string - text describing \a this DataArrayInt.
+ * \return std::string - text describing \a this DataArrayInt.
+ *
+ * \sa reprNotTooLong, reprZip
*/
std::string DataArrayInt::repr() const
{
return ret.str();
}
+/*!
+ * This method is close to repr method except that when \a this has more than 1000 tuples, all tuples are not
+ * printed out to avoid to consume too much space in interpretor.
+ * \sa repr
+ */
+std::string DataArrayInt::reprNotTooLong() const
+{
+ std::ostringstream ret;
+ reprNotTooLongStream(ret);
+ return ret.str();
+}
+
void DataArrayInt::writeVTK(std::ostream& ofs, int indent, const std::string& type, const std::string& nameInFile, DataArrayByte *byteArr) const
{
static const char SPACE[4]={' ',' ',' ',' '};
reprZipWithoutNameStream(stream);
}
+void DataArrayInt::reprNotTooLongStream(std::ostream& stream) const
+{
+ stream << "Name of int array : \"" << _name << "\"\n";
+ reprNotTooLongWithoutNameStream(stream);
+}
+
void DataArrayInt::reprWithoutNameStream(std::ostream& stream) const
{
DataArray::reprWithoutNameStream(stream);
_mem.reprZip(getNumberOfComponents(),stream);
}
+void DataArrayInt::reprNotTooLongWithoutNameStream(std::ostream& stream) const
+{
+ DataArray::reprWithoutNameStream(stream);
+ stream.precision(17);
+ _mem.reprNotTooLong(getNumberOfComponents(),stream);
+}
+
void DataArrayInt::reprCppStream(const std::string& varName, std::ostream& stream) const
{
int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents();
void repr(int sl, std::ostream& stream) const;
bool reprHeader(int sl, std::ostream& stream) const;
void reprZip(int sl, std::ostream& stream) const;
+ void reprNotTooLong(int sl, std::ostream& stream) const;
void fillWithValue(const T& val);
T *fromNoInterlace(int nbOfComp) const;
T *toNoInterlace(int nbOfComp) const;
MEDCOUPLING_EXPORT bool isMonotonic(bool increasing, double eps) const;
MEDCOUPLING_EXPORT std::string repr() const;
MEDCOUPLING_EXPORT std::string reprZip() const;
+ MEDCOUPLING_EXPORT std::string reprNotTooLong() const;
MEDCOUPLING_EXPORT void writeVTK(std::ostream& ofs, int indent, const std::string& nameInFile, DataArrayByte *byteArr) const;
MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const;
MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprNotTooLongStream(std::ostream& stream) const;
MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const;
MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprNotTooLongWithoutNameStream(std::ostream& stream) const;
MEDCOUPLING_EXPORT void reprCppStream(const std::string& varName, std::ostream& stream) const;
MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const;
MEDCOUPLING_EXPORT void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const;
MEDCOUPLING_EXPORT void iota(int init=0);
MEDCOUPLING_EXPORT std::string repr() const;
MEDCOUPLING_EXPORT std::string reprZip() const;
+ MEDCOUPLING_EXPORT std::string reprNotTooLong() const;
MEDCOUPLING_EXPORT void writeVTK(std::ostream& ofs, int indent, const std::string& type, const std::string& nameInFile, DataArrayByte *byteArr) const;
MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const;
MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprNotTooLongStream(std::ostream& stream) const;
MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const;
MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprNotTooLongWithoutNameStream(std::ostream& stream) const;
MEDCOUPLING_EXPORT void reprCppStream(const std::string& varName, std::ostream& stream) const;
MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const;
MEDCOUPLING_EXPORT void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const;
stream << "No data !\n";
}
+ /*!
+ * \param [in] sl is typically the number of components
+ */
+ template<class T>
+ void MemArray<T>::reprNotTooLong(int sl, std::ostream& stream) const
+ {
+ if(reprHeader(sl,stream))
+ {
+ const T *data=getConstPointer();
+ if(_nb_of_elem!=0 && sl!=0)
+ {
+ std::size_t nbOfTuples=_nb_of_elem/std::abs(sl);
+ if(nbOfTuples<=1000)
+ {
+ for(std::size_t i=0;i<nbOfTuples;i++)
+ {
+ stream << "Tuple #" << i << " : ";
+ std::copy(data,data+sl,std::ostream_iterator<T>(stream," "));
+ stream << "\n";
+ data+=sl;
+ }
+ }
+ else
+ {// too much tuples -> print the 3 first tuples and 3 last.
+ stream << "Tuple #0 : ";
+ std::copy(data,data+sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
+ stream << "Tuple #1 : ";
+ std::copy(data+sl,data+2*sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
+ stream << "Tuple #2 : ";
+ std::copy(data+2*sl,data+3*sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
+ stream << "...\n";
+ stream << "Tuple #" << nbOfTuples-3 << " : ";
+ std::copy(data+(nbOfTuples-3)*sl,data+(nbOfTuples-2)*sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
+ stream << "Tuple #" << nbOfTuples-2 << " : ";
+ std::copy(data+(nbOfTuples-2)*sl,data+(nbOfTuples-1)*sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
+ stream << "Tuple #" << nbOfTuples-1 << " : ";
+ std::copy(data+(nbOfTuples-1)*sl,data+nbOfTuples*sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
+ }
+ }
+ else
+ stream << "Empty Data\n";
+ }
+ }
+
template<class T>
void MemArray<T>::fillWithValue(const T& val)
{
self.assertRaises(InterpKernelException,m.getLocationFromCellId,5)
self.assertRaises(InterpKernelException,m.getLocationFromCellId,-1)
pass
+
+ def testSwig2DataArrayPrintNotTooLong1(self):
+ """ Now that DataArrayDouble and DataArrayInt and pickelized they can appear in YACS ports. Avoid to have too heavy string representation of them."""
+ d=DataArrayDouble(2000) ; d.iota() ; d.rearrange(2)
+ st0=d.repr() ; st1=str(d) ; st2=d.reprNotTooLong()
+ self.assertEqual(st0,st1) # 1000 tuples ( >=0 and <= 1000) -> str(d)==d.repr()
+ self.assertEqual(st1,st2)
+ #
+ d=DataArrayDouble(2002) ; d.iota() ; d.rearrange(2)
+ st0=d.repr() ; st1=str(d) ; st2=d.reprNotTooLong()
+ self.assertNotEqual(st0,st1) # 1001 tuples ( > 1000) -> str(d)==d.reprNotTooLong()
+ self.assertEqual(st1,st2)
+ self.assertIn(len(st2),xrange(0,1000)) # no more than 1000 characters
+ ## Now for DataArrayInt
+ d=DataArrayInt(2000) ; d.iota() ; d.rearrange(2)
+ st0=d.repr() ; st1=str(d) ; st2=d.reprNotTooLong()
+ self.assertEqual(st0,st1) # 1000 tuples ( >=0 and <= 1000) -> str(d)==d.repr()
+ self.assertEqual(st1,st2)
+ #
+ d=DataArrayInt(2002) ; d.iota() ; d.rearrange(2)
+ st0=d.repr() ; st1=str(d) ; st2=d.reprNotTooLong()
+ self.assertNotEqual(st0,st1) # 1001 tuples ( > 1000) -> str(d)==d.reprNotTooLong()
+ self.assertEqual(st1,st2)
+ self.assertIn(len(st2),xrange(0,1000)) # no more than 1000 characters
+ pass
pass
if __name__ == '__main__':
bool isMonotonic(bool increasing, double eps) const throw(INTERP_KERNEL::Exception);
std::string repr() const throw(INTERP_KERNEL::Exception);
std::string reprZip() const throw(INTERP_KERNEL::Exception);
+ std::string reprNotTooLong() const throw(INTERP_KERNEL::Exception);
bool isEqual(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception);
bool isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception);
DataArrayInt *convertToIntArr() const throw(INTERP_KERNEL::Exception);
std::string __str__() const throw(INTERP_KERNEL::Exception)
{
- return self->repr();
+ return self->reprNotTooLong();
}
double __float__() const throw(INTERP_KERNEL::Exception)
void replaceOneValByInThis(int valToBeReplaced, int replacedBy) throw(INTERP_KERNEL::Exception);
std::string repr() const throw(INTERP_KERNEL::Exception);
std::string reprZip() const throw(INTERP_KERNEL::Exception);
+ std::string reprNotTooLong() const throw(INTERP_KERNEL::Exception);
DataArrayInt *invertArrayO2N2N2O(int newNbOfElem) const throw(INTERP_KERNEL::Exception);
DataArrayInt *invertArrayN2O2O2N(int oldNbOfElem) const throw(INTERP_KERNEL::Exception);
DataArrayInt *invertArrayO2N2N2OBis(int newNbOfElem) const throw(INTERP_KERNEL::Exception);
std::string __str__() const throw(INTERP_KERNEL::Exception)
{
- return self->repr();
+ return self->reprNotTooLong();
}
int __len__() const throw(INTERP_KERNEL::Exception)