help-octave
[Top][All Lists]
Advanced

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

Re: Changing data type in octave_value_list [actually input args from DE


From: Joshua Rigler
Subject: Re: Changing data type in octave_value_list [actually input args from DEFUN_DLD]
Date: Fri, 11 Aug 2006 16:53:31 -0600
User-agent: Thunderbird 1.5.0.5 (X11/20060719)

<...original message deleted...>
Søren Hauberg wrote:
Hi,
  I'm not exactly sure if the following solve your problem, but it's
worth a shot:

  #include <octave/oct.h>
  #include <cstdlib>
DEFUN_DLD(bla, args, nargout, "...")
  {
    if (args(0).is_string()) {
       args(0) = octave_value( atof(args(0).string_value().c_str()) );
    }
    return args;
  }

I didn't have convert_s2i, so I converted to a double instead. The real
change is the use of the 'octave_value' constructor. Basicly you have to
insert 'octave_value's in an octave_value_list.

Soren,

I think what you suggested *should* work, but it's just a slightly different version of something I already tried, which did not work. So, I tried to come up with something even simpler in order to figure out what was going on, and discovered some very repeatable strangeness in Octave's dynamically loaded functions. Would you, or other interested parties, look at the following short code snippet, which should compile easily using 'mkoctfile blah.cc', and consider a couple of questions?


  #include <octave/oct.h>

  DEFUN_DLD(blah, args, nargout, "...")
  {

    int i;
    octave_value_list rets;

    rets = args;

    for (i=0; i<args.length(); i++) {
      if (args(i).is_string()) {
        args(i) = octave_value (9999);
        rets(i) = octave_value (9999);
      }
    }
    //return rets;
    return args;
  }


I test this by [un]commenting the 'return rets;' line, recompiling, and re-running blah.oct with various inputs that are a mixture of strings and non-strings. What I expect is that strings in both args(i) and rets(i) will get changed into the scalar 9999. What actually happens is that *only* rets(i) gets modified, while args(i) remains unchanged.

What is so special about args here? Why does it seem to be impossible to change any of its elements? Is it not an octave_value_list like rets? I'm sure the answer is related more to C++ than Octave, but I would love to be enlightened, nonetheless.

In any case, I think I've found a simple solution to my problem...just copy args(i) into a declared octave_value_list, and use that for all subsequent operations. Thanks for your help.

-EJR


reply via email to

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