Initializing help system before first use

xpress.Dot

xpress.Dot


Purpose

Alternative dot-product operator for an arbitrary number of NumPy single- or multi-dimensional arrays. Following the convention for dot-product, the result of Dot for a list of k objects T1, T2, ..., Tk of d1, d2, ..., dk dimensions is an object of d1 + d2 + ... + dk - 2(k-1) dimensions. For each i-th factor in [1,2,...,k-1], the arity of the last dimension of Ti must match the arity of the penultimate dimension of Ti+1 (or its arity if Ti+1 is single-dimensional, i.e., a vector).


Synopsis
a = xpress.Dot(t1, t2, ..., out)
Argument
out 
(optional) NumPy array of the correct dimension and arity where the result is stored. If not provided, the dot product is returned.
Example
The following code shows some possible uses of the Dot operator:
import numpy as np
import xpress as xp

N = 10
M = 20
S = range(N)

x  = np.array([xp.var() for i in S], dtype=xp.npvar)
x0 = np.random.random(N) # creates an N-vector of random numbers

p = xp.problem()

# objective function is the squared Euclidean distance of the
# variable vector x from a fixed point x0
p.setObjective(xp.Dot((x-x0),(x-x0)))

A = np.random.random((M,N))
b = np.random.random(M)

# constraint Ax = b, random MxN matrix A and M-vector b
p.addConstraint(xp.Dot(A, x) == b)

# Create a single quadratic constraint with
# a positive semidefinite matrix Q + N^3 * I

Q = np.random.random((N,N))
p.addConstraint(xp.Dot(x, Q + N**3 * np.eye(N), x) <= 1)

# Create four quadratic constraints using an order-three
# tensor, i.e., a three-dimensional array.

k = 4

T = np.random.random((k,N,N))
q = np.random.random(k)
p.addConstraint(xp.Dot(x, T, x) <= q)
Further information

From an operational standpoint, the dot product of k multi-dimensional arrays is the result of k-1 dot products of two factors each, and proceeds as in the following Python code:

result = T[0]
for i in range(1,k):
    result = xpress.Dot(result, T[i])
The dot product of two multi-dimensional array T' and T'' of dimensions d' and d'' and of arities (n1, n2, ..., nd') and (m1, m2, ..., md''), respectively, is a multi-dimensional array of dimension d' + d'' - 2, whose arity vector is (n1, n2, ..., nd'-1, m1, m2, ..., md''-2, md'') and whose generic element is

vi1,i2,...,id'-1, j1,j2,...,jd''-2,jd'' = ∑1≤h≤nd' t'i1,i2,...,id'-1,h· t''j1,j2,...,jd''-2,h,jd''.

It is assumed here that nd' = md''-1. Two simple cases may help understand the behavior of the operator: for two single-dimensional arrays v' and v'' of size n, the result is the inner product

1≤h≤n v'h· v''h.

For two matrices A and B of sizes m×n and n×p respectively, the result is the m×p matrix C whose generic element is

Cij = ∑1≤h≤n Aih· Bhj.

The Dot operator is functionally equivalent to Python's dot operator from the NumPy package. However, the Xpress Dot operator is the only one that can work on variables and expressions containing variables.