A high-performance general-purpose compute library
complex.h
Go to the documentation of this file.
1/*******************************************************
2 * Copyright (c) 2014, ArrayFire
3 * All rights reserved.
4 *
5 * This file is distributed under 3-clause BSD license.
6 * The complete license agreement can be obtained at:
7 * http://arrayfire.com/licenses/BSD-3-Clause
8 ********************************************************/
9
10#pragma once
11#include "af/defines.h"
12
13
14#ifdef __cplusplus
15#include <ostream>
16#include <istream>
17
18namespace af{
19#endif
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24typedef struct af_cfloat {
25 float real;
26 float imag;
27#ifdef __cplusplus
28 af_cfloat(const float _real = 0, const float _imag = 0) :real(_real), imag(_imag) {}
29#endif
30} af_cfloat;
31
32typedef struct af_cdouble {
33 double real;
34 double imag;
35#ifdef __cplusplus
36 af_cdouble(const double _real = 0, const double _imag = 0) :real(_real), imag(_imag) {}
37#endif
38} af_cdouble;
39#ifdef __cplusplus
40}
41#endif
42
43#ifdef __cplusplus
46
47AFAPI float real(af_cfloat val);
48AFAPI double real(af_cdouble val);
49
50AFAPI float imag(af_cfloat val);
51AFAPI double imag(af_cdouble val);
52
53// +,-,*,/ for (cfloat, cfloat) and (cdouble, cdouble)
54#define DEFINE_OP(OP) \
55 AFAPI af::cfloat operator OP(const af::cfloat &lhs, const af::cfloat &rhs); \
56 AFAPI af::cdouble operator OP(const af::cdouble &lhs, const af::cdouble &rhs); \
57
62
63#undef DEFINE_OP
64
65// +,/ for (cfloat, double) and (cdouble, double)
66#define DEFINE_OP(OP) \
67 AFAPI af::cfloat operator OP(const af::cfloat &lhs, const double &rhs); \
68 AFAPI af::cdouble operator OP(const af::cdouble &lhs, const double &rhs); \
69
72
73#undef DEFINE_OP
74
75#if AF_API_VERSION >= 31
76// -,* for (cfloat, double) and (cdouble, double)
77#define DEFINE_OP(OP) \
78 AFAPI af::cfloat operator OP(const af::cfloat &lhs, const double &rhs); \
79 AFAPI af::cdouble operator OP(const af::cdouble &lhs, const double &rhs); \
80
83
84#undef DEFINE_OP
85#endif // AF_API_VERSION
86
87#if AF_API_VERSION >= 31
88// +, -, *, / for (double, cfloat/cdouble) and (cfloat/cdouble, cdouble/cfloat)
89#define DEFINE_OP(OP) \
90 AFAPI af::cfloat operator OP(const double &rhs, const af::cfloat &lhs); \
91 AFAPI af::cdouble operator OP(const double &rhs, const af::cdouble &lhs); \
92 AFAPI af::cdouble operator OP(const af::cfloat &lhs, const af::cdouble &rhs); \
93 AFAPI af::cdouble operator OP(const af::cdouble &lhs, const af::cfloat &rhs); \
94
99
100#undef DEFINE_OP
101#endif // AF_API_VERSION
102
103AFAPI bool operator==(const cfloat &lhs, const cfloat &rhs);
104AFAPI bool operator==(const cdouble &lhs, const cdouble &rhs);
105
106AFAPI bool operator!=(const cfloat &lhs, const cfloat &rhs);
107AFAPI bool operator!=(const cdouble &lhs, const cdouble &rhs);
108
109AFAPI std::istream& operator>> (std::istream &is, cfloat &in);
110AFAPI std::istream& operator>> (std::istream &is, cdouble &in);
111
112AFAPI std::ostream& operator<< (std::ostream &os, const cfloat &in);
113AFAPI std::ostream& operator<< (std::ostream &os, const cdouble &in);
114
115
116AFAPI float abs(const cfloat &val);
117AFAPI double abs(const cdouble &val);
118
121
122}
123#endif
#define DEFINE_OP(OP)
Definition: complex.h:89
#define AFAPI
Definition: defines.h:38
AFAPI array abs(const array &in)
C++ Interface to calculate the absolute value.
AFAPI array operator==(const array &lhs, const array &rhs)
Performs an equality operation on two arrays or an array and a value.
AFAPI array imag(const array &in)
C++ Interface to return the imaginary part of a complex array.
AFAPI array operator!=(const array &lhs, const array &rhs)
Performs an inequality operation on two arrays or an array and a value.
AFAPI array real(const array &in)
C++ Interface to return the real part of a complex array.
AFAPI array operator<<(const array &lhs, const array &rhs)
Performs an left shift operation on two arrays or an array and a value.
AFAPI array operator>>(const array &lhs, const array &rhs)
Performs an right shift operation on two arrays or an array and a value.
Definition: algorithm.h:15
af::af_cfloat cfloat
Definition: complex.h:44
af::af_cdouble cdouble
Definition: complex.h:45
AFAPI cfloat conj(const cfloat &val)
af_cdouble(const double _real=0, const double _imag=0)
Definition: complex.h:36
double real
Definition: complex.h:33
double imag
Definition: complex.h:34
float real
Definition: complex.h:25
af_cfloat(const float _real=0, const float _imag=0)
Definition: complex.h:28
float imag
Definition: complex.h:26