{{ message }}

# Chaquopy with Scipy.Griddata bugs #68

Closed
opened this issue Nov 29, 2018 · 10 comments
Closed

# Chaquopy with Scipy.Griddata bugs #68

opened this issue Nov 29, 2018 · 10 comments
Labels

### KacemRostom commented Nov 29, 2018 • edited

 Hello, So i tried to use Scipy Griddata function in a small app with the following code. ` import numpy as np` `from scipy.interpolate import griddata` `````` X = np.array([.......]) Y = np.array([.......]) Z = np.array([.......]) D = np.array([.......]) Y0=1 X0=5 points = np.array((X.flatten(), Y.flatten(), Z.flatten())).T values = D.flatten() D0 = griddata(points, values, (X0,Y0,Z0))` `````` I inserted this code inside the Chaquopy Demo app, in ui_demo.py exactly. Inside "def onCreate(self, state):" function. The app takes about 5 mins to open the screen, sometimes never. Ofc the app works perfectly without this chunk of code. Is there a way i could use to speedup the code. It's really a small code and i intend to develop a small app that interpolate a small set of data thanks to Python Numpy and Scipy capabilities. No plotting, just that specific small of code that returns a float value. Just for info this is what i intend to achieve: I have a set of data for example: X Y Z 1 3 7 2 5 8 1 4 9 3 6 10 I would like to interpolate Z for X=2.5 and Y=3.5. I can use interp2.griddata from Scipy in Python or ScatteredInterpolant in Matlab like this: `z = griddata( [1 2 1 3], [3 5 4 6], [7 8 9 10], 2.5, 3.5, 'nearest' ) `or `S = scatteredInterpolant(x,y,z,d); `Is there a way i could use something similar in Swift/Objective-c or any other compatible language to develop a small app for iOS (as well as for Android if possible) where i insert scattered data and when the user enter a value for a given X and Y he gets an interpolated value for Z (i intend to use this with 4D dimension). The text was updated successfully, but these errors were encountered:
changed the title Chaquopy with Scipy bugs Chaquopy with Scipy.Griddata bugs Nov 29, 2018

### mhsmith commented Nov 29, 2018

 How much slower is the code on Android compared to other operating systems? If it is significantly slower, which part of it is slow? (Try inserting print statements so you can see when each line is reached.)

### KacemRostom commented Nov 29, 2018 • edited

 How much slower is the code on Android compared to other operating systems? If it is significantly slower, which part of it is slow? (Try inserting print statements so you can see when each line is reached.) I use Scipy on my Macbook as well as on my Android phone through IDE Pydroid 3 (which is an Android app that permits to run Python code) and it runs almost instantly. The code takes more than 5 mins for the same set of data on Chaquopy and it stuck at this specific instruction: ``````D0 = griddata(points, values, (X0,Y0,Z0))` `````` So basically at computing the interpolation value.

### mhsmith commented Nov 29, 2018

 How big are these datasets?

### KacemRostom commented Nov 30, 2018 • edited

 How big are these datasets? About 50 elements in each dimension. So each table has about 50 elements x 3. But again it runs almost instantly using an IDE on the same device. If i could just speedup this portion of code it would be terrific.

### mhsmith commented Nov 30, 2018

 OK, thanks, we'll take a look.

### KacemRostom commented Nov 30, 2018

 OK, thanks, we'll take a look. If you lik i could send you the project to try it from your side.

### mhsmith commented Dec 3, 2018 • edited

 I can confirm that `griddata` hangs forever on a physical device even for simple examples, and crashes on the emulator. Your simple X=2.5 and Y=3.5 example would never actually work with `griddata` because those coordinates are outside the convex hull of the dataset. In this case `Rbf` might be more appropriate, but unfortunately that crashes or hangs in the same way. We'll try updating SciPy and NumPy to the newest versions as soon as possible. Meanwhile, if your data is 2-dimensional, `interp2d` does work, though it may give extreme results for coordinates which are far away from the dataset.
added the bug label Dec 3, 2018

### KacemRostom commented Dec 7, 2018

 Thanks, i'll keep following the thread and if there is something we can do to help, let us know.

### mhsmith commented Dec 17, 2018 • edited

 We've added a new build of OpenBLAS to the repository which fixes this issue. To make your build re-check the repository, just make any change to your `pip` block in `build.gradle`: even reordering the packages should be enough. Although it wasn't the source of the problem, we've also taken the opportunity to add the current version of SciPy, 1.1.0.
closed this Dec 17, 2018

### KacemRostom commented Dec 22, 2018

 It worked! Very much appreciated sir!