[casacore] r21571 committed - Added test for std::vector<bool> and std::vector<ValueHolder>

0 views
Skip to first unread message

casa...@googlecode.com

unread,
Mar 2, 2015, 5:51:50 AM3/2/15
to casacor...@googlegroups.com
Revision: 21571
Author: gervandiepen
Date: Mon Mar 2 10:51:35 2015 UTC
Log: Added test for std::vector<bool> and std::vector<ValueHolder>
https://code.google.com/p/casacore/source/detail?r=21571

Modified:
/branches/nov14/python/Converters/test/tConvert.cc
/branches/nov14/python/Converters/test/tConvert.out
/branches/nov14/python/Converters/test/tConvert.py

=======================================
--- /branches/nov14/python/Converters/test/tConvert.cc Thu Dec 11 12:28:06
2014 UTC
+++ /branches/nov14/python/Converters/test/tConvert.cc Mon Mar 2 10:51:35
2015 UTC
@@ -31,24 +31,13 @@
#include <casacore/python/Converters/PycRecord.h>
#include <casacore/python/Converters/PycArray.h>
#include <casacore/casa/Arrays/ArrayIO.h>
+#include <casacore/casa/BasicSL/STLIO.h>

#include <boost/python.hpp>

using namespace boost::python;

namespace casacore { namespace python {
-
- template<typename T>
- std::ostream& operator<< (std::ostream& os, const std::vector<T>& vec)
- {
- os << '[';
- for (uInt i=0; i<vec.size(); ++i) {
- if (i > 0) os << ", ";
- os << "vecuInt " << vec[i];
- }
- os << ']';
- return os;
- }

struct TConvert
{
@@ -75,17 +64,23 @@
{cout << "Record "; in.print(cout); cout << endl; return in;}
ValueHolder testvh (const ValueHolder& in)
{cout << "VH " << in.dataType() << endl; return in;}
+ Vector<Bool> testvecbool (const Vector<Bool>& in)
+ {cout << "VecBool " << in << endl; return in;}
Vector<Int> testvecint (const Vector<int>& in)
{cout << "VecInt " << in << endl; return in;}
Vector<DComplex> testveccomplex (const Vector<DComplex>& in)
{cout << "VecComplex " << in << endl; return in;}
Vector<String> testvecstr (const Vector<String>& in)
{cout << "VecStr " << in << endl; return in;}
+ std::vector<bool> teststdvecbool (const std::vector<bool>& in)
+ {cout << "vecbool " << in << endl; return in;}
std::vector<uInt> teststdvecuint (const std::vector<uInt>& in)
{cout << "vecuInt " << in << endl; return in;}
std::vector<std::vector<uInt> > teststdvecvecuint
(const std::vector<std::vector<uInt> >& in)
{cout << "vecvecuInt " << in << endl; return in;}
+ std::vector<ValueHolder> teststdvecvh (const std::vector<ValueHolder>&
in)
+ {cout << "vecvh " << in.size() << endl; return in;}
IPosition testipos (const IPosition& in)
{cout << "IPos " << in << endl; return in;}
};
@@ -105,11 +100,14 @@
.def ("teststring", &TConvert::teststring)
.def ("testrecord", &TConvert::testrecord)
.def ("testvh", &TConvert::testvh)
+ .def ("testvecbool", &TConvert::testvecbool)
.def ("testvecint", &TConvert::testvecint)
.def ("testveccomplex", &TConvert::testveccomplex)
.def ("testvecstr", &TConvert::testvecstr)
+ .def ("teststdvecbool", &TConvert::teststdvecbool)
.def ("teststdvecuint", &TConvert::teststdvecuint)
.def ("teststdvecvecuint", &TConvert::teststdvecvecuint)
+ .def ("teststdvecvh" , &TConvert::teststdvecvh)
.def ("testipos", &TConvert::testipos)
;
}
@@ -124,8 +122,10 @@
casacore::python::register_convert_basicdata();
casacore::python::register_convert_casa_valueholder();
casacore::python::register_convert_casa_record();
+ casacore::python::register_convert_std_vector<bool>();
casacore::python::register_convert_std_vector<casacore::uInt>();

casacore::python::register_convert_std_vector<std::vector<casacore::uInt>
>();
+ casacore::python::register_convert_std_vector<casacore::ValueHolder>();

// Execute the test.
casacore::python::testConvert();
=======================================
--- /branches/nov14/python/Converters/test/tConvert.out Wed Dec 17 15:21:43
2014 UTC
+++ /branches/nov14/python/Converters/test/tConvert.out Mon Mar 2 10:51:35
2015 UTC
@@ -252,6 +252,8 @@
[2]
IPos [3]
[3]
+VecBool [1, 0, 0, 1]
+[True, False, False, True]
VecInt [1, 2, 3, 4]
[1, 2, 3, 4]
VecInt []
@@ -272,21 +274,23 @@
[]
VecStr [sc1]
['sc1']
-vecuInt [vecuInt 1, vecuInt 2, vecuInt 4]
+vecbool [0,1]
+[False, True]
+vecuInt [1,2,4]
[1, 2, 4]
vecuInt []
[]
-vecuInt [vecuInt 10]
+vecuInt [10]
[10]
-vecvecuInt [vecuInt [vecuInt 1, vecuInt 2, vecuInt 4]]
+vecvecuInt [[1,2,4]]
[[1, 2, 4]]
vecvecuInt []
[]
vecvecuInt []
[]
-vecvecuInt [vecuInt [vecuInt 1], vecuInt [vecuInt 2], vecuInt [vecuInt 4]]
+vecvecuInt [[1],[2],[4]]
[[1], [2], [4]]
-vecvecuInt [vecuInt [vecuInt 20]]
+vecvecuInt [[20]]
[[20]]
VH Bool
True
@@ -347,6 +351,8 @@
VH Array<double>
<<<
(1, 0)
+vecvh 3
+[2, 1.3, array([ True, False], dtype=bool)]
Record int: Int 1
int64: Int64 123456789012
str: String "bc"
=======================================
--- /branches/nov14/python/Converters/test/tConvert.py Wed Dec 17 15:21:43
2014 UTC
+++ /branches/nov14/python/Converters/test/tConvert.py Mon Mar 2 10:51:35
2015 UTC
@@ -22,6 +22,7 @@
print t.testipos (NUM.array([2]));
print t.testipos (NUM.array(3));

+ print t.testvecbool ([True,False,False,True])
print t.testvecint ([1,2,3,4]);
print t.testvecint ([]);
print t.testvecint ((-1,-2,-3,-4));
@@ -32,6 +33,7 @@
print t.testvecstr (["a1","a2","b1","b2"])
print t.testvecstr (())
print t.testvecstr ("sc1")
+ print t.teststdvecbool ([False,True])
print t.teststdvecuint ([1,2,4])
print t.teststdvecuint (())
print t.teststdvecuint (10)
@@ -89,6 +91,9 @@
print '<<<';
print res.shape;

+ # Test a sequence of ValueHolders
+ print t.teststdvecvh([2, 1.3, [True,False]]);
+
# On 64-bit machines the output also contains 'dtype=int32'
# So leave it out.
a =
t.testrecord({"int":1, "int64":123456789012L, "str":"bc", 'vecint':[1,2,3]})
Reply all
Reply to author
Forward
0 new messages