-
Notifications
You must be signed in to change notification settings - Fork 168
Scoping numba performance #1135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
cfe8351
601c9a6
ebf7977
d19c768
5c59c0b
b32dd00
65cd608
d24dd77
85e9631
e321fbf
cf5cd3c
95d76cd
7c8b99e
f0624a3
f9752c1
00a07a5
c69f7f9
eda6b38
27340f0
ae90dea
76e339d
a92bad1
db88090
2a8f657
b9631ef
3637fc2
c105e5f
566ce0a
be3066b
6dea491
ae08689
424cd21
9e81072
de01f20
c6a250c
afff754
7a8732b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,9 @@ | |
|
|
||
| from parcels.collection.collections import ParticleCollection | ||
| from parcels.collection.iterators import BaseParticleAccessor | ||
| from parcels.collection.iterators import BaseParticleCollectionIterator, BaseParticleCollectionIterable | ||
| from parcels.particle import ScipyParticle, JITParticle # noqa | ||
| from parcels.collection.iterators import BaseParticleCollectionIterator | ||
| from parcels.collection.iterators import BaseParticleCollectionIterable | ||
| from parcels.particle import ScipyParticle | ||
| from parcels.field import Field | ||
| from parcels.tools.loggers import logger | ||
| from parcels.tools.statuscodes import OperationCode | ||
|
|
@@ -130,16 +131,12 @@ def __init__(self, pclass, lon, lat, depth, time, lonlatdepth_dtype, pid_orig, p | |
| self._pclass = pclass | ||
|
|
||
| self._ptype = pclass.getPType() | ||
| self._data = {} | ||
| initialised = set() | ||
|
|
||
| self._ncount = len(lon) | ||
|
|
||
| for v in self.ptype.variables: | ||
| if v.name in ['xi', 'yi', 'zi', 'ti']: | ||
| self._data[v.name] = np.empty((len(lon), ngrid), dtype=v.dtype) | ||
| else: | ||
| self._data[v.name] = np.empty(self._ncount, dtype=v.dtype) | ||
| self._data = np.empty(self.ncount, dtype=self.ptype.dtype).view(np.recarray) | ||
| self._pbackup = np.empty(1, dtype=self.ptype.dtype).view(np.recarray) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, okay - this is how you circumvented the issue of backing-up the flex-definition particles. K. |
||
| self._data.lat = lat | ||
|
|
||
| if lon is not None and lat is not None: | ||
| # Initialise from lists of lon/lat coordinates | ||
|
|
@@ -155,7 +152,7 @@ def __init__(self, pclass, lon, lat, depth, time, lonlatdepth_dtype, pid_orig, p | |
| self._data['fileid'][:] = -1 | ||
|
|
||
| # special case for exceptions which can only be handled from scipy | ||
| self._data['exception'] = np.empty(self.ncount, dtype=object) | ||
| # self._data['exception'] = np.empty(self.ncount, dtype=object) | ||
|
|
||
| initialised |= {'lat', 'lon', 'depth', 'time', 'id'} | ||
|
|
||
|
|
@@ -175,7 +172,7 @@ def __init__(self, pclass, lon, lat, depth, time, lonlatdepth_dtype, pid_orig, p | |
| for i in range(self.ncount): | ||
| if (time[i] is None) or (np.isnan(time[i])): | ||
| raise RuntimeError('Cannot initialise a Variable with a Field if no time provided (time-type: {} values: {}). Add a "time=" to ParticleSet construction'.format(type(time), time)) | ||
| v.initial.fieldset.computeTimeChunk(time[i], 0) | ||
| # v.initial.fieldset.computeTimeChunk(time[i], 0) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, without this line, the whole content between l. 171 and l. 179 is not workable. The thing is: without calling the fieldset to compute the timechunk, the field(s) has/have no data if one wants to do field sampling. So, either make it work with the `computeTimeChunk' call, or comment / circumvent all code between l.171-179.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I agree. The problem is that this method is simply not implemented yet in numba. When/if it is it should be uncommented. |
||
| self._data[v.name][i] = v.initial[ | ||
| time[i], depth[i], lat[i], lon[i] | ||
| ] | ||
|
|
@@ -234,7 +231,7 @@ def __getattr__(self, name): | |
| :param name: name of the property | ||
| """ | ||
| for v in self.ptype.variables: | ||
| if v.name == name and name in self._data: | ||
| if v.name == name and name in list(self._data.dtype.fields): | ||
| return self._data[name] | ||
| return False | ||
|
|
||
|
|
@@ -441,8 +438,7 @@ def add_same(self, same_class): | |
| if not (same_class._sorted | ||
| and self._data['id'][-1] < same_class._data['id'][0]): | ||
| self._sorted = False | ||
| for d in self._data: | ||
| self._data[d] = np.concatenate((self._data[d], same_class._data[d])) | ||
| self._data = np.concatenate((self._data, same_class._data)) | ||
| self._ncount += same_class.ncount | ||
|
|
||
| def __iadd__(self, same_class): | ||
|
|
@@ -556,8 +552,7 @@ def remove_single_by_index(self, index): | |
| """ | ||
| super().remove_single_by_index(index) | ||
|
|
||
| for d in self._data: | ||
| self._data[d] = np.delete(self._data[d], index, axis=0) | ||
| self._data = np.delete(self._data, index) | ||
|
|
||
| self._ncount -= 1 | ||
|
|
||
|
|
@@ -644,8 +639,8 @@ def remove_multi_by_indices(self, indices): | |
| if type(indices) is dict: | ||
| indices = list(indices.values()) | ||
|
|
||
| for d in self._data: | ||
| self._data[d] = np.delete(self._data[d], indices, axis=0) | ||
| if len(indices): | ||
| self._data = np.delete(self._data, indices) | ||
|
|
||
| self._ncount -= len(indices) | ||
|
|
||
|
|
||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, totally understand this change - the flex-parameter 'field.evel(*kwargs)' function is not auto-convertable to C or C++.
Good change.