identity

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

Create an identity array with diagonal values 1. More...

## Functions
AFAPI array | identity (const dim4 &dims, const dtype ty=f32)
AFAPI array | identity (const dim_t d0, const dtype ty=f32)
AFAPI array | identity (const dim_t d0, const dim_t d1, const dtype ty=f32)
AFAPI array | identity (const dim_t d0, const dim_t d1, const dim_t d2, const dtype ty=f32)
AFAPI array | identity (const dim_t d0, const dim_t d1, const dim_t d2, const dim_t d3, const dtype ty=f32)
AFAPI af_err | af_identity (af_array *out, const unsigned ndims, const dim_t *const dims, const af_dtype type)

## Detailed Description

Create an identity array with diagonal values 1.

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
| ) |  |

Parameters

  [out] | out | is the generated array
  [in] | ndims | is size of dimension array `dims`
  [in] | dims | is the array containing sizes of the dimension
  [in] | type | is the type of array to generate

## ◆ identity() [1/5]

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

Parameters

  [in] | dims | is dim4 for size of all dimensions
  [in] | ty | is the type of array to generate

Returns
  an identity array of specified dimension and type

Examples:
  benchmarks/cg.cpp, and lin_algebra/cholesky.cpp.

## ◆ identity() [2/5]

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

Parameters

  [in] | d0 | is size of first dimension
  [in] | ty | is the type of array to generate

Returns
  an identity array of specified dimension and type

## ◆ identity() [3/5]

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

Parameters

  [in] | d0 | is size of first dimension
  [in] | d1 | is size of second dimension
  [in] | ty | is the type of array to generate

Returns
  an identity array of specified dimension and type

## ◆ identity() [4/5]

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

Parameters

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

Returns
  an identity array of specified dimension and type

## ◆ identity() [5/5]

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

Parameters

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

Returns
  an identity array of specified dimension and type