54 octave_idx_type n = j1 * nr + ((j2 - j1) * (nr-(j1-k) + nr-(j2-1-k))) / 2;
56 T *rvec = r.fortran_vec ();
60 rvec = std::copy (avec + ii, avec + nr, rvec);
73 std::fill (rvec, rvec + ii, T ());
74 std::copy (avec + ii, avec + nr, rvec + ii);
97 = ((j2 - j1) * ((j1+1-k) + (j2-k))) / 2 + (nc - j2) * nr;
103 rvec = std::copy (avec, avec + ii, rvec);
112 T *rvec = r.fortran_vec ();
116 std::copy (avec, avec + ii, rvec);
117 std::fill (rvec + ii, rvec + nr, T ());
135 error (
"tril: \"pack\" not implemented for sparse matrices");
144 if (m.
ridx (i) < j-k)
157 error (
"triu: \"pack\" not implemented for sparse matrices");
166 if (m.
ridx (i) > j-k)
192 bool lower = name ==
"tril";
195 int nargin = args.
length ();
198 if (nargin >= 2 && args(nargin-1).is_string ())
200 pack = args(nargin-1).string_value () ==
"pack";
206 k = args(1).int_value (
true);
212 if (nargin < 1 || nargin > 2)
220 error (
"%s: need a 2-D matrix", name.c_str ());
221 else if (k < -dims (0) || k > dims(1))
222 error (
"%s: requested diagonal out of range", name.c_str ());
247 #define ARRAYCASE(TYP) \
249 retval = do_trilu (arg.TYP ## _array_value (), k, lower, pack); \
270 error (
"%s: \"pack\" not implemented for class %s",
276 if (arg.
numel () == 0)
293 std::list<octave_value_list> idx_tmp;
294 ov_idx(1) =
static_cast<double> (nc+1);
295 ov_idx(0) =
Range (1, nr);
296 idx_tmp.push_back (ov_idx);
297 ov_idx(1) =
static_cast<double> (nc);
309 ov_idx(1) =
static_cast<double> (j);
310 ov_idx(0) =
Range (nr_limit, nr);
311 std::list<octave_value_list> idx;
312 idx.push_back (ov_idx);
327 ov_idx(1) =
static_cast<double> (j);
328 ov_idx(0) =
Range (1, nr_limit);
329 std::list<octave_value_list> idx;
330 idx.push_back (ov_idx);
350 @deftypefn {Function File} {} tril (@var{A})\n\
351 @deftypefnx {Function File} {} tril (@var{A}, @var{k})\n\
352 @deftypefnx {Function File} {} tril (@var{A}, @var{k}, @var{pack})\n\
353 @deftypefnx {Function File} {} triu (@var{A})\n\
354 @deftypefnx {Function File} {} triu (@var{A}, @var{k})\n\
355 @deftypefnx {Function File} {} triu (@var{A}, @var{k}, @var{pack})\n\
356 Return a new matrix formed by extracting the lower (@code{tril})\n\
357 or upper (@code{triu}) triangular part of the matrix @var{A}, and\n\
358 setting all other elements to zero.\n\
360 The second argument is optional, and specifies how many diagonals above or\n\
361 below the main diagonal should also be set to zero.\n\
363 The default value of @var{k} is zero, so that @code{triu} and @code{tril}\n\
364 normally include the main diagonal as part of the result.\n\
366 If the value of @var{k} is nonzero integer, the selection of elements starts\n\
367 at an offset of @var{k} diagonals above or below the main diagonal; above\n\
368 for positive @var{k} and below for negative @var{k}.\n\
370 The absolute value of @var{k} must not be greater than the number of\n\
371 subdiagonals or superdiagonals.\n\
377 tril (ones (3), -1)\n\
389 tril (ones (3), 1)\n\
396 If the option @qcode{\"pack\"} is given as third argument, the extracted\n\
397 elements are not inserted into a matrix, but rather stacked column-wise one\n\
407 @deftypefn {Function File} {} triu (@var{A})\n\
408 @deftypefnx {Function File} {} triu (@var{A}, @var{k})\n\
409 @deftypefnx {Function File} {} triu (@var{A}, @var{k}, @var{pack})\n\
410 See the documentation for the @code{tril} function (@pxref{tril}).\n\
ComplexNDArray complex_array_value(bool frc_str_conv=false) const
octave_idx_type cols(void) const
OCTINTERP_API void print_usage(void)
octave_idx_type length(void) const
#define DEFUN(name, args_name, nargout_name, doc)
void error(const char *fmt,...)
octave_value resize(const dim_vector &dv, bool fill=false) const
octave_idx_type * cidx(void)
static Array< T > do_tril(const Array< T > &a, octave_idx_type k, bool pack)
boolNDArray bool_array_value(bool warn=false) const
octave_idx_type rows(void) const
static Array< T > do_triu(const Array< T > &a, octave_idx_type k, bool pack)
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
bool is_sparse_type(void) const
octave_idx_type numel(const octave_value_list &idx)
Sparse< T > maybe_compress(bool remove_zeros=false)
SparseBoolMatrix sparse_bool_matrix_value(bool warn=false) const
SparseComplexMatrix sparse_complex_matrix_value(bool frc_str_conv=false) const
dim_vector dims(void) const
Handles the reference counting for all the derived classes.
charNDArray max(char d, const charNDArray &m)
This is a simple wrapper template that will subclass an Array type or any later type derived from ...
NDArray array_value(bool frc_str_conv=false) const
octave_idx_type * ridx(void)
std::string class_name(void) const
SparseMatrix sparse_matrix_value(bool frc_str_conv=false) const
const T * fortran_vec(void) const
builtin_type_t builtin_type(void) const
octave_idx_type columns(void) const
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
static Array< T > do_trilu(const Array< T > &a, octave_idx_type k, bool lower, bool pack)
charNDArray min(char d, const charNDArray &m)
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)