ismembertol — Test numeric membership within tolerance in MATLAB and RunMat.
ismembertol(A, B) returns logical membership flags for real numeric values in A that are within tolerance of values in B. Optional outputs return first or all matching one-based indices into B.
Syntax
LIA = ismembertol(A, B)
LIA = ismembertol(A, B, tol, Name, Value)
[LIA, LocB] = ismembertol(A, B)
[LIA, LocB] = ismembertol(A, B, tol, Name, Value)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
A | NumericArray | Yes | — | Query values or rows. |
B | NumericArray | Yes | — | Reference values or rows. |
tol | NumericScalar | No | 1e-12 for double, 1e-6 for single | Relative tolerance. |
Name,Value | Any | Variadic | — | Name-value options: ByRows, DataScale, OutputAllIndices. |
Returns
| Name | Type | Description |
|---|---|---|
LIA | LogicalArray | Logical mask over A. |
LocB | Any | First or all matching indices into B. |
Returned values from ismembertol depend on how many outputs the caller requests.
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:ismembertol:InvalidInput | A or B is not a supported real full numeric input. | ismembertol: inputs must be real full numeric arrays |
RunMat:ismembertol:InvalidArgument | Tolerance or name-value arguments are malformed. | ismembertol: invalid argument |
RunMat:ismembertol:RowsColumnMismatch | ByRows is true and A/B column counts differ. | ismembertol: inputs must have the same number of columns when ByRows is true |
RunMat:ismembertol:Internal | Internal conversion or allocation fails. | ismembertol: internal error |
How ismembertol works
- Without an explicit tolerance, RunMat uses MATLAB-compatible defaults:
1e-12for double inputs and1e-6when either input is single precision. - Element comparisons use
abs(A-B) <= tol * max(abs([A(:); B(:)]))unlessDataScaleis supplied. DataScale, when scalar, changes the tolerance test toabs(A-B) <= tol * DataScale.ByRows, true compares complete rows and returns outputs of sizesize(A,1) x 1; A and B must have the same number of columns.- In row mode, vector
DataScalesupplies one scale per column. A scale ofInfignores that column during matching. - The optional second output
LocBcontains the first one-based index inBfor each match and0when absent. OutputAllIndices, true makesLocBa cell array whose cells contain all matching one-based indices, or[0]when no match exists.NaNvalues do not match. Exact equalities, including equal infinities, match before tolerance subtraction is considered.- Complex, sparse, string, character, cell, struct, and object inputs are rejected. The documented host data and tolerance domains are
singleanddouble; RunMat mode additionally accepts host integer/logical data and typed integer/logical tolerance controls through declared compatibility extensions.
Does RunMat run ismembertol on the GPU?
ismembertol is registered as a sink builtin. When either input tensor lives on the GPU the runtime gathers authoritative typed storage to host memory and performs tolerance matching there.
Documented ordinary logical and double-index outputs are restored to the first resident input handle's owning provider. Integer gpuArray inputs through 32 bits retain their documented support across the fallback.
Resident 64-bit integer input and enabled ByRows or OutputAllIndices are RunMat-only extensions checked before gather. The extended all-indices cell result remains host materialized because the public GPU form excludes that output.
Examples
Testing approximate membership with default scaling
A = [0.1 1e10];
B = [0.1 + 1e-14, 1e10 + 5e-3];
LIA = ismembertol(A, B)Expected output:
LIA =
1x2 logical array
1 1Returning first matching indices
A = [1 2 4];
B = [2.01 2.02 4.2];
[LIA, LocB] = ismembertol(A, B, 0.05)Expected output:
LIA =
1x3 logical array
0 1 1
LocB =
0 1 3Using absolute tolerance with DataScale
A = 1e10;
B = 1e10 + 5e-3;
LIA = ismembertol(A, B, 1e-6, 'DataScale', 1)Expected output:
LIA =
0Comparing rows and ignoring one column
A = [0 0.5; 10 20];
B = [0.05 999; 10.2 -999];
[LIA, LocB] = ismembertol(A, B, 0.1, 'ByRows', true, 'DataScale', [1 Inf])Expected output:
LIA =
2x1 logical array
1
0
LocB =
1
0Returning all matching locations
A = 2;
B = [1.99 2.01 9.5];
[LIA, LocB] = ismembertol(A, B, 0.01, 'OutputAllIndices', true)Expected output:
LIA =
1
LocB =
1x1 cell array
{[1; 2]}Using gpuArray inputs
G = gpuArray([1; 2]);
H = gpuArray([1 + 1e-13; 3]);
LIA = ismembertol(G, H)Expected output:
LIA =
2x1 logical array
1
0Using ismembertol with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how ismembertol changes the result.
Run a small ismembertol example, explain the result, then change one input and compare the output.
FAQ
How is the default tolerance chosen?⌄
Double inputs use 1e-12. If either input is single precision, RunMat uses 1e-6.
Does ismembertol support string or cell inputs like ismember?⌄
No. MATLAB's tolerance membership operation is numeric; RunMat accepts real full numeric and logical inputs only.
What does OutputAllIndices change?⌄
The second output becomes a cell array. Each cell contains every one-based index in B within tolerance of the corresponding element or row of A, or [0] when no match exists.
Can DataScale be a vector?⌄
Only when ByRows is true. Each vector element scales the tolerance for the corresponding column; Inf ignores that column.
Do NaN values match each other?⌄
No. NaN does not match any value, including another NaN, for ismembertol.
Will ismembertol run on the GPU automatically?⌄
Documented gpuArray input includes integer classes through 32 bits but excludes 64-bit integers, ByRows, and OutputAllIndices. RunMat preserves those additional forms behind explicit compatibility gates.
Related Array functions
Sorting Sets
argsort · intersect · ismember · issorted · issortedrows · setdiff · setxor · sort · sortrows · union · unique
Grouping
accumarray · combinations · discretize · findgroups · groupcounts · grp2idx · splitapply
Shape
blkdiag · cat · circshift · diag · flip · fliplr · flipud · horzcat · ipermute · kron · permute · repelem · repmat · reshape · rot90 · squeeze · toeplitz · tril · triu · vertcat
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how ismembertol is executed, line by line, in Rust.
- View the source for ismembertol in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
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.