|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
atan2 on 3 dimentional arrayIs it normal, that i get error on
octave.exe:7> atan2(rand(5,5,5),rand(5,5,5)) error: invalid conversion of NDArray to Matrix _______________________________________________ Help-octave mailing list Help-octave@... https://www.cae.wisc.edu/mailman/listinfo/help-octave |
|
|
Re: atan2 on 3 dimentional arrayI believe the changeset http://velveeta.che.wisc.edu/cgi-bin/hgwebdir.cgi/octave/rev/798b0a00e80c fixed this issue, dated 20 Feb 2008 fixed this. However, it hasn't been applied to the 3.0.x branch and arguably should have been. Though it might be considered a new feature that this works for NDArrays, so maybe not. D. |
|
|
Re: atan2 on 3 dimentional arrayOn 15-Jul-2008, dbateman wrote:
| kruvalig wrote: | > | > Is it normal, that i get error on | > | > octave.exe:7> atan2(rand(5,5,5),rand(5,5,5)) | > error: invalid conversion of NDArray to Matrix | > | | I believe the changeset | | http://velveeta.che.wisc.edu/cgi-bin/hgwebdir.cgi/octave/rev/798b0a00e80c | | fixed this issue, dated 20 Feb 2008 fixed this. However, it hasn't been | applied to the 3.0.x branch and arguably should have been. Though it might | be considered a new feature that this works for NDArrays, so maybe not. OK, I applied it. I'm attaching the updated patch for the release-3-0-x branch. BTW, we could really use a release manager for the stable branch. Would anyone like to contribute by doing that? Thanks, jwe # HG changeset patch # User John W. Eaton <jwe@...> # Date 1203547151 18000 # Branch release-3-0-x # Node ID abbece6ab1864b1f4ea04d22de297e6e66bbd045 # Parent cd8576fabf72aec99fb1170cd5dce78a93d9fb90 atan2, fmod: accept N-d arrays diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2008-07-15 John W. Eaton <jwe@...> + + * data.cc (map_d_m, map_m_d, map_m_m, Fatan2, Ffmod): + Handle N-d arrays. + 2008-06-25 David Bateman <dbateman@...> * pr-output.cc (Frats): Print usage if nargin == 0. diff --git a/src/data.cc b/src/data.cc --- a/src/data.cc +++ b/src/data.cc @@ -130,61 +130,62 @@ typedef double (*d_dd_fcn) (double, double); -static Matrix -map_d_m (d_dd_fcn f, double x, const Matrix& y) +static NDArray +map_d_m (d_dd_fcn f, double x, const NDArray& y) { - octave_idx_type nr = y.rows (); - octave_idx_type nc = y.columns (); + NDArray retval (y.dims ()); + double *r_data = retval.fortran_vec (); - Matrix retval (nr, nc); + const double *y_data = y.data (); - for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - { - OCTAVE_QUIT; - retval (i, j) = f (x, y (i, j)); - } + octave_idx_type nel = y.numel (); + + for (octave_idx_type i = 0; i < nel; i++) + { + OCTAVE_QUIT; + r_data[i] = f (x, y_data[i]); + } return retval; } -static Matrix -map_m_d (d_dd_fcn f, const Matrix& x, double y) +static NDArray +map_m_d (d_dd_fcn f, const NDArray& x, double y) { - octave_idx_type nr = x.rows (); - octave_idx_type nc = x.columns (); + NDArray retval (x.dims ()); + double *r_data = retval.fortran_vec (); - Matrix retval (nr, nc); + const double *x_data = x.data (); - for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - { - OCTAVE_QUIT; - retval (i, j) = f (x (i, j), y); - } + octave_idx_type nel = x.numel (); + + for (octave_idx_type i = 0; i < nel; i++) + { + OCTAVE_QUIT; + r_data[i] = f (x_data[i], y); + } return retval; } -static Matrix -map_m_m (d_dd_fcn f, const Matrix& x, const Matrix& y) +static NDArray +map_m_m (d_dd_fcn f, const NDArray& x, const NDArray& y) { - octave_idx_type x_nr = x.rows (); - octave_idx_type x_nc = x.columns (); + assert (x.dims () == y.dims ()); - octave_idx_type y_nr = y.rows (); - octave_idx_type y_nc = y.columns (); + NDArray retval (x.dims ()); + double *r_data = retval.fortran_vec (); - assert (x_nr == y_nr && x_nc == y_nc); + const double *x_data = x.data (); + const double *y_data = y.data (); - Matrix retval (x_nr, x_nc); + octave_idx_type nel = x.numel (); - for (octave_idx_type j = 0; j < x_nc; j++) - for (octave_idx_type i = 0; i < x_nr; i++) - { - OCTAVE_QUIT; - retval (i, j) = f (x (i, j), y (i, j)); - } + for (octave_idx_type i = 0; i < nel; i++) + { + OCTAVE_QUIT; + r_data[i] = f (x_data[i], y_data[i]); + } return retval; } @@ -202,29 +203,18 @@ if (nargin == 2 && args(0).is_defined () && args(1).is_defined ()) { - if (args(0).is_integer_type () || args(0).is_integer_type ()) + if (args(0).is_integer_type () || args(1).is_integer_type ()) error ("atan2: not defined for integer types"); else { octave_value arg_y = args(0); octave_value arg_x = args(1); - octave_idx_type y_nr = arg_y.rows (); - octave_idx_type y_nc = arg_y.columns (); + dim_vector y_dims = arg_y.dims (); + dim_vector x_dims = arg_x.dims (); - octave_idx_type x_nr = arg_x.rows (); - octave_idx_type x_nc = arg_x.columns (); - - int arg_y_empty = empty_arg ("atan2", y_nr, y_nc); - int arg_x_empty = empty_arg ("atan2", x_nr, x_nc); - - if (arg_y_empty > 0 && arg_x_empty > 0) - return octave_value (Matrix ()); - else if (arg_y_empty || arg_x_empty) - return retval; - - octave_idx_type y_is_scalar = (y_nr == 1 && y_nc == 1); - octave_idx_type x_is_scalar = (x_nr == 1 && x_nc == 1); + bool y_is_scalar = y_dims.all_ones (); + bool x_is_scalar = x_dims.all_ones (); if (y_is_scalar && x_is_scalar) { @@ -244,7 +234,7 @@ if (! error_state) { - Matrix x = arg_x.matrix_value (); + NDArray x = arg_x.array_value (); if (! error_state) retval = map_d_m (atan2, y, x); @@ -252,7 +242,7 @@ } else if (x_is_scalar) { - Matrix y = arg_y.matrix_value (); + NDArray y = arg_y.array_value_value (); if (! error_state) { @@ -262,13 +252,13 @@ retval = map_m_d (atan2, y, x); } } - else if (y_nr == x_nr && y_nc == x_nc) + else if (y_dims == x_dims) { - Matrix y = arg_y.matrix_value (); + NDArray y = arg_y.array_value (); if (! error_state) { - Matrix x = arg_x.matrix_value (); + NDArray x = arg_x.array_value (); if (! error_state) retval = map_m_m (atan2, y, x); @@ -284,6 +274,14 @@ return retval; } +/* +%! assert (size (atan2 (zeros (0, 2), zeros (0, 2))), [0, 2]) +%! assert (size (atan2 (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4]) +%! assert (size (atan2 (rand (2, 3, 4), 1), [2, 3, 4]) +%! assert (size (atan2 (1, rand (2, 3, 4)), [2, 3, 4]) +%! assert (size (atan2 (1, 2), [1, 1]) +*/ + DEFUN (fmod, args, , "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} fmod (@var{x}, @var{y})\n\ @@ -298,25 +296,14 @@ if (nargin == 2 && args(0).is_defined () && args(1).is_defined ()) { - octave_value arg_x = args(0); - octave_value arg_y = args(1); + octave_value arg_y = args(0); + octave_value arg_x = args(1); - octave_idx_type y_nr = arg_y.rows (); - octave_idx_type y_nc = arg_y.columns (); + dim_vector y_dims = arg_y.dims (); + dim_vector x_dims = arg_x.dims (); - octave_idx_type x_nr = arg_x.rows (); - octave_idx_type x_nc = arg_x.columns (); - - int arg_y_empty = empty_arg ("fmod", y_nr, y_nc); - int arg_x_empty = empty_arg ("fmod", x_nr, x_nc); - - if (arg_y_empty > 0 && arg_x_empty > 0) - return octave_value (Matrix ()); - else if (arg_y_empty || arg_x_empty) - return retval; - - octave_idx_type y_is_scalar = (y_nr == 1 && y_nc == 1); - octave_idx_type x_is_scalar = (x_nr == 1 && x_nc == 1); + bool y_is_scalar = y_dims.all_ones (); + bool x_is_scalar = x_dims.all_ones (); if (y_is_scalar && x_is_scalar) { @@ -336,7 +323,7 @@ if (! error_state) { - Matrix x = arg_x.matrix_value (); + NDArray x = arg_x.array_value (); if (! error_state) retval = map_m_d (fmod, x, y); @@ -344,7 +331,7 @@ } else if (x_is_scalar) { - Matrix y = arg_y.matrix_value (); + NDArray y = arg_y.array_value (); if (! error_state) { @@ -354,13 +341,13 @@ retval = map_d_m (fmod, x, y); } } - else if (y_nr == x_nr && y_nc == x_nc) + else if (y_dims == x_dims) { - Matrix y = arg_y.matrix_value (); + NDArray y = arg_y.array_value (); if (! error_state) { - Matrix x = arg_x.matrix_value (); + NDArray x = arg_x.array_value (); if (! error_state) retval = map_m_m (fmod, x, y); @@ -374,6 +361,14 @@ return retval; } + +/* +%! assert (size (fmod (zeros (0, 2), zeros (0, 2))), [0, 2]) +%! assert (size (fmod (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4]) +%! assert (size (fmod (rand (2, 3, 4), 1), [2, 3, 4]) +%! assert (size (fmod (1, rand (2, 3, 4)), [2, 3, 4]) +%! assert (size (fmod (1, 2), [1, 1]) +*/ #define NATIVE_REDUCTION_1(FCN, TYPE, DIM) \ (arg.is_ ## TYPE ## _type ()) \ _______________________________________________ Help-octave mailing list Help-octave@... https://www.cae.wisc.edu/mailman/listinfo/help-octave |
|
|
|
|
|
Re: atan2 on 3 dimentional arrayOn Wed, Jul 16, 2008 at 7:14 PM, John W. Eaton <jwe@...> wrote:
> On 16-Jul-2008, Jaroslav Hajek wrote: > > | > BTW, we could really use a release manager for the stable branch. > | > Would anyone like to contribute by doing that? > | > | What exactly should the rm do? > > I have the following tasks in mind: > > * Monitor Octave bug reports and apply patches from the main development > branch to the stable branch. > > In some instances this job is trivial, but in others it requires > some care as the two branches may diverge so that patches don't > apply cleanly, or a change to the development branch might not be > appropriate for the stable branch (e.g., it changes an interface > that would break binary compatibility for .oct files). In the > latter case, maybe there is another fix that can be made that > doesn't break compatibility, or the fix may have to be deferred to > the release of the next major version. Ideally, only bug fixes > (and perhaps only fixes for regressions from previous releases) > should be applied, as I think the goal for the stable branch > should be stability. But currently we tend to apply patches that > are "safe", even if they fix bugs that are not regressions from > previous releases. > > * Make periodic releases from the stable branch. > > jwe > It sounds like something I could handle. However, I guess I'll need some guidance at first, as well as gaining practice with Mercurial. If you're ready for answering close-to-stupid questions for some time, then I feel up to the job :) regards -- RNDr. Jaroslav Hajek computing expert Aeronautical Research and Test Institute (VZLU) Prague, Czech Republic url: www.highegg.matfyz.cz _______________________________________________ Help-octave mailing list Help-octave@... https://www.cae.wisc.edu/mailman/listinfo/help-octave |
|
|
Re: atan2 on 3 dimentional arrayOn 16-Jul-2008, Jaroslav Hajek wrote:
| On Wed, Jul 16, 2008 at 7:14 PM, John W. Eaton <jwe@...> wrote: | > On 16-Jul-2008, Jaroslav Hajek wrote: | > | > | > BTW, we could really use a release manager for the stable branch. | > | > Would anyone like to contribute by doing that? | > | | > | What exactly should the rm do? | > | > I have the following tasks in mind: | > | > * Monitor Octave bug reports and apply patches from the main development | > branch to the stable branch. | > | > In some instances this job is trivial, but in others it requires | > some care as the two branches may diverge so that patches don't | > apply cleanly, or a change to the development branch might not be | > appropriate for the stable branch (e.g., it changes an interface | > that would break binary compatibility for .oct files). In the | > latter case, maybe there is another fix that can be made that | > doesn't break compatibility, or the fix may have to be deferred to | > the release of the next major version. Ideally, only bug fixes | > (and perhaps only fixes for regressions from previous releases) | > should be applied, as I think the goal for the stable branch | > should be stability. But currently we tend to apply patches that | > are "safe", even if they fix bugs that are not regressions from | > previous releases. | > | > * Make periodic releases from the stable branch. | > | > jwe | > | | It sounds like something I could handle. However, I guess I'll need | some guidance at first, | as well as gaining practice with Mercurial. If you're ready for | answering close-to-stupid questions for some time, then I feel up to | the job :) I was hoping to get someone new involved rather than overloading the current active contributors, but if you are interested, I won't turn down the offer. I'll contact you privately with some details about what you can do. Thanks, jwe _______________________________________________ Help-octave mailing list Help-octave@... https://www.cae.wisc.edu/mailman/listinfo/help-octave |
| Free embeddable forum powered by Nabble | Forum Help |