---
title: "transpose: WGSL and GLSL examples, uses and input limits"
description: "Transposing a matrix exchanges its rows and columns. Use it to change between row and column views of a linear map. A transpose is not a matrix inverse."
url: https://typeshade.dev/reference/functions/transpose/
language: en
---

# `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 1`M = [[1,5,9,13],[2,6,10,14],[3,7,11,15],[4,8,12,16]]`**

`1` `2` `3` `4` `5` `6` `7` `8` `9` `10` `11` `12` `13` `14` `15` `16`

Matrix displayed by rows. Constructor arguments run down each column.

**Result**

`transpose(M) = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]`

**Example 2`M = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]`**

`1` `0` `0` `0` `0` `1` `0` `0` `0` `0` `1` `0` `0` `0` `0` `1`

Matrix displayed by rows. Constructor arguments run down each column.

**Result**

`transpose(M) = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]`

**Example 3`M = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]`**

`0` `0` `0` `0` `0` `0` `0` `0` `0` `0` `0` `0` `0` `0` `0` `0`

Matrix displayed by rows. Constructor arguments run down each column.

**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](https://www.w3.org/TR/WGSL/) and [GLSL ES 3.00](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf).

## Related functions

- [`mat4`](https://typeshade.dev/reference/functions/mat4/)
- [`determinant`](https://typeshade.dev/reference/functions/determinant/)

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

```ts
declare function transpose(m: mat2x2): mat2x2
declare function transpose(m: mat2x3): mat3x2
declare function transpose(m: mat2x4): mat4x2
declare function transpose(m: mat3x2): mat2x3
declare function transpose(m: mat3x3): mat3x3
declare function transpose(m: mat3x4): mat4x3
declare function transpose(m: mat4x2): mat2x4
declare function transpose(m: mat4x3): mat3x4
declare function transpose(m: mat4x4): mat4x4
declare function transpose(m: mat2x2<f64>): mat2x2<f64>
declare function transpose(m: mat3x3<f64>): mat3x3<f64>
declare function transpose(m: mat4x4<f64>): mat4x4<f64>
```

## Parameters

- `m` `mat2x2``mat2x3``mat2x4``mat3x2``mat3x3``mat3x4``mat4x2``mat4x3``mat4x4``mat2x2<f64>``mat3x3<f64>``mat4x4<f64>`

## Return value

`mat2x2``mat3x2``mat4x2``mat2x3``mat3x3``mat4x3``mat2x4``mat3x4``mat4x4``mat2x2<f64>``mat3x3<f64>``mat4x4<f64>`

## Targets

**WGSL**

`transpose(a)`

**GLSL ES 3.00**

`transpose(a)`

## Examples

- [`gallery/bit-bump/bit-bump.shade.ts`](https://typeshade.dev/guide/examples/bit-bump/)
- [`gallery/normal-matrix/normal-matrix.shade.ts`](https://typeshade.dev/guide/examples/normal-matrix/)

## See also

- [Functions](https://typeshade.dev/reference/functions/)
- [Builtin table](https://typeshade.dev/guide/language/builtins/#geometry)
