A high-performance general-purpose compute library

- Main Page
- Tutorials
- Release Notes
- Examples

Functions
complex
ArrayFire Functions | ArrayFire Functions by Category » Mathematical functions » Complex operations

## Functions
af_err | af_cplx (af_array *out, const af_array in)
| C Interface to create a complex array from a single real array.
af_err | af_cplx2 (af_array *out, const af_array real, const af_array imag, const bool batch)
| C Interface to create a complex array from two real arrays.
array | complex (const array &in)
| C++ Interface to create a complex array from a single real array.
array | complex (const array &real_, const array &imag_)
| C++ Interface to create a complex array from two real arrays.
array | complex (const array &real_, const double imag_)
| C++ Interface to create a complex array from a single real array for the real component and a single scalar for each imaginary component.
array | complex (const double real_, const array &imag_)
| C++ Interface to create a complex array from a single scalar for each real component and a single real array for the imaginary component.

## Detailed Description

Create complex arrays.

Complex arrays are created from any of the following four inputs:

1. a single real array, returning zeros for the imaginary component. See `array b` in the example.
2. two real arrays, one for the real component and one for the imaginary component. See `array c` in the example.
3. a single real array for the real component and a single scalar for each imaginary component. See `array d` in the example.
4. a single scalar for each real component and a single real array for the imaginary component. See `array e` in the example.

Examples:

// Create a, a 2x3 array
array a = iota(dim4(2, 3)); // a = [0, 2, 4,
// 1, 3, 5]
// Create b from a single real array, returning zeros for the imaginary
// component
array b = complex(a); // b = [(0, 0), (2, 0), (4, 0),
// (1, 0), (3, 0), (5, 0)]
// Create c from two real arrays, one for the real component and one for the
// imaginary component
array c = complex(a, a); // c = [(0, 0), (2, 2), (4, 4),
// (1, 1), (3, 3), (5, 5)]
// Create d from a single real array for the real component and a single
// scalar for each imaginary component
array d = complex(a, 2); // d = [(0, 2), (2, 2), (4, 2),
// (1, 2), (3, 2), (5, 2)]
// Create e from a single scalar for each real component and a single real
// array for the imaginary component
array e = complex(2, a); // e = [(2, 0), (2, 2), (2, 4),
// (2, 1), (2, 3), (2, 5)]

## Function Documentation

## ◆ af_cplx()

af_err af_cplx | ( | af_array * | out,
|  | const af_array | in )

C Interface to create a complex array from a single real array.

Parameters

  [out] | out | complex array
  [in] | in | real array

Returns
  AF_SUCCESS, if function returns successfully, else an af_err code is given

## ◆ af_cplx2()

af_err af_cplx2 | ( | af_array * | out,
|  | const af_array | real,
|  | const af_array | imag,
|  | const bool | batch )

C Interface to create a complex array from two real arrays.

Parameters

  [out] | out | complex array
  [in] | real | real array to be assigned as the real component of the returned complex array
  [in] | imag | real array to be assigned as the imaginary component of the returned complex array
  [in] | batch | batch mode

Returns
  AF_SUCCESS, if function returns successfully, else an af_err code is given

## ◆ complex() [1/4]

array complex | ( | const array & | in | ) |

C++ Interface to create a complex array from a single real array.

Parameters

  [in] | in | input array

Returns
  complex array

## ◆ complex() [2/4]

array complex | ( | const array & | real_,
|  | const array & | imag_ )

C++ Interface to create a complex array from two real arrays.

Parameters

  [in] | real_ | input array to be assigned as the real component of the returned complex array
  [in] | imag_ | input array to be assigned as the imaginary component of the returned complex array

Returns
  complex array

## ◆ complex() [3/4]

array complex | ( | const array & | real_,
|  | const double | imag_ )

C++ Interface to create a complex array from a single real array for the real component and a single scalar for each imaginary component.

Parameters

  [in] | real_ | input array to be assigned as the real component of the returned complex array
  [in] | imag_ | single scalar to be assigned as the imaginary component of each value of the returned complex array

Returns
  complex array

## ◆ complex() [4/4]

array complex | ( | const double | real_,
|  | const array & | imag_ )

C++ Interface to create a complex array from a single scalar for each real component and a single real array for the imaginary component.

Parameters

  [in] | real_ | single scalar to be assigned as the real component of each value of the returned complex array
  [in] | imag_ | input array to be assigned as the imaginary component of the returned complex array

Returns
  complex array