Commit d6e232c7 authored by Christoph Groth's avatar Christoph Groth
Browse files

implement conjugate

parent a455ba70
......@@ -449,6 +449,22 @@ struct Absolute<Complex> {
double operator()(Complex x) { return std::abs(x); }
};
template <typename T>
struct Conjugate {
typedef T Type;
static constexpr const char *error = 0;
static const bool unchanged = true;
T operator()(T x) { return x; }
};
template <>
struct Conjugate<Complex> {
typedef Complex Type;
static constexpr const char *error = 0;
static const bool unchanged = false;
Complex operator()(Complex x) { return std::conj(x); }
};
// Integers are not changed by any kind of rounding.
template <typename Kind>
struct Round<Kind, long> {
......@@ -534,12 +550,18 @@ template PyNumberMethods Array<long>::as_number;
template PyNumberMethods Array<double>::as_number;
template PyNumberMethods Array<Complex>::as_number;
template PyObject *apply_unary_ufunc<Conjugate<long>>(PyObject*);
template PyObject *apply_unary_ufunc<Conjugate<double>>(PyObject*);
template PyObject *apply_unary_ufunc<Conjugate<Complex>>(PyObject*);
template PyObject *apply_unary_ufunc<Round<Nearest, long>>(PyObject*);
template PyObject *apply_unary_ufunc<Round<Nearest, double>>(PyObject*);
template PyObject *apply_unary_ufunc<Round<Nearest, Complex>>(PyObject*);
template PyObject *apply_unary_ufunc<Round<Floor, long>>(PyObject*);
template PyObject *apply_unary_ufunc<Round<Floor, double>>(PyObject*);
template PyObject *apply_unary_ufunc<Round<Floor, Complex>>(PyObject*);
template PyObject *apply_unary_ufunc<Round<Ceil, long>>(PyObject*);
template PyObject *apply_unary_ufunc<Round<Ceil, double>>(PyObject*);
template PyObject *apply_unary_ufunc<Round<Ceil, Complex>>(PyObject*);
......@@ -37,6 +37,7 @@ template <typename Op> PyObject *apply_unary_ufunc(PyObject *a);
template <typename T> struct Negative;
template <typename T> struct Positive;
template <typename T> struct Absolute;
template <typename T> struct Conjugate;
template <typename Kind, typename T> struct Round;
// Kinds of rounding, to be used with Round.
......
......@@ -3,6 +3,7 @@
#include <sstream>
#include <limits>
#include "array.hh"
#include "arithmetic.hh"
#include "functions.hh"
#include "conversion.hh"
......@@ -1126,6 +1127,7 @@ PyBufferProcs Array<T>::as_buffer = {
template <typename T>
PyMethodDef Array<T>::methods[] = {
{"transpose", (PyCFunction)transpose<T>, METH_NOARGS},
{"conjugate", (PyCFunction)apply_unary_ufunc<Conjugate<T> >, METH_NOARGS},
{0, 0} // Sentinel
};
......
......@@ -179,6 +179,7 @@ PyMethodDef functions[] = {
{"negative", unary_ufunc<Negative>, METH_VARARGS},
{"abs", unary_ufunc<Absolute>, METH_VARARGS},
{"absolute", unary_ufunc<Absolute>, METH_VARARGS},
{"conjugate", unary_ufunc<Conjugate>, METH_VARARGS},
{"round", unary_ufunc<Round_nearest>, METH_VARARGS},
{"floor", unary_ufunc<Round_floor>, METH_VARARGS},
{"ceil", unary_ufunc<Round_ceil>, METH_VARARGS},
......
......@@ -247,7 +247,8 @@ def test_unary_operators():
def test_unary_ufuncs():
for name in ["negative", "abs", "absolute", "round", "floor", "ceil"]:
for name in ["negative", "abs", "absolute", "round", "floor", "ceil",
"conjugate"]:
np_func = np.__dict__[name]
ta_func = ta.__dict__[name]
for dtype in dtypes:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment