## Copyright (C) 2026 The Octave Project Developers
##
## This file is part of Octave.
##
## Octave is free software: you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, see
## <https://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {} {@var{result} =} gather (@var{t})
## Force evaluation of tall array @var{t}.
##
## Tall arrays use lazy evaluation - operations are not computed until
## @code{gather()} is called. This function forces computation and returns
## the result as a regular array.
##
## Example:
## @example
## @group
## t = tall (rand (1e6, 100));
## s = sum (t);           % Lazy operation
## result = gather (s);   % Force evaluation, returns double
## @end group
## @end example
## @seealso{tall, head, tail}
## @end deftypefn

function result = gather (t)
  if (nargin != 1)
    print_usage ();
  endif

  if (strcmp (typeinfo (t), "tall") == 0)
    result = __gather__ (t);
  else
    result = t;  % If not tall, return as-is
  endif
endfunction

