diff options
Diffstat (limited to 'gruel/src')
-rw-r--r-- | gruel/src/include/gruel/pmt.h | 20 | ||||
-rw-r--r-- | gruel/src/lib/pmt/pmt.cc | 10 | ||||
-rw-r--r-- | gruel/src/lib/pmt/qa_pmt_prims.cc | 12 | ||||
-rw-r--r-- | gruel/src/lib/pmt/unv_template.cc.t | 12 | ||||
-rw-r--r-- | gruel/src/swig/pmt_swig.i | 50 |
5 files changed, 73 insertions, 31 deletions
diff --git a/gruel/src/include/gruel/pmt.h b/gruel/src/include/gruel/pmt.h index 68b122105..383a1d44d 100644 --- a/gruel/src/include/gruel/pmt.h +++ b/gruel/src/include/gruel/pmt.h @@ -223,6 +223,12 @@ GRUEL_API bool pmt_is_complex(pmt_t obj); //! Return a complex number constructed of the given real and imaginary parts. GRUEL_API pmt_t pmt_make_rectangular(double re, double im); +//! Return a complex number constructed of the given real and imaginary parts. +GRUEL_API pmt_t pmt_from_complex(double re, double im); + +//! Return a complex number constructed of the given a complex number. +GRUEL_API pmt_t pmt_from_complex(const std::complex<double> &z); + /*! * If \p z is complex, real or integer, return the closest complex<double>. * Otherwise, raise the wrong_type exception. @@ -480,6 +486,20 @@ GRUEL_API const double *pmt_f64vector_elements(pmt_t v, size_t &len); //< len GRUEL_API const std::complex<float> *pmt_c32vector_elements(pmt_t v, size_t &len); //< len is in elements GRUEL_API const std::complex<double> *pmt_c64vector_elements(pmt_t v, size_t &len); //< len is in elements +// len is in elements +GRUEL_API const std::vector<uint8_t> pmt_u8vector_elements(pmt_t v); +GRUEL_API const std::vector<int8_t> pmt_s8vector_elements(pmt_t v); +GRUEL_API const std::vector<uint16_t> pmt_u16vector_elements(pmt_t v); +GRUEL_API const std::vector<int16_t> pmt_s16vector_elements(pmt_t v); +GRUEL_API const std::vector<uint32_t> pmt_u32vector_elements(pmt_t v); +GRUEL_API const std::vector<int32_t> pmt_s32vector_elements(pmt_t v); +GRUEL_API const std::vector<uint64_t> pmt_u64vector_elements(pmt_t v); +GRUEL_API const std::vector<int64_t> pmt_s64vector_elements(pmt_t v); +GRUEL_API const std::vector<float> pmt_f32vector_elements(pmt_t v); +GRUEL_API const std::vector<double> pmt_f64vector_elements(pmt_t v); +GRUEL_API const std::vector<std::complex<float> > pmt_c32vector_elements(pmt_t v); +GRUEL_API const std::vector<std::complex<double> > pmt_c64vector_elements(pmt_t v); + // Return non-const pointers to the elements GRUEL_API void *pmt_uniform_vector_writable_elements(pmt_t v, size_t &len); //< works with any; len is in bytes diff --git a/gruel/src/lib/pmt/pmt.cc b/gruel/src/lib/pmt/pmt.cc index e5baca98a..1d1e9ba7c 100644 --- a/gruel/src/lib/pmt/pmt.cc +++ b/gruel/src/lib/pmt/pmt.cc @@ -388,9 +388,19 @@ pmt_is_complex(pmt_t x) pmt_t pmt_make_rectangular(double re, double im) { + return pmt_from_complex(re, im); +} + +pmt_t pmt_from_complex(double re, double im) +{ return pmt_t(new pmt_complex(std::complex<double>(re, im))); } +pmt_t pmt_from_complex(const std::complex<double> &z) +{ + return pmt_t(new pmt_complex(z)); +} + std::complex<double> pmt_to_complex(pmt_t x) { diff --git a/gruel/src/lib/pmt/qa_pmt_prims.cc b/gruel/src/lib/pmt/qa_pmt_prims.cc index 1bf5fcfb1..3ae4d70b6 100644 --- a/gruel/src/lib/pmt/qa_pmt_prims.cc +++ b/gruel/src/lib/pmt/qa_pmt_prims.cc @@ -134,12 +134,24 @@ qa_pmt_prims::test_complexes() { pmt_t p1 = pmt_make_rectangular(2, -3); pmt_t m1 = pmt_make_rectangular(-3, 2); + pmt_t p2 = pmt_from_complex(2, -3); + pmt_t m2 = pmt_from_complex(-3, 2); + pmt_t p3 = pmt_from_complex(std::complex<double>(2, -3)); + pmt_t m3 = pmt_from_complex(std::complex<double>(-3, 2)); CPPUNIT_ASSERT(!pmt_is_complex(PMT_T)); CPPUNIT_ASSERT(pmt_is_complex(p1)); CPPUNIT_ASSERT(pmt_is_complex(m1)); + CPPUNIT_ASSERT(pmt_is_complex(p2)); + CPPUNIT_ASSERT(pmt_is_complex(m2)); + CPPUNIT_ASSERT(pmt_is_complex(p3)); + CPPUNIT_ASSERT(pmt_is_complex(m3)); CPPUNIT_ASSERT_THROW(pmt_to_complex(PMT_T), pmt_wrong_type); CPPUNIT_ASSERT_EQUAL(std::complex<double>(2, -3), pmt_to_complex(p1)); CPPUNIT_ASSERT_EQUAL(std::complex<double>(-3, 2), pmt_to_complex(m1)); + CPPUNIT_ASSERT_EQUAL(std::complex<double>(2, -3), pmt_to_complex(p2)); + CPPUNIT_ASSERT_EQUAL(std::complex<double>(-3, 2), pmt_to_complex(m2)); + CPPUNIT_ASSERT_EQUAL(std::complex<double>(2, -3), pmt_to_complex(p3)); + CPPUNIT_ASSERT_EQUAL(std::complex<double>(-3, 2), pmt_to_complex(m3)); CPPUNIT_ASSERT_EQUAL(std::complex<double>(1.0, 0), pmt_to_complex(pmt_from_long(1))); CPPUNIT_ASSERT_EQUAL(std::complex<double>(1.0, 0), pmt_to_complex(pmt_from_double(1.0))); } diff --git a/gruel/src/lib/pmt/unv_template.cc.t b/gruel/src/lib/pmt/unv_template.cc.t index f74397421..1ed505e29 100644 --- a/gruel/src/lib/pmt/unv_template.cc.t +++ b/gruel/src/lib/pmt/unv_template.cc.t @@ -118,6 +118,18 @@ pmt_@TAG@vector_elements(pmt_t vector, size_t &len) return _@TAG@vector(vector)->elements(len); } +const std::vector< @TYPE@ > +pmt_@TAG@vector_elements(pmt_t vector) +{ + if (!vector->is_@TAG@vector()) + throw pmt_wrong_type("pmt_@TAG@vector_elements", vector); + size_t len; + const @TYPE@ *array = _@TAG@vector(vector)->elements(len); + const std::vector< @TYPE@ > vec(array, array+len); + return vec; +} + + @TYPE@ * pmt_@TAG@vector_writable_elements(pmt_t vector, size_t &len) { diff --git a/gruel/src/swig/pmt_swig.i b/gruel/src/swig/pmt_swig.i index b65857167..84f48b099 100644 --- a/gruel/src/swig/pmt_swig.i +++ b/gruel/src/swig/pmt_swig.i @@ -212,6 +212,8 @@ bool pmt_is_complex(pmt_t obj); //! Return a complex number constructed of the given real and imaginary parts. pmt_t pmt_make_rectangular(double re, double im); +pmt_t pmt_from_complex(const std::complex<double> &z); + /*! * If \p z is complex, real or integer, return the closest complex<double>. * Otherwise, raise the wrong_type exception. @@ -441,37 +443,23 @@ void pmt_c64vector_set(pmt_t v, size_t k, std::complex<double> x); // Return const pointers to the elements -const void *pmt_uniform_vector_elements(pmt_t v, size_t &len); //< works with any; len is in bytes - -const uint8_t *pmt_u8vector_elements(pmt_t v, size_t &len); //< len is in elements -const int8_t *pmt_s8vector_elements(pmt_t v, size_t &len); //< len is in elements -const uint16_t *pmt_u16vector_elements(pmt_t v, size_t &len); //< len is in elements -const int16_t *pmt_s16vector_elements(pmt_t v, size_t &len); //< len is in elements -const uint32_t *pmt_u32vector_elements(pmt_t v, size_t &len); //< len is in elements -const int32_t *pmt_s32vector_elements(pmt_t v, size_t &len); //< len is in elements -const uint64_t *pmt_u64vector_elements(pmt_t v, size_t &len); //< len is in elements -const int64_t *pmt_s64vector_elements(pmt_t v, size_t &len); //< len is in elements -const float *pmt_f32vector_elements(pmt_t v, size_t &len); //< len is in elements -const double *pmt_f64vector_elements(pmt_t v, size_t &len); //< len is in elements -const std::complex<float> *pmt_c32vector_elements(pmt_t v, size_t &len); //< len is in elements -const std::complex<double> *pmt_c64vector_elements(pmt_t v, size_t &len); //< len is in elements - -// Return non-const pointers to the elements - -void *pmt_uniform_vector_writable_elements(pmt_t v, size_t &len); //< works with any; len is in bytes - -uint8_t *pmt_u8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int8_t *pmt_s8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -uint16_t *pmt_u16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int16_t *pmt_s16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -uint32_t *pmt_u32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int32_t *pmt_s32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -uint64_t *pmt_u64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int64_t *pmt_s64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -float *pmt_f32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -double *pmt_f64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -std::complex<float> *pmt_c32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -std::complex<double> *pmt_c64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +%apply size_t & INOUT { size_t &len }; + +// works with any; len is in bytes +// Returns an opaque Python type +const void *pmt_uniform_vector_elements(pmt_t v, size_t &len); + +// Returns a Python tuple +const std::vector<uint8_t> pmt_u8vector_elements(pmt_t v); +const std::vector<int8_t> pmt_s8vector_elements(pmt_t v); +const std::vector<uint16_t> pmt_u16vector_elements(pmt_t v); +const std::vector<int16_t> pmt_s16vector_elements(pmt_t v); +const std::vector<uint32_t> pmt_u32vector_elements(pmt_t v); +const std::vector<int32_t> pmt_s32vector_elements(pmt_t v); +const std::vector<float> pmt_f32vector_elements(pmt_t v); +const std::vector<double> pmt_f64vector_elements(pmt_t v); +const std::vector<std::complex<float> > pmt_c32vector_elements(pmt_t v); +const std::vector<std::complex<double> > pmt_c64vector_elements(pmt_t v); /* * ------------------------------------------------------------------------ |