[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Request for indexing fix
From: |
David Bateman |
Subject: |
Request for indexing fix |
Date: |
Thu, 14 Jun 2007 01:08:07 +0200 |
User-agent: |
Thunderbird 1.5.0.7 (X11/20060921) |
Matlab allows the following code
x = randn(2,2,2);
idx(1:3) = {1};
idx(1) =';';
x(idx{:})
This is a really nice feature and I used it in the spline code I
committed. However, it seems that Octave doesn't allow this, and so the
ND spline code is in fact partially broken. I therefore suggest the
attached patch. One point however is that this means that x(':',1,1)
will give the same result, and without access to matlab at the moment
I'm unsure what matlab in fact does in this case.
D.
Index: src/ov-ch-mat.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/ov-ch-mat.cc,v
retrieving revision 1.27
diff -u -r1.27 ov-ch-mat.cc
--- src/ov-ch-mat.cc 3 Jun 2007 20:58:29 -0000 1.27
+++ src/ov-ch-mat.cc 13 Jun 2007 23:01:17 -0000
@@ -44,6 +44,16 @@
DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_char_matrix,
"char matrix", "int8");
+idx_vector
+octave_char_matrix::index_vector (void) const
+{
+ const char *p = matrix.data ();
+ if (numel () == 1 && *p == ':')
+ return idx_vector (':');
+ else
+ return idx_vector (array_value (true));
+}
+
bool
octave_char_matrix::valid_as_scalar_index (void) const
{
Index: src/ov-ch-mat.h
===================================================================
RCS file: /usr/local/cvsroot/octave/src/ov-ch-mat.h,v
retrieving revision 1.44
diff -u -r1.44 ov-ch-mat.h
--- src/ov-ch-mat.h 22 Jul 2006 08:31:17 -0000 1.44
+++ src/ov-ch-mat.h 13 Jun 2007 23:01:17 -0000
@@ -80,8 +80,7 @@
octave_base_value *clone (void) const { return new octave_char_matrix
(*this); }
octave_base_value *empty_clone (void) const { return new octave_char_matrix
(); }
- idx_vector index_vector (void) const
- { return idx_vector (array_value (true)); }
+ idx_vector index_vector (void) const;
bool is_char_matrix (void) const { return true; }
bool is_real_matrix (void) const { return true; }
- Request for indexing fix,
David Bateman <=