-
Notifications
You must be signed in to change notification settings - Fork 119
Tensor spaces, second try #861
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
Conversation
f530983 to
8a6d51f
Compare
59b0936 to
ee061ea
Compare
Regarding this topic: I have implemented a simple indexing capability for spaces, but it is nowhere near as powerful and flexible as the lazy approach of simply indexing the array and appropriately wrap whatever comes out. arr = self.data[indices]
return self.space[indices].element(arr)is much much less powerful than lazy indexing, if we don't put great amounts of work into it. So I'd say the space indexing can be used for simple things like >>> space = odl.rn((2, 3, 4))
>>> space[[0, 2]]
rn((2, 4))
>>> space[0]
rn(2)but not for indexing of elements. |
I realized that indexing like this is not really helpful since it's not compatible with power spaces. I'll think about it a bit more. |
|
Is this in a state where it needs a review? If so I guess I need to get at it. |
Yes it is. I deliberately didn't mention it so nobody burns time at it that they don't have :-) |
|
Could you do the rebase from master first? It seems rather big. |
Yes, I've also spotted some glitches that I want to fix along the way. |
6a1dd6e to
5292f10
Compare
|
Rebased |
adler-j
left a comment
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.
Huge review done, but mostly small things. I have not reviewed the tests yet, will do that later on.
On the larger scale, I have a few comments:
- The support for
DiscreteLpwith vector/tensor valued functions needs to be added and properly supported. This is the largest out-standing problem with this. - That all examples default to
shape=(2,3)makes the doc much harder to read and adds little. I understand that during development this is important, but in release we should trim this in general, just like we dont usedtype='float32'everywhere. - You have added
__hash__in a few places where it shouldn't, i.e. in mutable objects. Also I think you may have missed adding__ne__in some places, check that. - The
matrix_representation/MatrixOperatorthing needs to be fixed, but could use a new issue.
|
|
||
| x0 = np.arange(fn.size) | ||
| x = fn.element(x0) | ||
| x0 = np.arange(tspace.size) |
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.
tspace.shape?
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.
Haven't looked much into this file, probably needs more love
| Adding Fn spaces | ||
| ---------------- | ||
| The abstract spaces `FnBase` and `NtuplesBase` are the workhorses of the ODL space machinery. They are used in both the discrete :math:`R^n` case, as well as data representation for discretized function spaces such as :math:`L^2([0, 1])` in the `DiscretizedSpace` class. These are in general created through the `rn` and `uniform_discr` functions who take an ``impl`` parameter, allowing users to select the backend to use. | ||
| Adding Tensor spaces |
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.
Skipping the doc for now.
doc/source/generate_doc.py
Outdated
| def import_submodules(package, name=None, recursive=True): | ||
| """ Import all submodules of a module, recursively, including subpackages | ||
| """ | ||
| """Recursively import all submodules of ``package``.""" |
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.
Improve. I guess it returns the names etc?
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.
will check
| array-like | ||
| Any data structure which can be converted into a `numpy.ndarray` by the | ||
| `numpy.array` constructor. Includes all `NtuplesBaseVector` based classes. | ||
| `numpy.array` constructor. Includes all `Tensor` based classes. |
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.
The NtuplesBaseVector -> Tensor may be our best rename in a long time!
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.
Yeah scrap those shitty old names!
doc/source/guide/glossary.rst
Outdated
| discretization | ||
| Structure to handle the mapping between abstract objects (e.g. functions) and concrete, finite realizations. | ||
| It encompasses an abstract `Set`, a finite data container (`NtuplesBaseVector` in general) and the mappings between them, :term:`sampling` and :term:`interpolation`. | ||
| It encompasses an abstract `Set`, a finite data container (`GeneralizedTensor` in general) and the mappings between them, :term:`sampling` and :term:`interpolation`. |
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.
Didn't we scrap GeneralizedTensor?
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, needs to be replaced
odl/space/pspace.py
Outdated
| return ProductSpace(*self.spaces[indices], field=self.field) | ||
| elif isinstance(indices, tuple): | ||
| if len(indices) > 1: | ||
| raise ValueError('too many indices: {}'.format(indices)) |
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.
Another option is to pass these through further down, i.e.
return ProductSpace(self.spaces[indices[0]][indices[1:]], field=self.field)
odl/space/pspace.py
Outdated
| odl.discr.lp_discr.DiscreteLpElement.show : | ||
| Display of a discretized function | ||
| odl.space.base_ntuples.NtuplesBaseVector.show : | ||
| odl.space.base_tensors.GeneralizedTensor.show : |
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.
find replace GeneralizedTensor
odl/space/space_utils.py
Outdated
| impl : string, optional | ||
| The backend to use. See `odl.space.entry_points.NTUPLES_IMPLS` and | ||
| `odl.space.entry_points.FN_IMPLS` for available options. | ||
| order : {'C', 'F'}, optional |
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.
'A'?
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.
Clearly missing
odl/space/space_utils.py
Outdated
| `odl.space.entry_points.FN_IMPLS` for available options. | ||
| order : {'C', 'F'}, optional | ||
| Axis ordering of the data storage. | ||
| impl : str |
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.
optional
odl/space/weighting.py
Outdated
| if not np.isfinite(self.const): | ||
| raise ValueError('`const` {} is invalid'.format(const)) | ||
|
|
||
| def __hash__(self): |
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.
Prefer if __hash__ is always right after __eq__ since they are so strongly connected.
|
Thanks a lot for the detailed review @adler-j, will try to get this done asap. |
odl/space/npy_tensors.py
Outdated
| Parameters | ||
| ---------- | ||
| matrix : `array-like` or `scipy.sparse.base.spmatrix` | ||
| 2-dimensional array representing the linear operator. |
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.
You use a 3 dimensional array later.
Anyway, if we allow 2+, why not allow 1d as well, in which case this is an inner product.
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.
Wrong place again, you need to hack it apparently.
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.
The comment is w.r.t MatrixOperator where you assume the matrix is 2 or higher dimensional. I can easily see this working with 1 or even 0 dimensional arrays, so that condition is arbitrary.
The line "You use a 3 dimensional array later." refers to a comment that MatrixOperator input should be 2d, but you later use 3d. Also you later say that axis needs to be 1 or more, but the default is 0.
4fcd3a7 to
3183484
Compare
ebddf98 to
ac45d52
Compare
|
What is the review status on this? |
I figured that sampling would need tensor-valued functions, so I implemented them. Now I'm in the middle of writing/fixing the tests for those. |
|
Can you re-open this for a new review, if you want one, else we really want to go ahead here. |
|
After thinking about it some more, I think the following way of indexing spaces is most reasonable:
Opinions? |
|
The page for this PR has become unworkable once again, opening a new one. |
Copied from #753
TODOs:
NtuplesBase,FnBase,NumpyNtuplesandNumpyFnin the corresponding tensor classesNtuplesand related stuffNtuplesand the likes as special case to tensor classesMatVecOperatorMatrixOperator, see Reload modules in Spyder causes bugs #584. Solved in Issue 910 matvec op #911lp_discr, ...)TensorSetand others (see Scrap FunctionSet, DiscretizedSet and similar #860) duck-type space propertiesUse notion "rank" instead of "number of dimensions" to better distinguish betweenNot doing thisspace.ndimandspace.sizeTensorSpace.Done, but kind of wrong, see here and hereDone properly nowWrite extra documentation on tensorsShould be part of Representing vector- and tensor-valued functions #908showmethods (1D fromNtuples, 2D fromDiscreteLp)FunctionSpaceElementin 1D (again)FunctionSpaceas__getitem__byaxisattributeDiscreteLpas inFunctionSpace__array_ufunc__interface onTensorandNumpyTensor(the latter only differs in weight propagation)__array_ufunc__interface onDiscreteLpElement__array_ufunc__intefaces (bad input etc.)