← Reference · Nestor G Pestelos Jr · Print this page

Mathematics · Computer Science

Tensor (Mathematics and Computing)

Reference entry · last updated September 11, 2026

A tensor is an algebraic object that maps geometric and physical vectors to scalars in a multilinear fashion, or, in computational systems, a multidimensional array of numerical values indexed across an arbitrary number of discrete dimensions.[1, 2] While differential geometry and theoretical physics treat tensors as multilinear maps governed by strict coordinate-transformation laws, modern computing platforms like PyTorch, TensorFlow, and dedicated accelerator silicon treat tensors as contiguous or strided memory buffers equipped with dimension metadata. Tensors serve as the fundamental data substrate for neural network representations, deep learning parameter storage, and distributed accelerator workloads.

1. First Principles: Multilinear Algebra and Tensor Products

Modern tensor theory rests on the foundations of multilinear algebra. Rather than beginning with coordinate tables or index grids, modern mathematics defines a tensor by its coordinate-free algebraic behavior when acting on vector spaces and their linear duals.[1]

1.1 Dual Spaces and Multilinear Maps

Let \(V\) be a finite-dimensional vector space over a field \(\mathbb{F}\) (typically \(\mathbb{R}\) or \(\mathbb{C}\)). The dual space \(V^*\) consists of all linear functionals \(f: V \to \mathbb{F}\). Given vector spaces \(V_1, V_2, \dots, V_k\), a function

$$\phi: V_1 \times V_2 \times \dots \times V_k \to \mathbb{F}$$

is multilinear if it is linear in each argument independently when holding all other arguments fixed. That is, for any index \(i \in \{1, \dots, k\}\), scalars \(\alpha, \beta \in \mathbb{F}\), and vectors \(u, v \in V_i\):

$$\phi(v_1, \dots, \alpha u + \beta v, \dots, v_k) = \alpha \phi(v_1, \dots, u, \dots, v_k) + \beta \phi(v_1, \dots, v, \dots, v_k)$$

A tensor of type \((r, s)\) on \(V\) is formally defined as a multilinear map that takes \(r\) dual vectors and \(s\) vectors as inputs to produce a scalar:

$$T: \underbrace{V^* \times \dots \times V^*}_{r \text{ copies}} \times \underbrace{V \times \dots \times V}_{s \text{ copies}} \to \mathbb{F}$$

The integer \(r\) denotes the contravariant order, \(s\) denotes the covariant order, and the sum \(r + s\) defines the total rank (or valence) of the tensor.[2]

1.2 The Universal Property of the Tensor Product

Multilinear maps with fixed domain spaces and codomain form a vector space under pointwise addition and scalar multiplication. A bilinear map is generally not jointly linear on the Cartesian product \(V \times W\). The tensor product \(V \otimes W\) lets each such map factor through a unique linear map.[9]

Formally, the tensor product of vector spaces \(V\) and \(W\) is a vector space \(V \otimes W\) accompanied by a bilinear map \(\tau: V \times W \to V \otimes W\), denoted \(\tau(v, w) = v \otimes w\), satisfying the universal property: for every vector space \(U\) and every bilinear map \(B: V \times W \to U\), there exists a unique linear map \(\tilde{B}: V \otimes W \to U\) such that \(B = \tilde{B} \circ \tau\).

$$\dim(V \otimes W) = \dim(V) \times \dim(W)$$

If \(\{e_i\}\) forms a basis for \(V\) of dimension \(m\), and \(\{f_j\}\) forms a basis for \(W\) of dimension \(n\), then the set of simple tensors \(\{e_i \otimes f_j\}\) forms a basis for \(V \otimes W\) of dimension \(m \cdot n\). Any arbitrary tensor \(T \in V \otimes W\) decomposes into a linear combination of these basis elements:

$$T = \sum_{i=1}^m \sum_{j=1}^n T^{ij} (e_i \otimes f_j)$$

1.3 Tensor Type, Covariance, and Contravariance

Tensors are classified according to how their arguments relate to vectors and linear functionals:

2. Coordinate Systems and Transformation Laws

When coordinates are introduced on an underlying manifold or vector space, the components of a tensor transform in a specific manner under a smooth change of coordinates.[2]

2.1 Change of Basis and Index Notation

Consider a coordinate change from \(\{x^\mu\}\) to \(\{\tilde{x}^\alpha\}\). The Jacobian matrix of partial derivatives governs the local transformation:

$$J^\alpha_{\ \mu} = \frac{\partial \tilde{x}^\alpha}{\partial x^\mu}, \quad (J^{-1})^\mu_{\ \alpha} = \frac{\partial x^\mu}{\partial \tilde{x}^\alpha}$$

A tensor of type \((r, s)\) with components \(T^{\mu_1 \dots \mu_r}_{\ \nu_1 \dots \nu_s}\) transforms to the new coordinate basis according to the general multilinear transformation law:

$$\tilde{T}^{\alpha_1 \dots \alpha_r}_{\ \beta_1 \dots \beta_s} = \left( \prod_{i=1}^r \frac{\partial \tilde{x}^{\alpha_i}}{\partial x^{\mu_i}} \right) \left( \prod_{j=1}^s \frac{\partial x^{\nu_j}}{\partial \tilde{x}^{\beta_j}} \right) T^{\mu_1 \dots \mu_r}_{\ \nu_1 \dots \nu_s}$$

Contravariant indices (superscripts) transform via the forward Jacobian matrix \(\frac{\partial \tilde{x}^\alpha}{\partial x^\mu}\), opposing the transformation of basis vectors. Covariant indices (subscripts) transform via the inverse Jacobian matrix \(\frac{\partial x^\nu}{\partial \tilde{x}^\beta}\), in the same manner as basis vectors.

2.2 Einstein Summation Convention

Introduced by Albert Einstein in 1916, index summation notation omits explicit summation signs when an index appears once as an upper index and once as a lower index within a single term:

$$A^\mu B_\mu \equiv \sum_{\mu=1}^n A^\mu B_\mu$$

Indices that appear matched are dummy indices, representing summation. Unmatched indices are free indices, indicating the tensorial rank and dimension of the resulting expression. Contracting a contravariant index with a covariant index reduces the total tensor order by 2 (reducing an \((r, s)\) tensor to an \((r-1, s-1)\) tensor).

2.3 Geometric Invariance

While numerical component representations change based on the choice of basis, the underlying tensor object remains coordinate-independent. In differential geometry, tensor fields assign a multilinear map to each tangent space \(T_p M\) and cotangent space \(T_p^* M\) of a smooth manifold \(M\). If all components of a tensor vanish in one coordinate frame, the transformation laws dictate that they vanish in every coordinate frame, making tensor equations the natural language for physical laws (general covariance).[2]

3. Computational Tensors and Multidimensional Arrays

In computer science, software engineering, and machine learning, the word tensor carries a pragmatic, operational definition distinct from its mathematical namesake.[3, 4]

3.1 The Terminology Gap: Geometric Tensor vs. Data Array

A computational tensor is an \(N\)-dimensional numerical array characterized by:

In pure mathematics, an arbitrary 3D array of numbers is not necessarily a tensor unless it satisfies coordinate transformation laws under a change of basis. In computing frameworks, any multidimensional table of numerical values is termed a tensor regardless of variance or coordinate behavior.

3.2 Strides, Offsets, and Contiguous Memory Layouts

Let \((s_0, s_1, \dots, s_{N-1})\) be a stride tuple measured in elements, and let itemsize be the number of bytes per element. With zero-based indices and byte_offset measured from the storage start to the first logical element, the byte offset of an element is:

$$\text{offset} = \text{byte\_offset} + \text{itemsize} \cdot \sum_{k=0}^{N-1} i_k \cdot s_k$$

For a C-contiguous int32 array shaped (2, 3, 4), the element strides are (12, 4, 1). Index (1, 1, 1) lies 4 × (12 + 4 + 1) = 68 bytes from its first element. NumPy reports strides in bytes: (48, 16, 4) for this array.[10]

The two primary ordering conventions for dense arrays, using element strides, are:

3.3 Zero-Copy Views vs. Memory Allocations

Modern machine learning frameworks decouple logical shape metadata from underlying memory storage:[4]

