From e01cfd70c7b23c2c5fb9db6a0b7c0cbf4374c341 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 2 Oct 2017 09:03:27 +0100 Subject: [PATCH] Add missing declaration for std::complex Fixes missing type information for std::complex in scripting languages. Closes #732. Update Javascript and Octave complextest, although they don't actually get run as they don't work --- CHANGES.current | 5 +++++ Examples/test-suite/complextest.i | 17 ++++++++++++++--- Examples/test-suite/csharp/complextest_runme.cs | 6 ++++++ .../test-suite/javascript/complextest_runme.js | 12 ++++++++++-- Examples/test-suite/octave/complextest_runme.m | 13 +++++++++---- Examples/test-suite/python/complextest_runme.py | 12 ++++++++---- Lib/javascript/jsc/std_complex.i | 7 +++++++ Lib/javascript/v8/std_complex.i | 7 +++++++ Lib/octave/std_complex.i | 7 +++++++ Lib/python/std_complex.i | 9 +++++++-- Lib/ruby/std_complex.i | 7 +++++++ 11 files changed, 87 insertions(+), 15 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index e109d0447..fed03bfad 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -14,6 +14,11 @@ Version 4.0.0 (in progress) declared as such) smart-pointer classes deriving from parent smart-pointers +2017-10-02: wsfulton + [Javascript, Python, Ruby] Issue #732 - Missing type information for std::complex + in std_complex.i meant that previously std::complex always had to be fully qualified + in order to be wrapped with the appropriate typemaps. + 2017-09-29: wsfulton Issue #1100 - Allow an instantiated template to have the same name in the target language as the C++ template name, for example, this is now possible: diff --git a/Examples/test-suite/complextest.i b/Examples/test-suite/complextest.i index 6e82e8915..83dcdb907 100644 --- a/Examples/test-suite/complextest.i +++ b/Examples/test-suite/complextest.i @@ -26,19 +26,30 @@ return std::conj(a); } -#if 1 std::vector > Copy_h(const std::vector >& a) { std::vector > b(a.size()/2); std::copy(a.begin(), a.begin()+a.size()/2, b.begin()); return b; } -#endif + + using namespace std; struct ComplexPair { - std::complex z1, z2; + std::complex z1; + complex z2; }; + + complex Conj2(const complex& a) + { + return std::conj(a); + } + + complex Conjf2(const complex& a) + { + return std::conj(a); + } } diff --git a/Examples/test-suite/csharp/complextest_runme.cs b/Examples/test-suite/csharp/complextest_runme.cs index 2b7e4cc84..244a6fa1b 100644 --- a/Examples/test-suite/csharp/complextest_runme.cs +++ b/Examples/test-suite/csharp/complextest_runme.cs @@ -16,6 +16,12 @@ public class complextest_runme { if ( complextest.Conjf(a) != Complex.Conjugate(a) ) throw new Exception("std::complex test failed"); + if ( complextest.Conj2(a) != Complex.Conjugate(a) ) + throw new Exception("std::complex test failed"); + + if ( complextest.Conjf2(a) != Complex.Conjugate(a) ) + throw new Exception("std::complex test failed"); + var vec = new VectorStdCplx(); vec.Add(new Complex(1, 2)); vec.Add(new Complex(2, 3)); diff --git a/Examples/test-suite/javascript/complextest_runme.js b/Examples/test-suite/javascript/complextest_runme.js index b87d6bffa..ee7b93e04 100644 --- a/Examples/test-suite/javascript/complextest_runme.js +++ b/Examples/test-suite/javascript/complextest_runme.js @@ -8,8 +8,16 @@ a_c = complextest.Conj(a); if (a_c.toString() != expected.toString()) throw "Error in Conj(a)"; -a_c_f = complextest.Conjf(a); -if (a_c_f.toString() != expected.toString()) +a_c = complextest.Conjf(a); +if (a_c.toString() != expected.toString()) + throw "Error in Conjf(a)"; + +a_c = complextest.Conj2(a); +if (a_c.toString() != expected.toString()) + throw "Error in Conj(a)"; + +a_c = complextest.Conjf2(a); +if (a_c.toString() != expected.toString()) throw "Error in Conjf(a)"; v = new complextest.VectorStdCplx(); diff --git a/Examples/test-suite/octave/complextest_runme.m b/Examples/test-suite/octave/complextest_runme.m index 6a5433f1f..2341e8828 100644 --- a/Examples/test-suite/octave/complextest_runme.m +++ b/Examples/test-suite/octave/complextest_runme.m @@ -15,10 +15,15 @@ if (complextest.Conjf(a) != a.conjugate()) error("bad complex mapping") endif +if (complextest.Conj2(a) != a.conjugate()) + error("bad complex mapping") +endif + +if (complextest.Conjf2(a) != a.conjugate()) + error("bad complex mapping") +endif + v = (complex(1,2), complex(2,3), complex(4,3), 1); -try - complextest.Copy_h(v); -catch -end_try_catch +complextest.Copy_h(v); diff --git a/Examples/test-suite/python/complextest_runme.py b/Examples/test-suite/python/complextest_runme.py index a55e6098b..f82b21b42 100644 --- a/Examples/test-suite/python/complextest_runme.py +++ b/Examples/test-suite/python/complextest_runme.py @@ -8,13 +8,17 @@ if complextest.Conj(a) != a.conjugate(): if complextest.Conjf(a) != a.conjugate(): raise RuntimeError, "bad complex mapping" +if complextest.Conj2(a) != a.conjugate(): + raise RuntimeError, "bad complex mapping" + +if complextest.Conjf2(a) != a.conjugate(): + raise RuntimeError, "bad complex mapping" + v = (complex(1, 2), complex(2, 3), complex(4, 3), 1) -try: - complextest.Copy_h(v) -except: - pass +if len(complextest.Copy_h(v)) != 2: + raise RuntimeError("Copy_h failed") p = complextest.ComplexPair() p.z1 = complex(0, 1) diff --git a/Lib/javascript/jsc/std_complex.i b/Lib/javascript/jsc/std_complex.i index 088a4fe7b..a252e0aa8 100644 --- a/Lib/javascript/jsc/std_complex.i +++ b/Lib/javascript/jsc/std_complex.i @@ -8,6 +8,13 @@ #include %} +namespace std { + %naturalvar complex; + template class complex; + %template() complex; + %template() complex; +} + /* defining the complex as/from converters */ %swig_cplxdbl_convn(std::complex, std::complex, std::real, std::imag) diff --git a/Lib/javascript/v8/std_complex.i b/Lib/javascript/v8/std_complex.i index 088a4fe7b..a252e0aa8 100644 --- a/Lib/javascript/v8/std_complex.i +++ b/Lib/javascript/v8/std_complex.i @@ -8,6 +8,13 @@ #include %} +namespace std { + %naturalvar complex; + template class complex; + %template() complex; + %template() complex; +} + /* defining the complex as/from converters */ %swig_cplxdbl_convn(std::complex, std::complex, std::real, std::imag) diff --git a/Lib/octave/std_complex.i b/Lib/octave/std_complex.i index 771728b9d..30c188244 100644 --- a/Lib/octave/std_complex.i +++ b/Lib/octave/std_complex.i @@ -8,6 +8,13 @@ #include %} +namespace std { + %naturalvar complex; + template class complex; + %template() complex; + %template() complex; +} + /* defining the complex as/from converters */ %swig_cplxdbl_convn(std::complex, std::complex, std::real, std::imag) diff --git a/Lib/python/std_complex.i b/Lib/python/std_complex.i index 4e8fed305..c9c46c4c3 100644 --- a/Lib/python/std_complex.i +++ b/Lib/python/std_complex.i @@ -8,6 +8,13 @@ #include %} +namespace std { + %naturalvar complex; + template class complex; + %template() complex; + %template() complex; +} + /* defining the complex as/from converters */ %swig_cplxdbl_convn(std::complex, std::complex, std::real, std::imag) @@ -18,5 +25,3 @@ %typemaps_primitive(%checkcode(CPLXDBL), std::complex); %typemaps_primitive(%checkcode(CPLXFLT), std::complex); - - diff --git a/Lib/ruby/std_complex.i b/Lib/ruby/std_complex.i index dacbea2bb..ef4e8a104 100644 --- a/Lib/ruby/std_complex.i +++ b/Lib/ruby/std_complex.i @@ -8,6 +8,13 @@ #include %} +namespace std { + %naturalvar complex; + template class complex; + %template() complex; + %template() complex; +} + /* defining the complex as/from converters */ %swig_cplxdbl_convn(std::complex, std::complex, std::real, std::imag)