Main Content

eye

Identity matrix

Syntax

E =眼睛(深圳,arraytype)
E =眼睛(深圳,datatype,arraytype)

E =眼睛(深圳,'like',P)
E =眼睛(深圳,datatype,'like',P)

C = eye(sz,codist)
C = eye(sz,datatype,codist)
C = eye(sz,___,codist,'noCommunication')
C = eye(sz,___,codist,'like',P)

Description

E =眼睛(深圳,arraytype)creates anarraytypeidentity matrix with underlying class of double, with ones on the main diagonal and zeros elsewhere.

E =眼睛(深圳,datatype,arraytype)creates anarraytypeidentity matrix with underlying class ofdatatype, with ones on the main diagonal and zeros elsewhere.

The size and type of array are specified by the argument options according to the following table.

Argument Values Descriptions
sz n Specifies array size as ann-by-nmatrix.
m,n Specifies array size as anm-by-nmatrix.
[m n]
arraytype 'distributed' Specifies distributed array.
'codistributed' Specifies codistributed array, using the default distribution scheme.
'gpuArray' Specifies gpuArray.
datatype 'double'(default),'single','int8',“uint8”,'int16','uint16','int32','uint32','int64', or'uint64' Specifies underlying class of the array, i.e., the data type of its elements.

E =眼睛(深圳,'like',P)creates an identity matrix of the same type and underlying class (data type) as arrayP.

E =眼睛(深圳,datatype,'like',P)creates an identity matrix of the specified underlying class (datatype), and the same type as arrayP.

C = eye(sz,codist)orC = eye(sz,datatype,codist)creates a codistributed identity matrix of the specified size and underlying class (the defaultdatatypeis'double'). The codistributor object,codist, specifies the distribution scheme for creating the codistributed array. For information on constructing codistributor objects, see the reference pages forcodistributor1dandcodistributor2dbc. To use the default distribution scheme, you can specify a codistributor constructor without arguments. For example:

spmd C = eye(8,codistributor1d()); end

C = eye(sz,___,codist,'noCommunication')没有指定交互影响通信n is to be performed when constructing a codistributed array, skipping some error checking steps.

C = eye(sz,___,codist,'like',P)creates a codistributed identity matrix with the specified size, underlying class (datatype), and distribution scheme. If either thedatatypeor codistributor argument is omitted, the characteristic is acquired from the codistributed arrayP.

Examples

Create Distributed Identity Matrix

Create a 1000-by-1000 distributed identity matrix of underlying class double:

D = eye(1000,'distributed');

Create Codistributed Identity Matrix

Create a 1000-by-1000 codistributed double identity matrix, distributed by its second dimension (columns).

spmd(4) C = eye(1000,'codistributed');end

With four workers, each worker contains a 1000-by-250 local piece ofC.

Create a 1000-by-1000 codistributeduint16identity matrix , distributed by its columns.

spmd(4) codist = codistributor('1d',2,100*[1:numlabs]); C = eye(1000,1000,'uint16',codist);end

Each worker contains a 100-by-labindexlocal piece ofC.

Create gpuArray Identity Matrix

Create a 1000-by-1000 gpuArray identity matrix of underlying classuint32:

G = eye(1000,'uint32','gpuArray');
Introduced in R2006b