{
"title": "true",
"category": "array/creation",
"keywords": [
"true",
"logical",
"array",
"mask"
],
"summary": "Create logical arrays filled with true values.",
"references": [],
"gpu_support": {
"elementwise": false,
"reduction": false,
"precisions": [],
"broadcasting": "none",
"notes": "Always constructs a host logical array; gpuArray inputs are used only for sizing."
},
"fusion": {
"elementwise": false,
"reduction": false,
"max_inputs": 0,
"constants": "inline"
},
"requires_feature": null,
"tested": {
"unit": "builtins::array::creation::true_false::tests",
"integration": null
},
"description": "`true` creates logical arrays filled with true values. RunMat mirrors MATLAB sizing semantics across scalar, vector, matrix, and N-D forms.",
"behaviors": [
"`true()` returns the scalar logical `true`.",
"`true(n)` returns an n x n logical array of true values.",
"`true(m, n, ...)` returns a logical array with the requested dimensions.",
"`true(sz)` accepts a size vector (row or column) and returns an array with prod(sz) elements arranged using MATLAB column-major ordering.",
"`true(A)` returns a logical array of true with the same size as `A`.",
"`true(___, 'like', prototype)` uses the prototype only for sizing; the result is still a host logical array.",
"`true(___, 'logical')` is accepted for MATLAB compatibility and has no effect."
],
"examples": [
{
"description": "Creating a 2x3 logical array of true values",
"input": "mask = true(2, 3)",
"output": "mask = [1 1 1; 1 1 1]"
},
{
"description": "Creating a logical array from a size vector",
"input": "dims = [2 1 3];\nmask = true(dims)",
"output": "mask =\n 2x1x3 logical array\n 1\n 1\n 1\n 1\n 1\n 1"
},
{
"description": "Creating a true mask with the same size as an existing array",
"input": "A = rand(3, 2);\nmask = true(A)",
"output": "mask =\n 3x2 logical array\n 1 1\n 1 1\n 1 1"
}
],
"faqs": [
{
"question": "What does `true()` return?",
"answer": "It returns the logical scalar `true`."
},
{
"question": "Does `true(n)` create a square array?",
"answer": "Yes. `true(n)` returns an n x n logical array of true values, matching MATLAB behavior."
},
{
"question": "How does `true(sz)` interpret a size vector?",
"answer": "A row or column vector is treated as the full set of dimensions, so `true([2 3 4])` yields a 2x3x4 logical array."
},
{
"question": "Does `true` keep results on the GPU?",
"answer": "No. The builtin always returns a host logical array. gpuArray inputs are only used to infer the output size."
},
{
"question": "Is the `'logical'` option required?",
"answer": "No. `true` always returns logical values; the `'logical'` option is accepted only for MATLAB compatibility."
}
],
"links": [
{
"label": "false",
"url": "./false"
},
{
"label": "logical",
"url": "./logical"
},
{
"label": "islogical",
"url": "./islogical"
},
{
"label": "zeros",
"url": "./zeros"
},
{
"label": "colon",
"url": "./colon"
},
{
"label": "eye",
"url": "./eye"
},
{
"label": "fill",
"url": "./fill"
},
{
"label": "linspace",
"url": "./linspace"
},
{
"label": "logspace",
"url": "./logspace"
},
{
"label": "magic",
"url": "./magic"
},
{
"label": "meshgrid",
"url": "./meshgrid"
},
{
"label": "ones",
"url": "./ones"
},
{
"label": "rand",
"url": "./rand"
},
{
"label": "randi",
"url": "./randi"
},
{
"label": "randn",
"url": "./randn"
},
{
"label": "randperm",
"url": "./randperm"
},
{
"label": "range",
"url": "./range"
}
],
"source": {
"label": "`crates/runmat-runtime/src/builtins/array/creation/true_false.rs`",
"url": "https://github.com/runmat-org/runmat/blob/main/crates/runmat-runtime/src/builtins/array/creation/true_false.rs"
}
}