RunMat
GitHub

fliplr — Flip arrays left-to-right in MATLAB and RunMat.

fliplr(A) mirrors A across its vertical axis by reversing column order (dimension 2). Inputs with fewer than two columns are unchanged, and type/device handling follows MATLAB semantics across numeric, logical, text, and gpuArray inputs.

Syntax

B = fliplr(A)

Inputs

NameTypeRequiredDefaultDescription
AAnyYesInput array/value to reverse along columns.

Returns

NameTypeDescription
BAnyInput array mirrored left-to-right (dimension 2).

Errors

IdentifierWhenMessage
RunMat:fliplr:InvalidInputInput type or conversion path is unsupported for fliplr.fliplr: invalid input argument
RunMat:fliplr:UnsupportedInputInput type is unsupported for fliplr.fliplr: unsupported input type

How fliplr works

  • Always reverses dimension 2 (columns) and leaves all other dimensions untouched, even for rank > 2 data.
  • Inputs with fewer than two columns (column vectors, scalars) are returned unchanged because the second dimension is singleton.
  • Logical, numeric, complex, character, and string arrays all preserve their MATLAB types and storage layout.
  • gpuArray inputs execute on the device via the generic flip provider hook (axis = 1); when that hook is missing, RunMat gathers once, mirrors the data on the host, and uploads the result so the returned value is still a gpuArray.
  • Dimensions larger than ndims(A) are treated as singleton axes, so fliplr never errors when A has rank < 2.

Does RunMat run fliplr on the GPU?

RunMat first tries to execute fliplr on the GPU by delegating to the provider’s generic flip implementation with axis 1 (zero-based). If the provider does not implement this hook, RunMat transparently gathers the tensor, performs the horizontal flip on the host, and uploads the result back to the device so residency is preserved.

GPU memory and residency

You typically do not need to call gpuArray directly. RunMat’s auto-offload planner keeps tensors on the GPU when profitable and only gathers when a provider lacks the flip hook. Even in that fallback, fliplr uploads the flipped result back to the device so subsequent operations can stay gpu-resident.

Examples

Reverse Columns of a Matrix

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

Expected output:

B =
     3     2     1
     6     5     4

Mirror an Image Matrix Horizontally

img = reshape(1:16, 4, 4);
mirrored = fliplr(img)

Expected output:

mirrored =
    4     3     2     1
    8     7     6     5
   12    11    10     9
   16    15    14    13

Flip the Order of Polynomial Coefficients

c = [1 0 -2 5];
rev = fliplr(c)

Expected output:

rev = [5  -2  0  1]

Reverse Each Slice in a 3-D Array Along Columns

T = reshape(1:24, [3 4 2]);
F = fliplr(T)

Expected output:

F(:,:,1) =
     4     3     2     1
     8     7     6     5
    12    11    10     9

F(:,:,2) =
    16    15    14    13
    20    19    18    17
    24    23    22    21

Preserve Column Vector Orientation

col = (1:4)';
same = fliplr(col)

Expected output:

same =
     1
     2
     3
     4

Flip Characters in a Two-Row Char Array

C = ['r','u','n'; 'm','a','t'];
Ct = fliplr(C)

Expected output:

Ct =
    'nur'
    'tam'

Keep gpuArray Results on the Device While Flipping Columns

G = gpuArray(rand(8, 8));
H = fliplr(G)

Using fliplr with coding agents

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

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

FAQ

Does fliplr change column vectors?

No. A column vector has a singleton second dimension, so reversing that axis leaves the data unchanged.

Is fliplr the same as calling flip(A, 2)?

Yes. fliplr is a convenience wrapper around flip that always targets dimension 2 (columns).

Can I apply fliplr to N-D tensors?

Absolutely. Only dimension 2 is reversed; all other axes keep their original order regardless of rank.

Does fliplr support string and character arrays?

Yes. String arrays reorder their elements, and character arrays mirror each row while preserving UTF-8 data.

What happens on the GPU if there is no flip kernel?

RunMat gathers the tensor once, mirrors it on the CPU, and uploads the result so you still receive a gpuArray.

Does fliplr allocate new GPU buffers?

Providers may reuse storage, but the builtin always returns a fresh handle. The simple provider uploads a new buffer.

Is fliplr numerically stable?

Yes. The function only reorders elements; values are never modified, so it is numerically stable.

Shape

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

Sorting Sets

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

Creation

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

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 fliplr 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.