4

I got a matrix 'x' of float128 values and I am getting the next error when:

> q = (inv(xt * x) * xt) * n
> array type float128 is unsupported in linalg

Where xt is transposed x and n other float128 matrix. All Other operations with that matrix are handled correctly like transposing or matrix product.

Yes I need float128 for this case, otherwise the results are differing from the ones closer to real values we are taking as reference.

gerosalesc
  • 2,983
  • 3
  • 27
  • 46
  • This error message seems pretty straightforward to me: float128 support in NumPy is not complete or consistent. – xnx Jan 07 '16 at 17:28
  • @xnx It is, i need a workaround :p – gerosalesc Jan 07 '16 at 17:31
  • This sounds a bit like an [XY problem](http://xyproblem.info). If you're testing computed floating-point results against expected reference results, you can't hope for exact equality anyway, so you'll need to build a tolerance into your test; no amount of extra precision is going to make that need go away. (Of course, what that tolerance should be is another hard and task-dependent question.) Are you *sure* you need the extra precision? – Mark Dickinson Jan 07 '16 at 17:51
  • 4
    One other comment: from the code you show, it looks as though you're solving a least squares problem. Is there any reason you're not using the existing NumPy and SciPy routines for least squares? Those are likely to more numerically robust than a home-grown version. (In particular, actually inverting `xt*x` is not the most efficient or stable way to go about solving a least squares problem.) – Mark Dickinson Jan 07 '16 at 17:52
  • 1
    Relevant: http://www.johndcook.com/blog/2010/01/19/dont-invert-that-matrix/. It is almost never a good idea to directly invert a matrix. – ali_m Jan 07 '16 at 18:10
  • @MarkDickinson The end purpose of the function is to fit a curve with 3 variables using a cubic function like this `z = c0 + c1x + c2y + c3xy +...`, the math guy of this project suggested we could use this method and he even tested it in Excel (jmm yes Excel) and got close even tough the difference for the end results against the real thing are really important. I tried without luck the scipy's curve_fit, but I guess this could make another question. – gerosalesc Jan 07 '16 at 18:33

1 Answers1

0

There is no float128 data type in numpy. The supported numpy data types can be found here: http://docs.scipy.org/doc/numpy-1.10.1/user/basics.types.html

If you need a work around you could try to use NPY_LONGDOUBLE from the numpy C API http://docs.scipy.org/doc/numpy-1.10.0/reference/c-api.dtype.html

veda905
  • 782
  • 2
  • 12
  • 32
  • 4
    That depends on the platform. On OS X, there *is* `numpy.float128` dtype, though it doesn't give you the IEEE 754 binary128 format that you might hope. It corresponds to the standard 80-bit x87 extended precision type, with 6 bytes of padding. (Similarly, on Linux there's usually a `numpy.float96` dtype.) – Mark Dickinson Jan 07 '16 at 17:42
  • More info here in the excellent answer from Nathaniel Smith here: http://stackoverflow.com/a/17023995/270986 – Mark Dickinson Jan 07 '16 at 17:46
  • That is a good post, it explains things well. It seems my answer does not really answer the question, but could point to a way to answer it if `longdouble` is the way to go. – veda905 Jan 07 '16 at 17:58
  • I suspect that the OP is already *using* `np.longdouble`. That's the cause of the problem! The support for the `np.longdouble` type doesn't go all the way down to the core linear algebra operations. – Mark Dickinson Jan 07 '16 at 18:02