RunMat
GitHub

exp — Compute element-wise exponential values in MATLAB and RunMat.

Y = exp(X) raises *e* to each element of X. Real and complex inputs are handled element-wise under MATLAB semantics.

Syntax

Y = exp(X)

Inputs

NameTypeRequiredDefaultDescription
XAnyYesNumeric, logical, char, or complex input.

Returns

NameTypeDescription
YNumericArrayElementwise exponential result.

Errors

IdentifierWhenMessage
RunMat:exp:InvalidInputInput cannot be interpreted as numeric, logical, char, or complex data.exp: invalid input
RunMat:exp:InternalInternal tensor construction or provider interaction failed.exp: internal error

How exp works

  • exp(X) applies the exponential element-by-element with MATLAB broadcasting rules.
  • Logical inputs convert to double (true → 1.0, false → 0.0) before exponentiation.
  • Character arrays are treated as their numeric code points and return dense double tensors.
  • Complex values follow MATLAB's definition: exp(a + bi) = exp(a) * (cos(b) + i·sin(b)).
  • Inputs already living on the GPU stay there when the provider implements unary_exp; otherwise RunMat gathers the data, computes on the host, and returns the correct residency.

Does RunMat run exp on the GPU?

RunMat Accelerate keeps GPU tensors resident whenever the selected provider implements unary_exp. When the hook is missing or returns an error, RunMat automatically gathers the tensor, computes on the CPU, and re-wraps the result, ensuring correctness without surprising users.

GPU memory and residency

You typically do not need to call gpuArray manually in RunMat. The acceleration planner and fusion engine keep tensors on the GPU automatically when profitable. Users can still call gpuArray for explicit residency or to mirror MathWorks MATLAB workflows.

Examples

Calculate the exponential of a scalar value

y = exp(1)

Expected output:

y = 2.7183

Apply the exponential function to a vector of growth rates

rates = [-1 -0.5 0 0.5 1];
factor = exp(rates)

Expected output:

factor = [0.3679 0.6065 1 1.6487 2.7183]

Exponentiate every element of a matrix

A = [0 1 2; 3 4 5];
B = exp(A)

Expected output:

B = [1.0000 2.7183 7.3891; 20.0855 54.5982 148.4132]

Compute the exponential of complex numbers

z = [1+2i, -1+pi*i];
w = exp(z)

Expected output:

w = [-1.1312 + 2.4717i, -0.3679 + 0.0000i]

Run element-wise exponential on GPU data

G = gpuArray([0 1; 2 3]);
out = exp(G);
result = gather(out)

Expected output:

result = [1.0000 2.7183; 7.3891 20.0855]

Convert character codes to exponentials

C = 'ABC';
Y = exp(C)

Expected output:

Y = [1.6949e+28 4.6072e+28 1.2524e+29]

Using exp with coding agents

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

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

FAQ

When should I use the exp function?

Use exp whenever you need the natural exponential of a value or array, such as modelling growth, discounting continuous compounding, or preparing inputs for activation functions.

Does exp preserve tensor shapes?

Yes. exp returns a tensor with the same shape as the input, applying broadcasting rules where applicable.

How are logical arrays handled?

Logical arrays convert to doubles before exponentiation, matching MATLAB behavior: exp([true false]) returns [e 1].

What about complex inputs?

Complex scalars and tensors use MATLAB's complex exponential formula, producing complex outputs.

What happens when the GPU provider lacks unary_exp?

RunMat automatically gathers the data to the host, computes the result, and returns a dense tensor. Future GPU operations can still fuse because residency metadata is updated accordingly.

Can I expect double precision?

Yes. RunMat stores dense numeric tensors as double precision (f64). Providers may internally use single precision when configured, but results are converted back to double.

Elementwise

abs · angle · complex · conj · double · expm1 · factorial · gamma · hypot · imag · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · sign · single · sqrt · times

Trigonometry

acos · acosh · asin · asinh · atan · atan2 · atanh · cos · cosd · cosh · deg2rad · rad2deg · sin · sind · sinh · tan · tand · tanh

Reduction

all · any · cummax · cummin · cumprod · cumsum · cumtrapz · diff · gradient · max · mean · median · min · nnz · prod · std · sum · trapz · var

Signal

blackman · butter · conv · conv2 · deconv · filter · hamming · hann · sawtooth · sinc · square

Rounding

ceil · fix · floor · mod · rem · round

Factor

chol · eig · lu · qr · svd

Solve

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

Fft

fft · fft2 · fftshift · ifft · ifft2 · ifftshift

Interpolation

interp1 · interp2 · pchip · ppval · spline

Ode

ode15s · ode23 · ode45

Open-source implementation

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