RunMat
GitHub

ctranspose — Swap the first two dimensions of arrays and conjugate complex values.

B = ctranspose(A) (or B = A') flips the first two dimensions of A **and** conjugates complex values. Real-valued inputs therefore behave like transpose, while complex inputs receive Hermitian conjugation.

How ctranspose works in RunMat

  • Works for scalars, vectors, matrices, and N-D arrays; only the first two axes are swapped.
  • Real numeric, logical, and character data are not changed by conjugation.
  • Complex values receive element-wise conjugation after the transpose ((a + bi)' = a - bi).
  • Character arrays and cell arrays preserve their types; ctranspose simply rearranges entries.
  • String scalars are passed through unchanged; string arrays transpose like MATLAB.
  • Empty arrays and singleton dimensions follow MATLAB's column-major semantics.

How ctranspose runs on the GPU

**Provider support:** If the backend exposes both transpose (or permute) and unary_conj, the entire operation happens on the device without a gather.

**Partial hooks:** If the transpose succeeds but conjugation fails, RunMat falls back to the host path while logging a warning so users know their backend is incomplete.

**No hooks:** RunMat gathers the tensor, applies the conjugate transpose on the CPU, and re-uploads the result when possible so downstream kernels can keep running on the GPU.

Current providers operate on real double-precision tensors; complex GPU tensors will gather to the host until native complex layouts are implemented.

GPU memory and residency

No additional residency management is required. If the planner keeps your data on the GPU, ctranspose honours that residency and either executes on the device (when hooks are present) or performs a gather/transpose/upload round-trip automatically.

Examples

Conjugate transpose of a complex matrix

Z = [1+2i 3-4i; 5+0i 6-7i];
H = ctranspose(Z)

Expected output:

H =
   1 - 2i   5 - 0i
   3 + 4i   6 + 7i

Conjugate transpose of a real matrix equals the plain transpose

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

Expected output:

B =
     1     4
     2     5
     3     6

Conjugate transpose turns row vectors into column vectors

row = [1-2i, 3+4i, 5];
col = ctranspose(row);
size(col)

Expected output:

ans = [3 1]

Conjugate transpose of a complex scalar

z = 2 + 3i;
result = ctranspose(z)

Expected output:

result = 2 - 3i

Conjugate transpose of text data preserves characters

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

Expected output:

CT =
    'rm'
    'ua'
    'nt'

Conjugate transpose of a gpuArray without leaving the device

G = gpuArray(rand(1024, 64) + 1i * rand(1024, 64));
GT = ctranspose(G)

FAQ

How is ctranspose different from transpose?

transpose (A.') swaps dimensions without conjugation; ctranspose (A') also conjugates complex values. For purely real data they are identical.

Does ctranspose change logical or character arrays?

Only their layout changes. Values remain logical or character, and conjugation has no effect.

What about higher-dimensional arrays?

Only the first two axes are swapped; trailing dimensions stay in-place, matching MATLAB.

Does the result share storage with the input?

No. ctranspose materialises a fresh array, although fusion may eliminate the copy in optimised pipelines.

How are complex tensors handled on the GPU today?

Complex gpuArray support is still in flight. When complex data appears, RunMat gathers to the host, applies the conjugate transpose, and re-uploads if needed.

Will ctranspose fuse with neighbouring kernels?

Conjugate transposes currently act as fusion boundaries so that shape changes are visible to downstream kernels.

Can I rely on ctranspose inside linear-algebra routines (e.g., Hermitian products)?

Yes. The builtin mirrors MATLAB semantics precisely and is safe to use inside idioms like A' * A.

What error do I get for unsupported types?

Non-numeric objects (e.g., structs) raise ctranspose: unsupported input type ..., matching MATLAB's strict type checks.

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

transpose, conj, mtimes, gpuArray, gather, dot, mldivide, mpower, mrdivide, trace

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how ctranspose 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.