[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
What is the correct NDArray behavior of printf?
From: |
John W. Eaton |
Subject: |
What is the correct NDArray behavior of printf? |
Date: |
Thu, 22 Apr 2004 11:01:22 -0500 |
On 22-Apr-2004, David Bateman <address@hidden> wrote:
| The behavior of Matlab for printf, kron etc, is to horizontally or
| vertically stack the 2-D cuts of the NDArray objects. Thus in matlab
|
| a = [1, 2; 3, 4]; a(:,:,2) = [5, 6; 7, 8]; sprintf('%f %f\n', a)
|
| is legal and give
|
| ans =
|
| 1.000000 3.000000
| 2.000000 4.000000
| 5.000000 7.000000
| 6.000000 8.000000
|
|
| However, printf etc in octave called with NDArray arguments gives an
| error (when trying to transpose the NDArray).
I don't see a transpose error, I see
octave:4> printf ("%f %f\n", a)
error: invalid conversion of NDArray to Matrix
| What is the correct behavior for these functions called with NDArrays?
| Is the Matlab behavior of reducing these arrays to 2-D objects the way
| to go?
I think it is equivalent to
printf ("%f %f\n", a(:))
which gives the compatible result. I think the following change
should be all that is needed for this particular case. There are a
number of other things that will also need to be changed in
oct-stream.cc to handle N-d arrays.
jwe
src/ChangeLog:
2004-04-22 John W. Eaton <address@hidden>
* oct-stream.cc (printf_value_cache::curr_value): Now NDArray.
(printf_value_cache::double_value): Extract N-d array, not Matrix.
Index: src/oct-stream.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/oct-stream.cc,v
retrieving revision 1.100
diff -u -r1.100 oct-stream.cc
--- a/src/oct-stream.cc 23 Feb 2004 22:10:32 -0000 1.100
+++ b/src/oct-stream.cc 22 Apr 2004 15:59:59 -0000
@@ -2123,7 +2123,7 @@
int n_vals;
int n_elts;
const double *data;
- Matrix curr_val;
+ NDArray curr_val;
state curr_state;
// Must create value cache with values!
@@ -2151,7 +2151,7 @@
{
octave_value tmp_val = values (val_idx);
- curr_val = tmp_val.matrix_value ();
+ curr_val = tmp_val.array_value ();
if (! error_state)
{