Fix C# std::complex pass by value typemaps

This commit is contained in:
William S Fulton 2017-10-02 19:06:06 +01:00
commit a55981b883
7 changed files with 45 additions and 20 deletions

View file

@ -14,6 +14,9 @@ Version 4.0.0 (in progress)
declared as such)
smart-pointer classes deriving from parent smart-pointers
2017-10-02: wsfulton
[C#] Fix std::complex types passed by value.
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

View file

@ -14,24 +14,24 @@
%template(VectorStdCplx) std::vector<std::complex<double> >;
#endif
%inline
%inline
{
std::complex<double> Conj(const std::complex<double>& a)
std::complex<double> Conj(std::complex<double> a)
{
return std::conj(a);
}
}
std::complex<float> Conjf(const std::complex<float>& a)
std::complex<float> Conjf(std::complex<float> a)
{
return std::conj(a);
}
}
std::vector<std::complex<double> > Copy_h(const std::vector<std::complex<double> >& a)
std::vector<std::complex<double> > CopyHalf(std::vector<std::complex<double> > a)
{
std::vector<std::complex<double> > b(a.size()/2);
std::copy(a.begin(), a.begin()+a.size()/2, b.begin());
return b;
}
}
using namespace std;
@ -41,14 +41,25 @@
complex<double> z2;
};
complex<double> Conj2(const complex<double>& a)
const complex<double>& Conj2(const complex<double>& a)
{
return std::conj(a);
static complex<double> ret;
ret = std::conj(a);
return ret;
}
complex<float> Conjf2(const complex<float>& a)
const complex<float>& Conjf2(const complex<float>& a)
{
return std::conj(a);
static complex<float> ret;
ret = std::conj(a);
return ret;
}
const vector<complex<double> >& CopyHalfRef(const vector<complex<double> >& a)
{
static vector<complex<double> > b;
b = CopyHalf(a);
return b;
}
}
@ -59,7 +70,7 @@
%{
%}
%inline
%inline
{
complex Conj(complex a)
{

View file

@ -28,8 +28,11 @@ public class complextest_runme {
vec.Add(new Complex(4, 3));
vec.Add(new Complex(1, 0));
if ( complextest.Copy_h(vec).Count != 2 )
throw new Exception("vector<complex> test failed");
if ( complextest.CopyHalf(vec).Count != 2 )
throw new Exception("CopyHalf test failed");
if ( complextest.CopyHalfRef(vec).Count != 2 )
throw new Exception("CopyHalfRef test failed");
var p = new ComplexPair();
p.z1 = new Complex(0, 1);

View file

@ -27,4 +27,5 @@ v.add([4,3]);
v.add(1);
// TODO: how to check validity?
complextest.Copy_h(v);
complextest.CopyHalf(v);
complextest.CopyHalfRef(v);

View file

@ -26,4 +26,5 @@ endif
v = (complex(1,2), complex(2,3), complex(4,3), 1);
complextest.Copy_h(v);
complextest.CopyHalf(v);
complextest.CopyHalfRef(v);

View file

@ -17,8 +17,11 @@ if complextest.Conjf2(a) != a.conjugate():
v = (complex(1, 2), complex(2, 3), complex(4, 3), 1)
if len(complextest.Copy_h(v)) != 2:
raise RuntimeError("Copy_h failed")
if len(complextest.CopyHalf(v)) != 2:
raise RuntimeError("CopyHalf failed")
if len(complextest.CopyHalfRef(v)) != 2:
raise RuntimeError("CopyHalfRef failed")
p = complextest.ComplexPair()
p.z1 = complex(0, 1)

View file

@ -45,8 +45,11 @@ public:
%typemap(imtype) std::complex<T>, const std::complex<T> & "System.Numerics.Complex"
%typemap(cstype) std::complex<T>, const std::complex<T> & "System.Numerics.Complex"
%typemap(in) std::complex<T>($*1_ltype temp), const std::complex<T> &($*1_ltype temp)
%{temp = std::complex< double >($input.real, $input.imag);
%typemap(in) std::complex<T>
%{$1 = std::complex< double >($input.real, $input.imag);%}
%typemap(in) const std::complex<T> &($*1_ltype temp)
%{temp = std::complex< T >($input.real, $input.imag);
$1 = &temp;%}
%typemap(out, null="SwigCreateSystemNumericsComplex(0.0, 0.0)") std::complex<T>