transpose
Function
Transposing a matrix exchanges its rows and columns.
Compare examples
Compare the column-major input with the displayed output. Off-diagonal entries exchange positions.
Example 1M = [[1,5,9,13],[2,6,10,14],[3,7,11,15],[4,8,12,16]]
12345678910111213141516 - Result
transpose(M) = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]
Example 2M = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]
1000010000100001 - Result
transpose(M) = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]
Example 3M = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
0000000000000000 - Result
transpose(M) = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
The examples are calculation models and do not run GPU work. The reference below gives the complete call signatures. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.
When to use it
Use it to change between row and column views of a linear map.
Inputs and limits
A transpose is not a matrix inverse. This model uses a square matrix; a rectangular transpose also swaps the matrix dimensions.
For shader input rules and precision, consult WGSL and GLSL ES 3.00.
Related functions
- WGSL
transpose(a)- GLSL ES 3.00
transpose(a)
The signature, the sentence and any message are the compiler's own text at commit af54ddad5.
Returns the transpose of a mat4.
Syntax
declare function transpose(m: mat2x2): mat2x2declare function transpose(m: mat2x3): mat3x2declare function transpose(m: mat2x4): mat4x2declare function transpose(m: mat3x2): mat2x3declare function transpose(m: mat3x3): mat3x3declare function transpose(m: mat3x4): mat4x3declare function transpose(m: mat4x2): mat2x4declare function transpose(m: mat4x3): mat3x4declare function transpose(m: mat4x4): mat4x4declare function transpose(m: mat2x2<f64>): mat2x2<f64>declare function transpose(m: mat3x3<f64>): mat3x3<f64>declare function transpose(m: mat4x4<f64>): mat4x4<f64>Parameters
Return value
mat2x2mat3x2mat4x2mat2x3mat3x3mat4x3mat2x4mat3x4mat4x4mat2x2<f64>mat3x3<f64>mat4x4<f64>
Targets
- WGSL
-
transpose(a) - GLSL ES 3.00
-
transpose(a)