RunMat
GitHub

logspace — Generate logarithmically spaced row vectors in MATLAB and RunMat.

logspace(a, b, n) returns n points spaced logarithmically between 10^a and 10^b. Default point count and row-vector output behavior follow MATLAB semantics.

Syntax

x = logspace(start, stop)
x = logspace(start, stop, n)

Inputs

NameTypeRequiredDefaultDescription
startNumericScalarYesStarting exponent value.
stopNumericScalarYesEnding exponent value.
nIntegerScalarNo50Number of points.

Returns

NameTypeDescription
xNumericArrayRow vector of logarithmically spaced values.

Errors

IdentifierWhenMessage
More than three input arguments are provided.logspace: expected two or three input arguments
The count argument is not a numeric scalar value.logspace: number of points must be a scalar
The count argument is not an integer value.logspace: number of points must be an integer
The count argument is negative.logspace: number of points must be >= 0

How logspace works

  • logspace(a, b) is equivalent to logspace(a, b, 50).
  • logspace(a, b, 0) returns a 1 × 0 empty double row vector.
  • logspace(a, b, 1) returns 10^b.
  • logspace(a, b, 2) returns [10^a 10^b].
  • Endpoints may be real or complex scalars. Complex inputs produce complex outputs using the analytic definition 10^z = e^{z ln 10}.
  • Scalar inputs may be numeric literals, 1×1 tensors, or gathered GPU scalars (gpuArray handles). Non-scalar inputs raise an error.
  • The third argument must be a finite, non-negative integer.

Does RunMat run logspace on the GPU?

When either endpoint already resides on the GPU, RunMat attempts to keep the sequence on the device. Providers that implement linspace, scalar multiplication, and unary_exp can build the vector entirely in device memory. If any hook is unavailable, RunMat generates the sequence on the host and performs a single upload, ensuring downstream kernels still receive a GPU tensor without surprising performance cliffs.

GPU memory and residency

You usually do not need to call gpuArray yourself in RunMat. When an acceleration provider is active and either endpoint already lives on the GPU, RunMat keeps the generated sequence on the device whenever the provider exposes the necessary hooks. If the hooks are missing, RunMat generates the vector on the host and uploads it once. This strategy preserves residency for subsequent kernels while avoiding partial GPU execution.

Examples

Creating decades between 10 and 1000

x = logspace(1, 3, 3)

Expected output:

x = [10 100 1000]

Generating logarithmic spacing with the default 50 points

f = logspace(1, 4)

Expected output:

% f is a 1x50 row vector spanning [10, 10^4]
disp(f(1));
disp(f(end))

Requesting a single logarithmic sample

edge = logspace(-3, 2, 1)

Expected output:

edge = 100

Building a swept frequency vector on the GPU

lo = gpuArray(0);
hi = gpuArray(3);
freq = logspace(lo, hi, 256);
resp = sin(2*pi*freq)

Expected output:

% freq and resp remain on the GPU when an acceleration provider is active.
disp(gather(freq(1:5)))

Producing complex logarithmic spacing

z = logspace(1+1i, 2+2i, 4)

Expected output:

% Complex row vector with magnitudes and phases progressing logarithmically
disp(z)

Matching MATLAB's legacy logspace(a, pi, n) syntax

theta = logspace(-1, pi, 5)

Expected output:

% Interprets pi literally: theta(end) == 10^pi
disp(theta(end))

Using logspace with coding agents

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

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

FAQ

What base does logspace use?

RunMat follows MATLAB and always computes powers of ten. To use another base, build your own sequence (base .^ linspace(...)) or multiply the output by a constant factor.

Does logspace include both endpoints?

Yes. The first element is exactly 10^a and the final element is exactly 10^b, even when rounding errors could otherwise accumulate.

Can I request zero points?

Yes. logspace(a, b, 0) returns a 1 × 0 empty row vector.

What happens when a equals b?

Every element equals 10^a. For example, logspace(2, 2, 4) returns [100 100 100 100].

Does logspace support complex endpoints?

Yes. Real and imaginary components are interpolated independently, and the final values are computed using 10^z = e^{z ln 10}.

Is the third argument required to be an integer?

Yes. Non-integer or negative counts raise an error, matching MATLAB semantics.

Does the function support GPU scalars?

Yes. GPU scalars are gathered once to determine the sequence, and the resulting vector is uploaded back to the device when profitable.

How accurate is the last element?

The implementation explicitly overwrites the final element with 10^b to match MATLAB’s behavior and avoid floating-point drift.

How does logspace differ from linspace?

linspace spaces points linearly between two values, whereas logspace spaces points logarithmically between powers of ten.

Can I generate descending values?

Yes. logspace(3, 1, 4) returns [1000 464.1589 215.4435 100], decreasing logarithmically.

Creation

colon · eye · false · fill · inf · linspace · magic · meshgrid · nan · ones · peaks · rand · randi · randn · randperm · range · true · zeros

Sorting Sets

argsort · intersect · ismember · issorted · setdiff · sort · sortrows · union · unique

Shape

cat · circshift · diag · flip · fliplr · flipud · horzcat · ipermute · kron · permute · repelem · repmat · reshape · rot90 · squeeze · tril · triu · vertcat

Indexing

find · ind2sub · sub2ind

Introspection

isempty · ismatrix · isscalar · isvector · length · ndims · numel · size

Open-source implementation

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