[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Can .oct files do in-place matrix operations?
From: |
John W. Eaton |
Subject: |
Can .oct files do in-place matrix operations? |
Date: |
Tue, 12 May 1998 12:15:51 -0500 (CDT) |
On 12-May-1998, Dirk Laurie <address@hidden> wrote:
| I have some old Matlab 3.5 files in which row and column rotations
| are done in-place using .mex files. I.e. the .mex file for
| rotate(A,ij,R,job)
| does the equivalent of
| A(ij,:)=R*A(ij,:); (job=1)
| or A(:,ij)=A(:,ij)*R; (job=2)
| or both (job=3),
| where R is a 2x2 matrix and ij is a two-component index vector.
|
| This speeded up my program by about 50%, I recall.
|
| Now I get the impression that Octave will not allow me to do
| this by an .oct file. It seems to require my returning the
| changed A as an octave_value, which as far as I can make out
| involves two full matrix assignments: one to make the local
| copy of A that I modify, and one to assign it back to my
| original matrix. Since rotation is an O(n) operation I will
| probably not gain by doing this, or am I wrong?
You may still get some improvement in performance, but arguments
passed to functions defined by .oct files still have pass-by-value
semantics, though they are only copied if necessary (if they are
modified in the function). In either case (.m or .oct file) only
one copy should be performed:
funcction y = f (x)
y = x; # no data copied -- only reference count updated
y(1) = 2; # copy forced.
endfunction
jwe