class devito.types.TensorFunction(*args, **kwargs)[source]

Bases: AbstractTensor

Tensor valued Function represented as a Matrix. Each component is a Function or TimeFunction.

A TensorFunction and the classes that inherit from it takes the same parameters as a DiscreteFunction and additionally:

  • name (str) – Name of the symbol.

  • grid (Grid, optional) – Carries shape, dimensions, and dtype of the TensorFunction. When grid is not provided, shape and dimensions must be given. For MPI execution, a Grid is compulsory.

  • space_order (int or 3-tuple of ints, optional) – Discretisation order for space derivatives. Defaults to 1. space_order also impacts the number of points available around a generic point of interest. By default, space_order points are available on both sides of a generic point of interest, including those nearby the grid boundary. Sometimes, fewer points suffice; in other scenarios, more points are necessary. In such cases, instead of an integer, one can pass a 3-tuple (o, lp, rp) indicating the discretization order (o) as well as the number of points on the left (lp) and right (rp) sides of a generic point of interest.

  • shape (tuple of ints, optional) – Shape of the domain region in grid points. Only necessary if grid isn’t given.

  • dimensions (tuple of Dimension, optional) – Dimensions associated with the object. Only necessary if grid isn’t given.

  • dtype (data-type, optional) – Any object that can be interpreted as a numpy data type. Defaults to np.float32.

  • staggered (tuple of Dimension, optional) – Define how the TensorFunction is staggered.

  • initializer (callable or any object exposing the buffer interface, optional) – Data initializer. If a callable is provided, data is allocated lazily.

  • allocator (MemoryAllocator, optional) – Controller for memory allocation. To be used, for example, when one wants to take advantage of the memory hierarchy in a NUMA architecture. Refer to default_allocator.__doc__ for more information.

  • padding (int or tuple of ints, optional) –

    Deprecated since version shouldn’t: be used; padding is now automatically inserted.

    Allocate extra grid points to maximize data access alignment. When a tuple of ints, one int per Dimension should be provided.

  • symmetric (bool, optional) – Whether the tensor is symmetric or not. Defaults to True.

  • diagonal (Bool, optional) – Whether the tensor is diagonal or not. Defaults to False.

  • staggered – Staggering of each component, needs to have the size of the tensor. Defaults to the Dimensions.

property is_diagonal

Whether the tensor is diagonal.


Check if matrix is symmetric matrix, that is square matrix and is equal to its transpose.

By default, simplifications occur before testing symmetry. They can be skipped using ‘simplify=False’; while speeding things a bit, this may however induce false negatives.


>>> from sympy import Matrix
>>> m = Matrix(2, 2, [0, 1, 1, 2])
>>> m
[0, 1],
[1, 2]])
>>> m.is_symmetric()
>>> m = Matrix(2, 2, [0, 1, 2, 0])
>>> m
[0, 1],
[2, 0]])
>>> m.is_symmetric()
>>> m = Matrix(2, 3, [0, 0, 0, 0, 0, 0])
>>> m
[0, 0, 0],
[0, 0, 0]])
>>> m.is_symmetric()
>>> from sympy.abc import x, y
>>> m = Matrix(3, 3, [1, x**2 + 2*x + 1, y, (x + 1)**2, 2, 0, y, 0, 3])
>>> m
[         1, x**2 + 2*x + 1, y],
[(x + 1)**2,              2, 0],
[         y,              0, 3]])
>>> m.is_symmetric()

If the matrix is already simplified, you may speed-up is_symmetric() test by using ‘simplify=False’.

>>> bool(m.is_symmetric(simplify=False))
>>> m1 = m.expand()
>>> m1.is_symmetric(simplify=False)
property space_dimensions

Spatial dimensions.


The space order for all components.