Operations such as slicing, transposing (permuting dimensions), expanding (broadcasting), and squeezing manipulate only shape and stride tuples. These operations execute in \(O(1)\) constant time without copying underlying bytes. A tensor becomes non-contiguous when its strides deviate from standard row-major progression (for instance, after a transpose). Calling operations that expect contiguous bytes requires an explicit copy step (such as PyTorch's .contiguous()) to reorder memory sequentially.

4. Tensor Operations and Decompositions

High-order data collections quickly become intractable due to exponential growth in parameters. Tensor decompositions generalize matrix factorizations (such as SVD and Eigendecomposition) to higher dimensions.[5]

4.1 Tensor Contractions and Outer Products

Fundamental operations define transformations on multidimensional arrays:

4.2 Canonical Polyadic (CP) Decomposition

The Canonical Polyadic (CP) decomposition (also known as CANDECOMP/PARAFAC) factorizes a tensor \(\mathcal{X} \in \mathbb{R}^{I \times J \times K}\) into a sum of component rank-1 tensors:[5]

$$\mathcal{X} \approx \sum_{r=1}^R a_r \otimes b_r \otimes c_r$$

where \(a_r \in \mathbb{R}^I\), \(b_r \in \mathbb{R}^J\), \(c_r \in \mathbb{R}^K\), and \(R\) is the chosen number of components in the approximation. The CP rank of \(\mathcal{X}\) is the minimum number of rank-1 terms needed for exact equality. Rank-1 means an outer product of vectors. CP rank differs from the number of axes, called order or rank in Section 3.1. Unlike matrix rank, determining the exact CP rank of a general 3D tensor is an NP-hard problem, and the best rank-\(R\) approximation may not always exist due to non-closed solution spaces.

4.3 Tucker Decomposition and Tensor Trains

Tucker Decomposition: A higher-order form of Principal Component Analysis (PCA). It decomposes a tensor into a small dense core tensor \(\mathcal{G} \in \mathbb{R}^{P \times Q \times R}\) multiplied by orthogonal factor matrices along each mode:

$$\mathcal{X} \approx \mathcal{G} \times_1 A \times_2 B \times_3 C$$

Tensor Train (TT) Decomposition: Mitigates the curse of dimensionality for very high orders by factorizing an \(N\)-way tensor into a linear chain of interconnected 3D core tensors. TT decomposition compresses parameter counts from exponential \(O(d^N)\) to polynomial \(O(N \cdot d \cdot r^2)\), enabling simulation of quantum many-body states and low-rank compression of neural network weights.[6]

5. Tensors in Deep Learning Systems and Hardware

In modern artificial intelligence, neural networks are constructed as computational graphs where nodes represent mathematical transformations and edges represent flowing data tensors.[3]

5.1 Automatic Differentiation and Execution Graphs

Deep learning frameworks compute gradients across thousands of tensor variables using reverse-mode automatic differentiation (backpropagation). During the forward pass, frameworks record operations in a Directed Acyclic Graph (DAG). Each tensor node tracks:

During the backward pass, vector-Jacobian products (VJPs) traverse the graph in reverse topological order, accumulating partial derivatives directly into parameter gradient buffers.

5.2 Systolic Arrays and Tensor Cores

General-purpose CPUs execute sequential scalar or small vector SIMD instructions. Because deep learning workloads are dominated by large matrix multiplications and convolutions, modern AI accelerators incorporate specialized 2D arithmetic matrix hardware:[7]

5.3 Tensor Parallelism and Model Sharding

When large language model parameter tensors exceed the memory capacity of a single GPU (e.g., 70B+ parameters), distributed frameworks split individual weight tensors across multiple accelerators using Tensor Parallelism (Megatron-LM):[8]

See Also

References

  1. S. Axler, Linear Algebra Done Right, 3rd ed. Cham: Springer, 2015. DOI: 10.1007/978-3-319-11080-6
  2. J. M. Lee, Introduction to Smooth Manifolds, 2nd ed. New York: Springer, 2013. DOI: 10.1007/978-1-4419-9982-5
  3. M. Abadi et al., "TensorFlow: A System for Large-Scale Machine Learning," in 12th USENIX Symposium on Operating Systems Design and Implementation (OSDI 16), 2016, pp. 265–283. URL: https://www.usenix.org/conference/osdi16/technical-sessions/presentation/abadi
  4. A. Paszke et al., "PyTorch: An Imperative Style, High-Performance Deep Learning Library," in Advances in Neural Information Processing Systems (NeurIPS), vol. 32, 2019, pp. 8026–8037. Free full text: https://arxiv.org/abs/1912.01703
  5. T. G. Kolda and B. W. Bader, "Tensor Decompositions and Applications," SIAM Review, vol. 51, no. 3, pp. 455–500, 2009. DOI: 10.1137/07070111X
  6. I. V. Oseledets, "Tensor-Train Decomposition," SIAM Journal on Scientific Computing, vol. 33, no. 5, pp. 2295–2317, 2011. DOI: 10.1137/090752286
  7. N. P. Jouppi et al., "In-Datacenter Performance Analysis of a Tensor Processing Unit," in Proceedings of the 44th Annual International Symposium on Computer Architecture (ISCA), 2017, pp. 1–12. DOI: 10.1145/3079856.3080246
  8. M. Shoeybi et al., "Megatron-LM: Training Multi-Billion Parameter Language Models Using Model Parallelism," arXiv preprint arXiv:1909.08053, 2019. Free full text: https://arxiv.org/abs/1909.08053
  9. Harvard University, Math 55a tensor-product course notes. Course notes
  10. NumPy Developers, numpy.ndarray.strides, NumPy Manual. Stride units and indexing examples