RunMat
GitHub

transpose — Swap the first two dimensions of arrays without taking the complex conjugate.

B = transpose(A) flips the first two dimensions of A without conjugating complex values. It is equivalent to the MATLAB syntax A.' and leaves higher dimensions untouched.

How transpose works in RunMat

  • 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.

How transpose runs 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

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 ...]).

These functions work well alongside transpose. Each page has runnable examples you can try in the browser.

ctranspose, permute, mtimes, gpuArray, gather, dot, mldivide, mpower, mrdivide, trace

Open-source implementation

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

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code — faster, on any GPU, with no license required.

  • Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
  • Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
  • A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.

Getting started · Benchmarks · Pricing

Try RunMat — free, no sign-up

Start running MATLAB code immediately in your browser.