octave-maintainers
[Top][All Lists]
Advanced

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

Re: goals for 3.1


From: David Bateman
Subject: Re: goals for 3.1
Date: Sun, 09 Mar 2008 21:33:12 +0100
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

John W. Eaton wrote:
>    7. Ensure that all operations which work on dimensions alone
>       (squeeze, numel, triu, etc.) work for all objects and preserve
>       type.  Should these functions all be built-in?  Possibly they
>       should all be provided by the octave_value class interface.
>   

Ok, I see this task as being in three parts, and maybe a zeroth part

0) Identify which functions are concerned. I see the list at the moment
as being triu, tril, squeeze, permute, ipermute, shiftdim, circshift,
reshape,  and resize. I'm not sure I see why numel was in that original
list. Are there any others?

1) Write test code that compares the output of Octave against matlab for
the desired functions and confirm their consistency. Address any issues
in the Octave code. The resize function doesn't exist in matlab so its
not obvious to test this function. The attached code I believe tests all
of the others and compares the behavior with matlab's as thecode is
matlab compatible. The 3.0.0 behavior of all of these functions seems to
be correct.

2) Convert that test code to test/assert framework of Octave for
regression testing. It would be easy to add the attached test code into
the test/ directory. However, the trend is to have the tests embedded in
the code, and that will be an issue, in that all of the tests are much
the same, and distributing the tests into each function will result in
code duplication.

3) Convert these functions to be members of the octave_value class. What
are your thoughts now on this? Should they be members of the
octave_value class? Or can we forgo this?

Regards
David
function testfunc
  sz2 = [10, 11];
  sz3 = [10, 1, 11];
  fn = {'triu', 'tril', 'squeeze', 'permute', 'ipermute', ...
        'shiftdim', 'shiftdim', 'circshift', 'circshift', 'reshape'};
  sz = {sz2, sz2, sz3, sz3, sz3, sz3, sz3, sz3, sz3, sz3};
  args = {{}, {}, {}, {[3, 1, 2]}, {[3, 1, 2]}, {1}, {-1}, {1}, ...
          {[1, -1]}, {[sz3(end), sz3(1:end-1)]}};
  for i = 1 : length (fn)
    fnargs = args{i};
    fntestfunc (fn{i}, sz{i}, fnargs{:});
  end
end

function fntestfunc (fn, sz, varargin)
  s = warning ('off');
  typ = {'double', 'complex', 'logical', 'sparse', 'complex sparse', ...
         'logical sparse', 'int8', 'int16', 'int32', 'int64', 'uint8', ...
         'uint16', 'uint32', 'uint64'};

  cmplx = [2, 5];
  nlogical = [3, 6];
  ninteger = [7, 8, 9, 10, 11, 12, 13, 14];
  nsparse = [4, 5, 6];

  fprintf ('Testing %s:\n', fn);
  
  for i = 1 : length(typ)
    if (any (nsparse == i))
      if (length (sz) > 2)
        sz = [sz(1), sz(3)];
      end
      if (any (cmplx == i))
        m = sparse ((1 + 1i) * reshape ([1 : prod(sz)], sz));
      else
        m = sparse (reshape ([1 : prod(sz)], sz));
      end
      if (strcmp (fn, 'permute') || strcmp (fn, 'ipermute'))
        varargin{1} = [2, 1];
      end
    else
      if (any (cmplx == i))
        m = (1 + 1i) * reshape ([1 : prod(sz)], sz);
      else
        m = reshape ([1 : prod(sz)], sz);
      end
    end
    if (any (nlogical == i))
      m = cast (m, 'logical');
    end
    if (any (ninteger == i))
      m = cast (m, typ{i});
    end

    try
      y = feval (fn, m, varargin{:});
      %% Block below can be replaced with asserts when no matlab
      %% support needed.
      if ( ~ strcmp (class (y), class (m)))
        error ();
      end
      if (issparse (y) ~= issparse (m))
        error ();
      end
      if (any (cast (real (y), 'double') ~= ...
               feval (fn , cast (real (m), 'double'), varargin{:})))
        error ();
      end
      %% assert (class (y), class (m));
      %% assert (issparse (y), issparse (m));
      %% assert (cast (real (y), 'double'), ...
      %%         feval (fn , cast (real (m), 'double'), varargin{:}));
    catch
      fprintf ('   failed for type %s\n', typ{i});
    end
    if (exist ('OCTAVE_VERSION'))
      eval ('fflush(stdout);');
    end
  end
end

reply via email to

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