Mon 23 Aug 2010 09:10:40 AM UTC, original submission:
First of all, let me express my gratitude and respect for making Octave a true "Matlab challenger".
I'm using version 3.2.4 on i686-pc-linux-gnu. I have some numerical code that should run for dense and sparse matrices as well as for linear operators specified through the Octave OOP facilities. The matrix class 'mat' [2] does not properly handle the overloaded transpose operator.
The code calling the 'mat' class [2]
m = 3; n = 5; A = mat(m,n); y = randn(m,1);
z1 = [A']*y; % => OK
z2 = (A')*y; % => error [1]
z3 = A'*y; % => error [1]
yields the error [1] on Octave but works fine for Matlab. Only putting [] around the transposed operator seems to work.
Thanks for you help
Hannes Nickisch
[1]
error: T& Array<T>::checkelem (2): range error
error: called from:
error: mat_bug.m at line 3, column 4
[2]
The matrix class consists of 4 files located in @mat:
1) mat.m
function A = mat(m,n)
sz = [m,n];
A.mat = randn(sz);
A.sz = sz; A.ctransp = 0;
A = class(A,mfilename);
2) size.m
function [sz1,sz2] = size(A,id)
sz = A.sz; if A.ctransp, sz = sz([2,1]); end
if nargin==1
if nargout==2, sz1 = sz(1); sz2 = sz(2); else sz1 = sz; end
elseif nargin==2
if nargout>1, error('too many output arguments'), end
if id(1)>numel(sz), sz1 = 1; else sz1 = sz(id); end
else
error('wrong number of input arguments')
end
3) ctranspose.m
function A = ctranspose(A), A.ctransp = xor(A.ctransp,1);
4) mtimes.m
function y = mtimes(A,x), if A.ctransp, y = A.mat'x; else y = A.matx; end
|