ctranspose — Conjugate-transpose arrays in MATLAB and RunMat.
B = ctranspose(A) (or A') swaps the first two dimensions of A and conjugates complex values. Real-valued inputs therefore behave like simple transpose, with MATLAB/RunMat Hermitian semantics for complex data.
Syntax
B = ctranspose(A)Inputs
A- Type
Any- Required
- Yes
- Description
- Input scalar/array value.
Returns
B- Type
Any- Description
- Input value with first two dimensions swapped and complex conjugated.
Errors
RunMat:ctranspose:InvalidArgument- When
- Call does not provide exactly one input argument.
- Message
ctranspose: invalid argument
RunMat:ctranspose:InvalidInput- When
- Input type is unsupported for conjugate transpose, the input has a nonsingleton dimension above two, or the input uses complex integer storage.
- Message
ctranspose: unsupported input type
RunMat:ctranspose:Internal- When
- Runtime cannot materialize conjugate-transpose output.
- Message
ctranspose: internal runtime failure
Behavior and supported arrays
B = ctranspose(A) (or A') swaps the first two dimensions and conjugates complex values. Real-valued input behaves like simple transpose. Scalars, vectors, matrices, and explicit trailing singleton dimensions are supported; N-D arrays with a nonsingleton dimension above two are rejected in favor of permute.
Real numeric, logical, and character entries are unchanged by conjugation. Complex single and double entries are conjugated and remain complex even when every imaginary component is zero. Complex integer storage is rejected. Empty arrays use column-major transpose semantics.
Dense real integer input retains all eight integer classes. Integer-valued sparse storage requires the ctranspose-integer-sparse RunMat extension. Character and cell arrays retain their types while entries move to transposed positions. String scalars pass through and string arrays transpose. Scalar structs are unchanged; struct arrays transpose. External objects may provide their own ctranspose method.
GPU residency and provider behavior
Real and complex provider-resident tensors use the exact provider's transpose or permute operation and, for complex input, its unary_conj hook when available. Single and double are the supported floating precisions; no broadcast or reduction is performed.
When a required hook is unavailable, RunMat gathers to host, conjugate-transposes, and attempts to re-upload. The result may remain on host if re-upload is unavailable. Complex fallback preserves interleaved storage metadata when the result remains complex. A partial transpose/conjugation hook failure selects the host fallback and emits a warning. The operation is a fusion boundary so downstream kernels see the new shape.
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 + 7iConjugate 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 6Conjugate 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 - 3iConjugate 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
G = gpuArray(rand(1024, 64) + 1i * rand(1024, 64));
GT = ctranspose(G)Using ctranspose with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how ctranspose changes the result.
Run a small ctranspose example, explain the result, then change one input and compare the output.
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?⌄
Use permute for higher-dimensional arrays. ctranspose accepts vectors and matrices, including explicit trailing singleton dimensions, and rejects nonsingleton dimensions above two.
Does the result share storage with the input?⌄
An array transpose usually materializes a new arrangement. A provider may return a lazy view or alias for an identity-shaped result, so storage independence is not guaranteed; value semantics remain unchanged.
How are complex tensors handled on the GPU today?⌄
Complex gpuArray values use interleaved real/imaginary storage. Providers with transpose/permute and unary_conj hooks keep the conjugate transpose resident; fallback gathers and attempts to re-upload through the same complex storage metadata.
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 for the supported numeric, logical, character, string, cell, scalar-struct, sparse, and resident array forms described above. On those inputs it preserves the conjugate-transpose semantics required by idioms such as A' * A.
What error do I get for unsupported types?⌄
Supported scalar structs are unchanged by transpose. Unsupported value kinds raise ctranspose: unsupported input type ...; external objects can provide their own ctranspose method.
Related Linalg functions
Ops
cross · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose
Structure
bandwidth · isdiag · ishermitian · issymmetric · istril · istriu · symrcm
Factor
chol · decomposition · decomposition.ctranspose · decomposition.mldivide · decomposition.mrdivide · decomposition.mtimes · decomposition.rdivide · decomposition.subsref · decomposition.times · decomposition.uminus · decomposition.uplus · eig · eigs · gmres · ichol · ilu · lu · ordeig · ordqz · ordschur · pcg · qr · qz · rsf2csf · schur · svd
Source you can read
Every RunMat function's source is public. Read exactly how ctranspose is executed, line by line, in Rust.
- View the source for ctranspose in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.