Package cplex :: Package _internal :: Module _matrices :: Class SparsePair
 

Class SparsePair

A class for storing sparse vector data.

An instance of this class has two attributes, ind and val. ind specifies the indices and val specifies the values. ind and val must be sequences of the same length. In general, ind may contain any identifier; for example, when a SparsePair object is passed to Cplex.linear_constraints.add, its ind attribute may be a list containing both variable names and variable indices.

Instance Methods
 
__init__(self, ind=None, val=None)
Constructor for SparsePair.
 
__repr__(self)
Representation method of SparsePair.
 
isvalid(self)
Tests that ind and val have the same length.
 
unpack(self)
Extracts the indices and values sequences as a tuple.
Method Details

__init__(self, ind=None, val=None)
(Constructor)

 

Constructor for SparsePair.

Takes two arguments, ind and val; ind specifies the indices that the SparsePair refers to, and val specifies the float values associated with those indices; ind and val must have the same length. If ind or val is omitted, they will default to an empty list.

>>> spair = SparsePair(ind=[0], val=[1.0])

__repr__(self)
(Representation operator)

 

Representation method of SparsePair.

Example usage:

>>> SparsePair(ind=[0], val=[1.0])
SparsePair(ind = [0], val = [1.0])

isvalid(self)

 

Tests that ind and val have the same length.

Example usage:

>>> spair = SparsePair(ind=[0, 1, 2], val=[1.0, 1.0, 1.0])
>>> spair.isvalid()
True

unpack(self)

 

Extracts the indices and values sequences as a tuple.

Returns ind and val as given in __init__.

>>> spair = SparsePair(ind=[0, 1, 2], val=[1.0, 1.0, 1.0])
>>> ind, val = spair.unpack()