octave-maintainers
[Top][All Lists]
Advanced

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

Re: How to use the OO features of Octave


From: John W. Eaton
Subject: Re: How to use the OO features of Octave
Date: Tue, 23 Sep 2008 17:26:55 -0400

On 23-Sep-2008, David Bateman wrote:

| Ok, I see the return value should be minus one, but index_pos definitely 
| needs to be. As far as I can see a pretty generic NDArray end method 
| would look like
| 
| 
| function r = end (obj, index_pos, num_indices)
|    ++index_pos;
|    dv = size (obj.x);
|    for i = num_indices + 1 : length (dv)
|      dv(num_indices) *= dv(i);
|    endfor
|    if (index_pos < length (dv))
|      r = dv (index_pos);
|    elseif
|      r = 1;
|    endif
| endfunction

I think the elseif above should be else, but that's not the problem.
 
| though the "++index_pos;" should go away if F__end__ was adapted to pass 
| "index_pos + 1". However, this doesn't work correctly with the toy class 
| What I see is
| 
| a = gf (floor(4*rand(3,3,2)),2);
| 
| a(1,1:end)
| 
| ans =
| GF(2^2) array. Primitive Polynomial = D^2+D+1 (decimal 7)
| 
| Array elements =
| 
| 0
| 
| and
| 
| a(1,1,1:end)
| 
| ans =
| GF(2^2) array. Primitive Polynomial = D^2+D+1 (decimal 7)
| 
| Array elements =
| 
| 0
| 
| Not sure what is going wrong but the first of the above should produce 6 
| elements and the second 2 elements, but both produce 1. Any ideas?

In your subsref.m, I think you need

      ind = s.subs;
      b = gf (a.x(ind{:}), a.m, a.prim_poly)

instead of 

      ind = s.subs{:};
      b = gf (a.x(ind), a.m, a.prim_poly)

Maybe this is a bug that it is not at least warning you about the
assignment of the comma-separated list to IND, which is only assigning
the first value in the cs-list to IND.

| On a related note "a(:)" on the class object works correctly, but 
| "a(1,:)" and "a(:,1)" etc don't

I think both will work correctly with the change above to your subsref
function.

jwe


reply via email to

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