Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve non-trivial datatypes (#1808)
Move the storage of rank and order from `ast.basic.TypedAstNode` to an internal property of `ast.datatypes.PyccelType` objects (the properties are still exposed via `ast.basic.TypedAstNode`). This allows mixed ordered objects to be described and therefore created (e.g. `list[float[:,:](order=F)]`). A test is added for this case. This change should make #1583 simple to implement. Making the rank and order part of the type fixes #1821 . This provides enough information to allow lists of arrays. Fixes #1721. In order to correctly index types such as `list[float[:,:](order=F)]` the creation of an `IndexedElement` in the syntactic stage is modified. Instead of collapsing all the indices into one `IndexedElement` an `IndexedElement` is created for each `ast.Subscript`. In the semantic stage this is collapsed into one `IndexedElement` for each container. E.g. for the following code: ```python import numpy as np a = (np.ones((3,4)), np.zeros((3,4))) a[0][1][2] ``` On the devel branch after the syntactic stage the last line is described as `IndexedElement('a', (0, 1, 2))`. This persists to the codegen stage. On this branch after the syntactic stage the last line is described as `IndexedElement(IndexedElement(IndexedElement('a', (0,)), (1,)), (2,))`. After the semantic stage it becomes `IndexedElement(IndexedElement('a', (0,)), (1,2))`. The printers are modified to handle this. The generated code is not changed (as support for lists has not yet been added) so the indices are still used together to index a 3D array. **Commit Summary** - Update documentation - Add missing `if __name__ == '__main__'` on old documentation examples. - Remove `static_rank` and `static_order` properties from `pyccel.ast.basic`. These properties are now contained in `static_type`. - Remove `_rank` and `_order` properties from `TypedAstNode`s. - Change `PyccelOperator.set_shape_rank` functions to `PyccelOperator.set_shape` functions (the rank must now be determined at the same time as the type). - Remove `PyccelOperator._set_order` functions. - Simplify homogeneity checks for tuples, lists and sets - Ensure the shape of an empty list/tuple literal is set correctly. - Correct the class type of `CmathPolar` - Remove the `order` argument from the `Allocate` constructor (the information is now retrieved from the order of the allocated variable). - Add the properties `rank` and `order` to `pyccel.ast.datatypes.PyccelType`. - Add a `switch_rank` function to `pyccel.ast.datatypes.HomogeneousContainerType`. - Add a `container_rank` property to `pyccel.ast.datatypes.HomogeneousContainerType`. - Parameterise `NumpyNDArrayType` by the rank and the order - Change the argument of `NumpyNewArray` from `dtype` to `class_type` (to set the rank/order in the subclass). - Allow `NumpyArray` to handle mixed rank objects (e.g. list of F-ordered arrays). - Rename `NumpyUfuncBase._set_shape_rank` to `NumpyUfuncBase._get_shape_rank` and return the shape and rank to avoid saving the rank unnecessarily. - Rename `NumpyUfuncBase._set_order` to `NumpyUfuncBase._get_order` and pass the rank and return the order to avoid saving unnecessarily. - Add docstrings. - Add a `NumpyNDArrayType.__new__` function which redirects rank 0 arrays to scalar types. - Augment `NumpyNDArrayType.__add__` to handle rank and ordering. - Add a `NumpyNDArrayType.swap_order` function to change between C and F ordered equivalent types. - Add `__str__` or `__repr__` functions to `PyccelType`s such that printing them gives a valid type annotation. - Add a `NumpyInt` object to easily find the NumPy integer which has the same precision as Python integers. - Remove `rank` and `order` arguments from `pyccel.ast.type_annotations.VariableTypeAnnotation` constructor (information now available in `class_type`). - Remove `order` property from `pyccel.ast.type_annotations.VariableTypeAnnotation` (`rank` is retained for now). - Update vector expression unravelling functions to handle multiple levels of `IndexedElement`s. - Improve docstrings in `pyccel.ast.utilities`. - Remove `rank` and `order` arguments from `pyccel.ast.variable.Variable` constructor (the information is now retrieved from the `class_type`). - Remove unused property `is_stack_scalar`. - Simplify `is_ndarray` method. - Add `_is_slice` attribute to `IndexedElement` to indicate if an element or a slice of the base is represented. - Add `allows_negative_indexes` property to `IndexedElement`. - Update `_print_IndexedElement` to handle multi-level `IndexedElement`s. - Correct `abs` call in `_print_NumpyNorm` - Improve error message for wrong arguments. - Allocate strings on the stack to avoid calling `Allocate` (to be improved with #459 ). - Remove `get_type_description` (this is now handled by `PyccelType.__str__`). - Provide a traceback to `errors.report` to allow the location of a `TypeError` raised during a `FunctionCall` to be more easily located. - Stop collapsing `ast.Subscript` into one `IndexedElement` object. - Add some mixed ordered tests. - Disable tests with ambiguous interfaces (see #1821).
- Loading branch information
1 parent
1390622
commit e36726f
Showing
42 changed files
with
1,176 additions
and
875 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,3 +113,5 @@ setter | |
bitwise | ||
datatyping | ||
datatypes | ||
indexable | ||
traceback |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.