A high-performance general-purpose compute library

- Main Page
- Tutorials
- Release Notes
- Examples

Functions
moddims
ArrayFire Functions | ArrayFire Functions by Category » Functions to create and modify Arrays » Move and Reorder array content

## Functions
AFAPI array | moddims (const array &in, const dim4 &dims)
| C++ Interface to modify the dimensions of an input array to a specified shape.
AFAPI array | moddims (const array &in, const dim_t d0, const dim_t d1=1, const dim_t d2=1, const dim_t d3=1)
| C++ Interface to modify the dimensions of an input array to a specified shape.
AFAPI array | moddims (const array &in, const unsigned ndims, const dim_t *const dims)
| C++ Interface to modify the dimensions of an input array to a specified shape.
AFAPI af_err | af_moddims (af_array *out, const af_array in, const unsigned ndims, const dim_t *const dims)
| C Interface to modify the dimensions of an input array to a specified shape.

## Detailed Description

Modify the dimensions of an array without changing the order of its elements.

This function only modifies array metadata and requires no computation. It is a NOOP.

Examples:

// Create a, a 2x3 array
array a = iota(dim4(2, 3)); // a = [0, 2, 4,
// 1, 3, 5]
// Create b by modifying the dimensions of a to the shape described by a dim4 object
array b = moddims(a, dim4(3, 2)); // b = [0, 3,
// 1, 4,
// 2, 5]
// Create c by modifying the dimensions of a to the shape described by dimension length parameters
array c = moddims(a, 3, 2); // c = [0, 3,
// 1, 4,
// 2, 5]
// Create d by modifying the dimensions of a to the shape described by an array of ndims dimensions
vector<dim_t> x{3, 2};
array d = moddims(a, 2, x.data()); // d = [0, 3,
// 1, 4,
// 2, 5]

## Function Documentation

## ◆ af_moddims()

AFAPI af_err af_moddims | ( | af_array * | out,
|  | const af_array | in,
|  | const unsigned | ndims,
|  | const dim_t *const | dims )

C Interface to modify the dimensions of an input array to a specified shape.

Parameters

  [out] | out | modded output
  [in] | in | input array
  [in] | ndims | number of dimensions
  [in] | dims | new dimension sizes

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

## ◆ moddims() [1/3]

AFAPI array moddims | ( | const array & | in,
|  | const dim4 & | dims )

C++ Interface to modify the dimensions of an input array to a specified shape.

Parameters

  [in] | in | input array
  [in] | dims | new dimension sizes

Returns
  modded output

## ◆ moddims() [2/3]

AFAPI array moddims | ( | const array & | in,
|  | const dim_t | d0,
|  | const dim_t | d1 = 1,
|  | const dim_t | d2 = 1,
|  | const dim_t | d3 = 1 )

C++ Interface to modify the dimensions of an input array to a specified shape.

Parameters

  [in] | in | input array
  [in] | d0 | new size of the first dimension
  [in] | d1 | new size of the second dimension (optional)
  [in] | d2 | new size of the third dimension (optional)
  [in] | d3 | new size of the fourth dimension (optional)

Returns
  modded output

## ◆ moddims() [3/3]

AFAPI array moddims | ( | const array & | in,
|  | const unsigned | ndims,
|  | const dim_t *const | dims )

C++ Interface to modify the dimensions of an input array to a specified shape.

Parameters

  [in] | in | input array
  [in] | ndims | number of dimensions
  [in] | dims | new dimension sizes

Returns
  modded output