-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
140 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
{ | ||
"className": "ut.ndim.Tensor_Permute_Spec", | ||
"title": "Reshaping Tensors", | ||
"narrative": "Permuting an N-dimensional array means rearranging the dimensions/axes of the N-dimensional array. \nIt produces a new tensor with the same data as the original tensor, \nbut with the specified dimensions rearranged. \n \nThis is very useful for example when you want to \nchange the order of dimensions, for example, if you have a tensor with dimensions (batch_size, channels, height, width), \nyou can use permute() to rearrange the dimensions to (batch_size, height, width, channels). \nAnother useful application of permute() is transposing a matrix. \nFor example, if you have a matrix with dimensions (rows, columns), \nyou can use permute() to rearrange the dimensions to (columns, rows). \n \nPermuting is a very cheap operation because it does not copy any data but merely \ncreates a new view on the same data with a different access pattern.", | ||
"subjects": ["neureka.Tensor"], | ||
"statistics": { | ||
"runs": "2", | ||
"successRate": "100.0%", | ||
"failures": "0", | ||
"errors": "0", | ||
"skipped": "0", | ||
"duration": "0.003 seconds" | ||
}, | ||
"headers": [], | ||
"tags": {}, | ||
"see": [], | ||
"features": [ | ||
{ | ||
"id": "We can use the \"permute\" method to rearrange the dimensions of a tensor.", | ||
"result": "PASS", | ||
"duration": "0.002 seconds", | ||
"iterations": { | ||
"tags": {}, | ||
"see": [], | ||
"extraInfo": [ | ||
"\n In Neureka `Tensor::permute(int...)` rearranges the original tensor according to the desired \n ordering and returns a new multidimensional rotated tensor. \n The size of the returned tensor remains the same as that of the original.\n " | ||
] | ||
}, | ||
"blocks": [ | ||
{ | ||
"kind": "given", | ||
"text": "A tensor with a shape of [2, 4, 6, 8]", | ||
"code": [ | ||
"Tensor t = Tensor.ofFloats().withShape(2, 4, 6, 8).andSeed(42)" | ||
] | ||
}, | ||
|
||
{ | ||
"kind": "expect", | ||
"text": "By default, the tensor has a row major layout.", | ||
"code": [ | ||
"t.NDConf.layout == NDConfiguration.Layout.ROW_MAJOR", | ||
"t.NDConf.traits == [NDTrait.COMPACT, NDTrait.SIMPLE, NDTrait.ROW_MAJOR, NDTrait.CONTINUOUS_MATRIX]" | ||
] | ||
}, | ||
|
||
{ | ||
"kind": "when", | ||
"text": "We create a new permuted tensor with the shape of [6, 4, 8, 2] and store it as `t2`.", | ||
"code": ["var t2 = t.permute( 2, 1, 3, 0 )"] | ||
}, | ||
|
||
{ | ||
"kind": "then", | ||
"text": "The new tensor has the shape of [6, 4, 8, 2].", | ||
"code": ["t2.shape == [6, 4, 8, 2]"] | ||
}, | ||
|
||
{ | ||
"kind": "and", | ||
"text": "A unspecific layout is assigned to the new tensor.", | ||
"code": [ | ||
"t2.NDConf.layout == NDConfiguration.Layout.UNSPECIFIC", | ||
"t2.NDConf.traits == [NDTrait.COMPACT, NDTrait.COL_MAJOR, NDTrait.CONTINUOUS_MATRIX]" | ||
] | ||
}, | ||
|
||
{ | ||
"kind": "and", | ||
"text": "The new tensor has the same size as the original tensor, but it is not the same object.", | ||
"code": ["t2.size == t.size", "t2 !== t"] | ||
} | ||
], | ||
"problems": { "dataValues": [], "errors": [] } | ||
}, | ||
|
||
{ | ||
"id": "When matrices are transpose, they will change their layout type as expected.", | ||
"result": "PASS", | ||
"duration": "0", | ||
"iterations": { | ||
"tags": {}, | ||
"see": [], | ||
"extraInfo": [] | ||
}, | ||
"blocks": [ | ||
{ | ||
"kind": "given", | ||
"text": "", | ||
"code": [ | ||
"Tensor t = Tensor.ofFloats().withShape(3, 4).andSeed(42)" | ||
] | ||
}, | ||
|
||
{ | ||
"kind": "expect", | ||
"text": "", | ||
"code": [ | ||
"t.NDConf.layout == NDConfiguration.Layout.ROW_MAJOR", | ||
"t.NDConf.traits == [NDTrait.COMPACT, NDTrait.SIMPLE, NDTrait.ROW_MAJOR, NDTrait.CONTINUOUS_MATRIX]" | ||
] | ||
}, | ||
|
||
{ "kind": "when", "text": "", "code": ["t = t.T"] }, | ||
|
||
{ | ||
"kind": "then", | ||
"text": "", | ||
"code": [ | ||
"t.NDConf.layout == NDConfiguration.Layout.COLUMN_MAJOR", | ||
"t.NDConf.traits == [NDTrait.COMPACT, NDTrait.COL_MAJOR, NDTrait.CONTINUOUS_MATRIX]" | ||
] | ||
} | ||
], | ||
"problems": { "dataValues": [], "errors": [] } | ||
} | ||
], | ||
"generator": "https://github.com/renatoathaydes/spock-reports" | ||
} |