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: Lukas Reichlin
Subject: Re: How to use "do_colon_op" in an oct-file?
Date: Thu, 15 Oct 2015 19:24:23 +0200

On 15.10.2015, at 18:15, John W. Eaton <address@hidden> wrote:

> 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
> 

Perfect! The function [1] works now as expected.

Thank you very much for your support and super-fast response,
Lukas

[1]
http://sourceforge.net/p/octave/control/ci/oct/tree/src/__lti_input_idx__.cc




reply via email to

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