# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1314413843 18000 # Node ID 15eefbd9d4e85da20b9f10ae04a96145499b9dd6 # Parent 38b52a073cfaeaafb412368f88a3df76d065c35f Implement a few missing automatic bsxfun power operators * bsxfun-decl.h: Declare mixed integer-float bsxfun power operators. * int8NDArray.h: Ditto. * int16NDArray.h: Ditto. * int32NDArray.h: Ditto. * int64NDArray.h: Ditto. * uint8NDArray.h: Ditto. * uint16NDArray.h: Ditto. * uint32NDArray.h: Ditto. * uint64NDArray.h: Ditto. * bsxfun-defs.cc: Define mixed integer-float bsxfun power operators. * int8NDArray.cc: Ditto. * int16NDArray.cc: Ditto. * int32NDArray.cc: Ditto. * int64NDArray.cc: Ditto. * uint8NDArray.cc: Ditto. * uint16NDArray.cc: Ditto. * uint32NDArray.cc: Ditto. * uint64NDArray.cc: Ditto. * fNDArray.h: Declare mixed float-complex bsxfun power operators. * fNDArray.cc: Define mixed float-complex bsxfun power operators. * oct-inttypes.cc: Declare overloaded pow(integer, float) functions. * oct-inttypes.cc: Define and instantiate overloaded pow(integer, float) functions. * op-int.h: Remove casts so that mixed-type bsxfun_pow functions are called now. * xpow.cc: Cast to complex arrays if pow returns non-real; call bsxfun on a few missing functions diff -r 38b52a073cfa -r 15eefbd9d4e8 liboctave/bsxfun-decl.h --- a/liboctave/bsxfun-decl.h Fri Aug 26 09:33:52 2011 -0400 +++ b/liboctave/bsxfun-decl.h Fri Aug 26 21:57:23 2011 -0500 @@ -42,6 +42,12 @@ BSXFUN_OP_DECL (min, ARRAY, API) \ BSXFUN_OP_DECL (max, ARRAY, API) +#define BSXFUN_MIXED_INT_DECLS(INT_TYPE, API) \ + BSXFUN_OP2_DECL (pow, INT_TYPE, INT_TYPE, NDArray, API) \ + BSXFUN_OP2_DECL (pow, INT_TYPE, INT_TYPE, FloatNDArray, API) \ + BSXFUN_OP2_DECL (pow, INT_TYPE, NDArray, INT_TYPE, API) \ + BSXFUN_OP2_DECL (pow, INT_TYPE, FloatNDArray, INT_TYPE, API) + #define BSXFUN_STDREL_DECLS(ARRAY, API) \ BSXFUN_REL_DECL (eq, ARRAY, API) \ BSXFUN_REL_DECL (ne, ARRAY, API) \ diff -r 38b52a073cfa -r 15eefbd9d4e8 liboctave/bsxfun-defs.cc --- a/liboctave/bsxfun-defs.cc Fri Aug 26 09:33:52 2011 -0400 +++ b/liboctave/bsxfun-defs.cc Fri Aug 26 21:57:23 2011 -0500 @@ -174,4 +174,11 @@ BSXFUN_REL_DEF_MXLOOP (gt, ARRAY, mx_inline_gt) \ BSXFUN_REL_DEF_MXLOOP (ge, ARRAY, mx_inline_ge) +//For bsxfun power with mixed integer/float types +#define BSXFUN_POW_MIXED_MXLOOP(INT_TYPE) \ + BSXFUN_OP2_DEF_MXLOOP (pow, INT_TYPE, INT_TYPE, NDArray, mx_inline_pow) \ + BSXFUN_OP2_DEF_MXLOOP (pow, INT_TYPE, INT_TYPE, FloatNDArray, mx_inline_pow)\ + BSXFUN_OP2_DEF_MXLOOP (pow, INT_TYPE, NDArray, INT_TYPE, mx_inline_pow) \ + BSXFUN_OP2_DEF_MXLOOP (pow, INT_TYPE, FloatNDArray, INT_TYPE, mx_inline_pow) + #endif diff -r 38b52a073cfa -r 15eefbd9d4e8 liboctave/fNDArray.cc --- a/liboctave/fNDArray.cc Fri Aug 26 09:33:52 2011 -0400 +++ b/liboctave/fNDArray.cc Fri Aug 26 21:57:23 2011 -0500 @@ -885,3 +885,5 @@ BSXFUN_OP_DEF_MXLOOP (pow, FloatNDArray, mx_inline_pow) BSXFUN_OP2_DEF_MXLOOP (pow, FloatComplexNDArray, FloatComplexNDArray, FloatNDArray, mx_inline_pow) +BSXFUN_OP2_DEF_MXLOOP (pow, FloatComplexNDArray, FloatNDArray, + FloatComplexNDArray, mx_inline_pow) diff -r 38b52a073cfa -r 15eefbd9d4e8 liboctave/fNDArray.h --- a/liboctave/fNDArray.h Fri Aug 26 09:33:52 2011 -0400 +++ b/liboctave/fNDArray.h Fri Aug 26 21:57:23 2011 -0500 @@ -182,5 +182,7 @@ BSXFUN_OP_DECL (pow, FloatNDArray, OCTAVE_API) BSXFUN_OP2_DECL (pow, FloatComplexNDArray, FloatComplexNDArray, FloatNDArray, OCTAVE_API) +BSXFUN_OP2_DECL (pow, FloatComplexNDArray, FloatNDArray, + FloatComplexNDArray, OCTAVE_API) #endif diff -r 38b52a073cfa -r 15eefbd9d4e8 liboctave/int16NDArray.cc --- a/liboctave/int16NDArray.cc Fri Aug 26 09:33:52 2011 -0400 +++ b/liboctave/int16NDArray.cc Fri Aug 26 21:57:23 2011 -0500 @@ -56,3 +56,5 @@ BSXFUN_STDREL_DEFS_MXLOOP (int16NDArray) BSXFUN_OP_DEF_MXLOOP (pow, int16NDArray, mx_inline_pow) + +BSXFUN_POW_MIXED_MXLOOP (int16NDArray) diff -r 38b52a073cfa -r 15eefbd9d4e8 liboctave/int16NDArray.h --- a/liboctave/int16NDArray.h Fri Aug 26 09:33:52 2011 -0400 +++ b/liboctave/int16NDArray.h Fri Aug 26 21:57:23 2011 -0500 @@ -44,6 +44,7 @@ MINMAX_DECLS (int16NDArray, octave_int16, OCTAVE_API) BSXFUN_STDOP_DECLS (int16NDArray, OCTAVE_API) +BSXFUN_MIXED_INT_DECLS(int16NDArray, OCTAVE_API) BSXFUN_STDREL_DECLS (int16NDArray, OCTAVE_API) #endif diff -r 38b52a073cfa -r 15eefbd9d4e8 liboctave/int32NDArray.cc --- a/liboctave/int32NDArray.cc Fri Aug 26 09:33:52 2011 -0400 +++ b/liboctave/int32NDArray.cc Fri Aug 26 21:57:23 2011 -0500 @@ -56,3 +56,4 @@ BSXFUN_STDREL_DEFS_MXLOOP (int32NDArray) BSXFUN_OP_DEF_MXLOOP (pow, int32NDArray, mx_inline_pow) +BSXFUN_POW_MIXED_MXLOOP (int32NDArray) diff -r 38b52a073cfa -r 15eefbd9d4e8 liboctave/int32NDArray.h --- a/liboctave/int32NDArray.h Fri Aug 26 09:33:52 2011 -0400 +++ b/liboctave/int32NDArray.h Fri Aug 26 21:57:23 2011 -0500 @@ -44,6 +44,7 @@ MINMAX_DECLS (int32NDArray, octave_int32, OCTAVE_API) BSXFUN_STDOP_DECLS (int32NDArray, OCTAVE_API) +BSXFUN_MIXED_INT_DECLS(int32NDArray, OCTAVE_API) BSXFUN_STDREL_DECLS (int32NDArray, OCTAVE_API) #endif diff -r 38b52a073cfa -r 15eefbd9d4e8 liboctave/int64NDArray.cc --- a/liboctave/int64NDArray.cc Fri Aug 26 09:33:52 2011 -0400 +++ b/liboctave/int64NDArray.cc Fri Aug 26 21:57:23 2011 -0500 @@ -56,3 +56,5 @@ BSXFUN_STDREL_DEFS_MXLOOP (int64NDArray) BSXFUN_OP_DEF_MXLOOP (pow, int64NDArray, mx_inline_pow) + +BSXFUN_POW_MIXED_MXLOOP (int64NDArray) diff -r 38b52a073cfa -r 15eefbd9d4e8 liboctave/int64NDArray.h --- a/liboctave/int64NDArray.h Fri Aug 26 09:33:52 2011 -0400 +++ b/liboctave/int64NDArray.h Fri Aug 26 21:57:23 2011 -0500 @@ -44,6 +44,7 @@ MINMAX_DECLS (int64NDArray, octave_int64, OCTAVE_API) BSXFUN_STDOP_DECLS (int64NDArray, OCTAVE_API) +BSXFUN_MIXED_INT_DECLS(int64NDArray, OCTAVE_API) BSXFUN_STDREL_DECLS (int64NDArray, OCTAVE_API) #endif diff -r 38b52a073cfa -r 15eefbd9d4e8 liboctave/int8NDArray.cc --- a/liboctave/int8NDArray.cc Fri Aug 26 09:33:52 2011 -0400 +++ b/liboctave/int8NDArray.cc Fri Aug 26 21:57:23 2011 -0500 @@ -56,3 +56,4 @@ BSXFUN_STDREL_DEFS_MXLOOP (int8NDArray) BSXFUN_OP_DEF_MXLOOP (pow, int8NDArray, mx_inline_pow) +BSXFUN_POW_MIXED_MXLOOP (int8NDArray) diff -r 38b52a073cfa -r 15eefbd9d4e8 liboctave/int8NDArray.h --- a/liboctave/int8NDArray.h Fri Aug 26 09:33:52 2011 -0400 +++ b/liboctave/int8NDArray.h Fri Aug 26 21:57:23 2011 -0500 @@ -44,6 +44,7 @@ MINMAX_DECLS (int8NDArray, octave_int8, OCTAVE_API) BSXFUN_STDOP_DECLS (int8NDArray, OCTAVE_API) +BSXFUN_MIXED_INT_DECLS(int8NDArray, OCTAVE_API) BSXFUN_STDREL_DECLS (int8NDArray, OCTAVE_API) #endif diff -r 38b52a073cfa -r 15eefbd9d4e8 liboctave/oct-inttypes.cc --- a/liboctave/oct-inttypes.cc Fri Aug 26 09:33:52 2011 -0400 +++ b/liboctave/oct-inttypes.cc Fri Aug 26 21:57:23 2011 -0500 @@ -578,6 +578,23 @@ template octave_int +pow (const float& a, const octave_int& b) +{ return octave_int (pow (a, b.float_value ())); } + +template +octave_int +pow (const octave_int& a, const float& b) +{ + return ((b >= 0 && b < std::numeric_limits::digits && b == xround (b)) + ? pow (a, octave_int (static_cast (b))) + : octave_int (pow (a.double_value (), static_cast (b)))); +} + +// FIXME: Do we really need a differently named single-precision +// function integer power function here instead of an overloaded +// one? +template +octave_int powf (const float& a, const octave_int& b) { return octave_int (pow (a, b.float_value ())); } @@ -595,6 +612,8 @@ template OCTAVE_API octave_int pow (const octave_int&, const octave_int&); \ template OCTAVE_API octave_int pow (const double&, const octave_int&); \ template OCTAVE_API octave_int pow (const octave_int&, const double&); \ + template OCTAVE_API octave_int pow (const float&, const octave_int&); \ + template OCTAVE_API octave_int pow (const octave_int&, const float&); \ template OCTAVE_API octave_int powf (const float&, const octave_int&); \ template OCTAVE_API octave_int powf (const octave_int&, const float&); \ template OCTAVE_API octave_int \ diff -r 38b52a073cfa -r 15eefbd9d4e8 liboctave/oct-inttypes.h --- a/liboctave/oct-inttypes.h Fri Aug 26 09:33:52 2011 -0400 +++ b/liboctave/oct-inttypes.h Fri Aug 26 21:57:23 2011 -0500 @@ -874,6 +874,17 @@ template extern OCTAVE_API octave_int +pow (const float& a, const octave_int& b); + +template +extern OCTAVE_API octave_int +pow (const octave_int& a, const float& b); + +// FIXME: Do we really need a differently named single-precision +// function integer power function here instead of an overloaded +// one? +template +extern OCTAVE_API octave_int powf (const float& a, const octave_int& b); template diff -r 38b52a073cfa -r 15eefbd9d4e8 liboctave/uint16NDArray.cc --- a/liboctave/uint16NDArray.cc Fri Aug 26 09:33:52 2011 -0400 +++ b/liboctave/uint16NDArray.cc Fri Aug 26 21:57:23 2011 -0500 @@ -56,3 +56,4 @@ BSXFUN_STDREL_DEFS_MXLOOP (uint16NDArray) BSXFUN_OP_DEF_MXLOOP (pow, uint16NDArray, mx_inline_pow) +BSXFUN_POW_MIXED_MXLOOP (uint16NDArray) diff -r 38b52a073cfa -r 15eefbd9d4e8 liboctave/uint16NDArray.h --- a/liboctave/uint16NDArray.h Fri Aug 26 09:33:52 2011 -0400 +++ b/liboctave/uint16NDArray.h Fri Aug 26 21:57:23 2011 -0500 @@ -44,6 +44,7 @@ MINMAX_DECLS (uint16NDArray, octave_uint16, OCTAVE_API) BSXFUN_STDOP_DECLS (uint16NDArray, OCTAVE_API) +BSXFUN_MIXED_INT_DECLS(uint16NDArray, OCTAVE_API) BSXFUN_STDREL_DECLS (uint16NDArray, OCTAVE_API) #endif diff -r 38b52a073cfa -r 15eefbd9d4e8 liboctave/uint32NDArray.cc --- a/liboctave/uint32NDArray.cc Fri Aug 26 09:33:52 2011 -0400 +++ b/liboctave/uint32NDArray.cc Fri Aug 26 21:57:23 2011 -0500 @@ -56,3 +56,4 @@ BSXFUN_STDREL_DEFS_MXLOOP (uint32NDArray) BSXFUN_OP_DEF_MXLOOP (pow, uint32NDArray, mx_inline_pow) +BSXFUN_POW_MIXED_MXLOOP (uint32NDArray) diff -r 38b52a073cfa -r 15eefbd9d4e8 liboctave/uint32NDArray.h --- a/liboctave/uint32NDArray.h Fri Aug 26 09:33:52 2011 -0400 +++ b/liboctave/uint32NDArray.h Fri Aug 26 21:57:23 2011 -0500 @@ -44,6 +44,7 @@ MINMAX_DECLS (uint32NDArray, octave_uint32, OCTAVE_API) BSXFUN_STDOP_DECLS (uint32NDArray, OCTAVE_API) +BSXFUN_MIXED_INT_DECLS(uint32NDArray, OCTAVE_API) BSXFUN_STDREL_DECLS (uint32NDArray, OCTAVE_API) #endif diff -r 38b52a073cfa -r 15eefbd9d4e8 liboctave/uint64NDArray.cc --- a/liboctave/uint64NDArray.cc Fri Aug 26 09:33:52 2011 -0400 +++ b/liboctave/uint64NDArray.cc Fri Aug 26 21:57:23 2011 -0500 @@ -56,3 +56,5 @@ BSXFUN_STDREL_DEFS_MXLOOP (uint64NDArray) BSXFUN_OP_DEF_MXLOOP (pow, uint64NDArray, mx_inline_pow) +BSXFUN_POW_MIXED_MXLOOP (uint64NDArray) + diff -r 38b52a073cfa -r 15eefbd9d4e8 liboctave/uint64NDArray.h --- a/liboctave/uint64NDArray.h Fri Aug 26 09:33:52 2011 -0400 +++ b/liboctave/uint64NDArray.h Fri Aug 26 21:57:23 2011 -0500 @@ -44,6 +44,7 @@ MINMAX_DECLS (uint64NDArray, octave_uint64, OCTAVE_API) BSXFUN_STDOP_DECLS (uint64NDArray, OCTAVE_API) +BSXFUN_MIXED_INT_DECLS(uint64NDArray, OCTAVE_API) BSXFUN_STDREL_DECLS (uint64NDArray, OCTAVE_API) #endif diff -r 38b52a073cfa -r 15eefbd9d4e8 liboctave/uint8NDArray.cc --- a/liboctave/uint8NDArray.cc Fri Aug 26 09:33:52 2011 -0400 +++ b/liboctave/uint8NDArray.cc Fri Aug 26 21:57:23 2011 -0500 @@ -55,4 +55,6 @@ BSXFUN_STDOP_DEFS_MXLOOP (uint8NDArray) BSXFUN_STDREL_DEFS_MXLOOP (uint8NDArray) +BSXFUN_POW_MIXED_MXLOOP (uint8NDArray) BSXFUN_OP_DEF_MXLOOP (pow, uint8NDArray, mx_inline_pow) + diff -r 38b52a073cfa -r 15eefbd9d4e8 liboctave/uint8NDArray.h --- a/liboctave/uint8NDArray.h Fri Aug 26 09:33:52 2011 -0400 +++ b/liboctave/uint8NDArray.h Fri Aug 26 21:57:23 2011 -0500 @@ -44,6 +44,7 @@ MINMAX_DECLS (uint8NDArray, octave_uint8, OCTAVE_API) BSXFUN_STDOP_DECLS (uint8NDArray, OCTAVE_API) +BSXFUN_MIXED_INT_DECLS(uint8NDArray, OCTAVE_API) BSXFUN_STDREL_DECLS (uint8NDArray, OCTAVE_API) #endif diff -r 38b52a073cfa -r 15eefbd9d4e8 src/OPERATORS/op-int.h --- a/src/OPERATORS/op-int.h Fri Aug 26 09:33:52 2011 -0400 +++ b/src/OPERATORS/op-int.h Fri Aug 26 21:57:23 2011 -0500 @@ -732,7 +732,7 @@ { \ if (is_valid_bsxfun (a_dims, b_dims)) \ { \ - return bsxfun_pow (a, static_cast (b)); \ + return bsxfun_pow (a, b); \ } \ else \ { \ @@ -758,7 +758,7 @@ { \ if (is_valid_bsxfun (a_dims, b_dims)) \ { \ - return bsxfun_pow (static_cast (a), b); \ + return bsxfun_pow (a, b); \ } \ else \ { \ @@ -784,7 +784,7 @@ { \ if (is_valid_bsxfun (a_dims, b_dims)) \ { \ - return bsxfun_pow (a, static_cast (b)); \ + return bsxfun_pow (a, b); \ } \ else \ { \ @@ -810,7 +810,7 @@ { \ if (is_valid_bsxfun (a_dims, b_dims)) \ { \ - return bsxfun_pow (static_cast (a), b); \ + return bsxfun_pow (a, b); \ } \ else \ { \ diff -r 38b52a073cfa -r 15eefbd9d4e8 src/xpow.cc --- a/src/xpow.cc Fri Aug 26 09:33:52 2011 -0400 +++ b/src/xpow.cc Fri Aug 26 21:57:23 2011 -0500 @@ -2598,8 +2598,21 @@ if (a_dims != b_dims) { - gripe_nonconformant ("operator .^", a_dims, b_dims); - return octave_value (); + if (is_valid_bsxfun (a_dims, b_dims)) + { + //Potentially complex results + FloatNDArray xa = octave_value_extract (a); + FloatNDArray xb = octave_value_extract (b); + if (! xb.all_integers () && xa.any_element_is_negative ()) + return octave_value (bsxfun_pow (FloatComplexNDArray (xa), xb)); + else + return octave_value (bsxfun_pow (xa, xb)); + } + else + { + gripe_nonconformant ("operator .^", a_dims, b_dims); + return octave_value (); + } } int len = a.length (); @@ -2673,8 +2686,15 @@ if (a_dims != b_dims) { - gripe_nonconformant ("operator .^", a_dims, b_dims); - return octave_value (); + if (is_valid_bsxfun (a_dims, b_dims)) + { + return bsxfun_pow (a, b); + } + else + { + gripe_nonconformant ("operator .^", a_dims, b_dims); + return octave_value (); + } } FloatComplexNDArray result (a_dims); @@ -2765,8 +2785,15 @@ if (a_dims != b_dims) { - gripe_nonconformant ("operator .^", a_dims, b_dims); - return octave_value (); + if (is_valid_bsxfun (a_dims, b_dims)) + { + return bsxfun_pow (a, b); + } + else + { + gripe_nonconformant ("operator .^", a_dims, b_dims); + return octave_value (); + } } FloatComplexNDArray result (a_dims); @@ -2808,8 +2835,15 @@ if (a_dims != b_dims) { - gripe_nonconformant ("operator .^", a_dims, b_dims); - return octave_value (); + if (is_valid_bsxfun (a_dims, b_dims)) + { + return bsxfun_pow (a, b); + } + else + { + gripe_nonconformant ("operator .^", a_dims, b_dims); + return octave_value (); + } } FloatComplexNDArray result (a_dims);