RunMat
GitHub

transpose — Transpose arrays by swapping the first two dimensions without complex conjugation.

B = transpose(A) swaps the first two dimensions of A without conjugating complex values. It is equivalent to MATLAB A.' and preserves trailing dimensions for N-D arrays.

Syntax

B = transpose(A)

Inputs

NameTypeRequiredDefaultDescription
AAnyYesInput scalar/array value.

Returns

NameTypeDescription
BAnyInput value with first two dimensions swapped.

Errors

IdentifierWhenMessage
RunMat:transpose:InvalidArgumentCall does not provide exactly one input argument.transpose: invalid argument
RunMat:transpose:InvalidInputInput type is unsupported for transpose.transpose: unsupported input type
RunMat:transpose:InternalRuntime cannot materialize transpose output.transpose: internal runtime failure

How transpose works

  • Works for scalars, vectors, matrices, and N-D arrays; only the first two axes are swapped.
  • Complex values are not conjugated. Use ctranspose/A' for conjugate transpose.
  • Logical, string, character, and cell arrays preserve their types and metadata.
  • Vectors become column or row matrices as needed (e.g., size(transpose(1:3)) == [3 1]).
  • Empty and singleton dimensions follow MATLAB's column-major semantics.

Does RunMat run transpose on the GPU?

When a gpuArray is provided, RunMat first asks the active Accel provider for a dedicated transpose kernel. The WGPU backend ships such a kernel today; other providers may supply their own implementation. If the hook is missing, RunMat gathers the data to the host, performs the transpose once, and re-uploads it so downstream GPU work continues without residency churn.

GPU memory and residency

No additional residency management is required. If the planner keeps your data on the GPU, transpose will honour that residency and either invoke a provider kernel or, in the worst case, perform a gather/transpose/upload round-trip automatically.

Examples

Transposing a numeric matrix to swap rows and columns

A = [1 2 3; 4 5 6];
B = transpose(A)

Expected output:

B =
     1     4
     2     5
     3     6

Turning a row vector into a column vector

row = 1:4;
col = transpose(row);
size(col)

Expected output:

ans = [4 1]

Preserving imaginary parts when transposing complex matrices

Z = [1+2i 3-4i];
ZT = transpose(Z)

Expected output:

ZT =
     1.0000 + 2.0000i
     3.0000 - 4.0000i

Transposing logical masks while keeping logical type

mask = logical([1 0 1; 0 1 0]);
maskT = transpose(mask);
class(maskT)

Expected output:

ans = 'logical'

Transposing character arrays to flip rows and columns of text

C = ['r' 'u' 'n'; 'm' 'a' 't'];
CT = transpose(C)

Expected output:

CT =
    'rm'
    'ua'
    'nt'

Transposing gpuArray data without leaving the device

G = gpuArray(rand(1024, 32));
GT = transpose(G);
isgpuarray(GT)

Expected output:

ans = logical 1

Using transpose with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how transpose changes the result.

Run a small transpose example, explain the result, then change one input and compare the output.

FAQ

Does transpose conjugate complex numbers?

No. Use ctranspose or the ' operator for conjugate transpose.

What happens for tensors with more than two dimensions?

Only the first two axes are swapped; higher dimensions remain in-place.

Do empty matrices stay empty after transposition?

Yes. MATLAB's empty-dimension rules are preserved exactly.

Is the result a copy or a view?

It is a new array. Neither the input nor the output share storage.

Can I transpose cell arrays?

Yes—RunMat mirrors MATLAB by rearranging each cell handle into the new layout.

Are logical arrays still logical after transpose?

Absolutely. The data stay in compact logical storage.

How does transpose interact with the fusion planner?

Fusion treats transposes as pipeline boundaries, so kernels before and after the transpose can still fuse independently.

What if my provider lacks a transpose kernel?

RunMat transparently gathers, transposes on the host, and re-uploads while logging a warning.

Does transpose change sparse matrices?

Sparse support is planned; current releases operate on dense arrays.

Can I compose transpose with permute?

Yes—transpose is equivalent to permute(A, [2 1 3 ...]).

Factor

chol · eig · lu · qr · svd

Solve

cond · det · inv · linsolve · norm · pinv · rank · rcond · rref

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how transpose is executed, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.