octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to use "do_colon_op" in an oct-file?


From: John W. Eaton
Subject: Re: How to use "do_colon_op" in an oct-file?
Date: Thu, 15 Oct 2015 12:15:03 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.7.0

On 10/15/2015 11:29 AM, Lukas Reichlin wrote:

I'm trying to substitute the following function with C++ using DEFUN_DLD:

function [mat_idx, opt_idx] = __lti_input_idx__ (varargin)

   str_idx = find (cellfun (@ischar, varargin));

   if (isempty (str_idx))
     mat_idx = 1 : nargin;
     opt_idx = [];
   else
     mat_idx = 1 : str_idx(1)-1;
     opt_idx = str_idx(1) : nargin;
   endif

endfunction

In the file  libinterp/corefcn/data.cc,  I found the expression

        retval = do_colon_op (args(0), args(1));

on line 6322 (inside definition of DEFUN (colon, args, …) on lines 6305-6335) 
and tried to use it in my C++ code.

I don't think you need do_colon_op for this job. You just need to return Range or Matrix objects.

  Range mat_idx (1, idx);
  Range opt_idx (idx+1, len);

  retval(1) = opt_idx;
  retval(0) = mat_idx;

Note that you probably want to either set the size or retval when you create it, or assign the elements from N-1 to 0 so that resizing only happens once instead of N times.

jwe




reply via email to

[Prev in Thread] Current Thread [Next in Thread]