dot — Compute dot products in MATLAB and RunMat.
dot(A, B) evaluates inner products between matching slices of A and B, optionally along a selected dimension. Complex inputs use conjugate-on-first-argument semantics consistent with MATLAB and RunMat.
Syntax
C = dot(A, B)
C = dot(A, B, dim)Inputs
A- Type
Any- Required
- Yes
- Description
- Left operand.
B- Type
Any- Required
- Yes
- Description
- Right operand.
dim- Type
NumericScalar- Required
- Yes
- Description
- Reduction dimension.
Returns
C- Type
NumericArray- Description
- Dot product result.
Errors
RunMat:dot:InvalidArgument- When
- Argument count or dimension argument is invalid.
- Message
dot: invalid argument
RunMat:dot:InvalidInput- When
- Inputs are unsupported or incompatible.
- Message
dot: A and B must be the same size.
RunMat:dot:Internal- When
- Runtime cannot materialize dot outputs.
- Message
dot: internal runtime failure
Behavior and supported arrays
dot(A, B) evaluates inner products between matching slices of A and B, optionally along a selected dimension. Complex inputs use conjugate-on-first-argument semantics consistent with MATLAB and RunMat.
Vectors need the same number of elements and may use different row/column orientations. Matrices and N-D arrays must have identical sizes.
When no dimension is supplied, the function reduces along the first non-singleton dimension (dim = 1 when all dimensions are singleton).
dot(A, B, dim) collapses dimension dim (1-based) while leaving every other dimension untouched.
Complex inputs conjugate the first argument before multiplication; real inputs use a straight element-wise product.
Single inputs produce single results, including on the host/fallback path; otherwise the floating result is double.
Empty reductions yield zeros of the appropriate shape; length mismatches raise A and B must be the same size.
Public MATLAB data inputs are single or double. RunMat additionally accepts logical and all eight typed-integer classes only in RunMat extension mode.
When both extension operands are typed integers, each product is formed from authoritative integer storage before crossing to the floating reduction/output domain, avoiding pre-product loss above flintmax.
Typed-integer dim is a documented control input, is available in compatibility modes, and is decoded exactly in every supported integer class.
GPU residency and provider behavior
Same-owner, same-device real floating inputs can use the owning provider's native dot hook. Other supported resident forms gather through the originating owner and restore real results there when its precision can represent the output. Complex outputs remain host-side until provider complex dot support is available.
Native dispatch never sends integer or logical storage to a floating dot hook. It requires proven common ownership/device and accepts a fresh result only after owner, device, shape, real noninteger storage, and operand-requested precision validation. A malformed native result is rejected without replay; only a typed unsupported-hook result permits host fallback. Global-provider fallback for an unknown device is not accepted as ownership. Outputs that alias either input or the fallback residency anchor are rejected and never freed as provider-owned results. Other rejected allocations are freed only through a proven actual owner. Fallback gathers through each handle owner and restores real output to the first resident owner only after applying the same owner, device, shape, storage, class-metadata, freshness, and requested-precision checks.
The provider-side hook is limited to proven-same-owner, same-device real floating inputs. Integer/logical extensions gather through the owning provider and bypass floating-native hooks; operational provider failures and malformed native outputs remain terminal.
Examples
Computing the dot product of row vectors
A = [1 2 3];
B = [4 5 6];
val = dot(A, B)Expected output:
val = 32Dotting column vectors to obtain a scalar
u = [1; 3; 5];
v = [2; 4; 6];
val = dot(u, v)Expected output:
val = 44Applying dot along a chosen dimension
X = [1 2 3; 4 5 6];
Y = [6 5 4; 3 2 1];
cols = dot(X, Y, 1) % collapse rows
rows = dot(X, Y, 2) % collapse columnsExpected output:
cols = [18 20 18];
rows = [28; 28]Dotting complex vectors uses conjugation on the first input
a = [1+2i, 3-4i];
b = [2-3i, -1+5i];
val = dot(a, b)Expected output:
val = -27 + 4iEvaluating dot on gpuArray inputs
G1 = gpuArray([1 2 3 4]);
G2 = gpuArray([4 3 2 1]);
G = dot(G1, G2);
result = gather(G)Expected output:
result = 20Using dot with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how dot changes the result.
Run a small dot example, explain the result, then change one input and compare the output.
FAQ
Does dot require vectors?⌄
No. Any pair of tensors with identical sizes works; specifying a dimension lets you dot slices of higher-dimensional arrays.
How does the optional dimension behave?⌄
dot(A, B, dim) collapses the dimth dimension (1-based). Dimensions greater than the array rank have length 1 and therefore leave the data unchanged.
What happens with complex numbers?⌄
The first input is conjugated before multiplication so the result matches MATLAB's hermitian inner product.
Are empty inputs supported?⌄
Yes. If the reduction dimension has length 0 the result is filled with zeros of the appropriate shape.
Will the result stay on the GPU?⌄
When a provider is active the runtime uploads real-valued results back to the device. Complex outputs stay on the host until GPU complex support is available.
What error is raised for size mismatches?⌄
When A and B differ in size dot raises: A and B must be the same size. matching MATLAB's wording.
Does dot accept logical or integer inputs?⌄
Only as explicit RunMat extensions. Current public MATLAB documentation lists single and double data inputs. RunMat mode accepts logical and all eight integer classes; compatibility modes reject those data forms. Typed-integer dim remains documented and available.
Can I request conjugation of the second argument instead?⌄
No. MATLAB's dot is fixed to conjugate the first argument. Use sum(A .* conj(B)) manually if you need the opposite orientation.
Related Linalg functions
Ops
cross · ctranspose · 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 dot is executed, line by line, in Rust.
- View the source for dot 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.