A high-performance general-purpose compute library

- Main Page
- Tutorials
- Release Notes
- Examples

Functions
identity
ArrayFire Functions | ArrayFire Functions by Category » Functions to create and modify Arrays » Functions to create arrays.

## Functions
AFAPI array | identity (const dim4 &dims, const dtype ty=f32)
| C++ Interface to generate an identity array.
AFAPI array | identity (const dim_t d0, const dtype ty=f32)
| C++ Interface to generate a 1-D identity array.
AFAPI array | identity (const dim_t d0, const dim_t d1, const dtype ty=f32)
| C++ Interface to generate a 2-D identity array.
AFAPI array | identity (const dim_t d0, const dim_t d1, const dim_t d2, const dtype ty=f32)
| C++ Interface to generate a 3-D identity array.
AFAPI array | identity (const dim_t d0, const dim_t d1, const dim_t d2, const dim_t d3, const dtype ty=f32)
| C++ Interface to generate a 4-D identity array.
AFAPI af_err | af_identity (af_array *out, const unsigned ndims, const dim_t *const dims, const af_dtype type)
| C Interface to generate an identity array.

## Detailed Description

Generate an identity matrix.

array a = identity(5, 3);
// a [5 3 1 1]
// 1.0000 0.0000 0.0000
// 0.0000 1.0000 0.0000
// 0.0000 0.0000 1.0000
// 0.0000 0.0000 0.0000
// 0.0000 0.0000 0.0000

## Function Documentation

## ◆ af_identity()

AFAPI af_err af_identity | ( | af_array * | out,
|  | const unsigned | ndims,
|  | const dim_t *const | dims,
|  | const af_dtype | type )

C Interface to generate an identity array.

Parameters

  [out] | out | identity array
  [in] | ndims | number of dimensions
  [in] | dims | size
  [in] | type | type

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

## ◆ identity() [1/5]

AFAPI array identity | ( | const dim4 & | dims,
|  | const dtype | ty = f32 )

C++ Interface to generate an identity array.

Parameters

  [in] | dims | size
  [in] | ty | type

Returns
  identity array

## ◆ identity() [2/5]

AFAPI array identity | ( | const dim_t | d0,
|  | const dim_t | d1,
|  | const dim_t | d2,
|  | const dim_t | d3,
|  | const dtype | ty = f32 )

C++ Interface to generate a 4-D identity array.

Parameters

  [in] | d0 | size of the first dimension
  [in] | d1 | size of the second dimension
  [in] | d2 | size of the third dimension
  [in] | d3 | size of the fourth dimension
  [in] | ty | type

Returns
  identity array

## ◆ identity() [3/5]

AFAPI array identity | ( | const dim_t | d0,
|  | const dim_t | d1,
|  | const dim_t | d2,
|  | const dtype | ty = f32 )

C++ Interface to generate a 3-D identity array.

Parameters

  [in] | d0 | size of the first dimension
  [in] | d1 | size of the second dimension
  [in] | d2 | size of the third dimension
  [in] | ty | type

Returns
  identity array

## ◆ identity() [4/5]

AFAPI array identity | ( | const dim_t | d0,
|  | const dim_t | d1,
|  | const dtype | ty = f32 )

C++ Interface to generate a 2-D identity array.

Parameters

  [in] | d0 | size of the first dimension
  [in] | d1 | size of the second dimension
  [in] | ty | type

Returns
  identity array

## ◆ identity() [5/5]

AFAPI array identity | ( | const dim_t | d0,
|  | const dtype | ty = f32 )

C++ Interface to generate a 1-D identity array.

Parameters

  [in] | d0 | size of the first dimension
  [in] | ty | type

Returns
  identity array