BSC#
purpose#
The bsc
package takes given matrices
See Section 4 of $GALAHAD/doc/bsc.pdf for a brief description of the method employed and other details.
matrix storage#
The unsymmetric
Dense storage format:
The matrix
Sparse co-ordinate storage format:
Only the nonzero entries of the matrices are stored.
For the
Sparse row-wise storage format:
Again only the nonzero entries are stored, but this time
they are ordered so that those in row i appear directly before those
in row i+1. For the i-th row of
Sparse column-wise storage format:
Once again only the nonzero entries are stored, but this time
they are ordered so that those in column j appear directly before those
in column j+1. For the j-th column of
The symmetric
Sparse co-ordinate storage format:
Only the nonzero entries of the matrices are stored.
For the
Sparse row-wise storage format:
Again only the nonzero entries are stored, but this time
they are ordered so that those in row i appear directly before those
in row i+1. For the i-th row of
functions#
- bsc.initialize()#
Set default option values and initialize private data.
Returns:
- optionsdict
- dictionary containing default control options:
- errorint
error and warning diagnostics occur on stream error.
- outint
general output occurs on stream out.
- print_levelint
the level of output required is specified by print_level.
- max_colint
maximum permitted number of nonzeros in a column of \f
; -ve means unlimit. - new_aint
how much has
changed since it was last accessed:
0
unchanged.
1
values changed.
2
structure changed.
3
structure changed but values not required.
- extra_space_sint
how much extra space is to be allocated in
above that needed to hold the Schur complement. - s_also_by_columnbool
should s.ptr also be set to indicate the first entry in each column of
. - space_criticalbool
if
space_critical
is True, every effort will be made to use as little space as possible. This may result in longer computation time.- deallocate_error_fatalbool
if
deallocate_error_fatal
is True, any array/pointer deallocation error will terminate execution. Otherwise, computation will continue.- prefixstr
all output lines will be prefixed by the string contained in quotes within
prefix
, e.g. ‘word’ (note the qutoes) will result in the prefix word.
- bsc.load(m, n, A_type, A_ne, A_row, A_col, A_ptr, options=None)#
Import the structure of
to build that of . Parameters:
- mint
holds the number of rows of
. - nint
holds the number of columns of
. - A_typestring
specifies the unsymmetric storage scheme used for the matrix
. It should be one of ‘coordinate’, ‘sparse_by_rows’ or ‘dense’; lower or upper case variants are allowed. - A_neint
holds the number of entries in
in the sparse co-ordinate storage scheme. It need not be set for any of the other two schemes. - A_rowndarray(A_ne)
holds the row indices of
in the sparse co-ordinate storage scheme. It need not be set for any of the other two schemes, and in this case can be None. - A_colndarray(A_ne)
holds the column indices of
in either the sparse co-ordinate, or the sparse row-wise storage scheme. It need not be set when the dense storage scheme is used, and in this case can be None. - A_ptrndarray(m+1)
holds the starting position of each row of
, as well as the total number of entries, in the sparse row-wise storage scheme. It need not be set when the other schemes are used, and in this case can be None. - optionsdict, optional
dictionary of control options (see
bsc.initialize
).Returns:
- S_neint
holds the number of entries in
.
- bsc.form(m, n, A_ne, A_val, S_ne, D)#
Form the Schur complement matrix
. Parameters:
- mint
holds the number of rows of
. - nint
holds the number of columns of
. - A_neint
holds the number of entries in the matrix
. - A_valndarray(A_ne)
holds the values of the nonzeros in the matrix
in the same order as specified in the sparsity pattern in bsc.load
.- S_neint
holds the number of entries in the matrix
, as returned by bsc.load
.- Dndarray(n)
holds the values of diagonal matrix
. If is the identity matrix, it can take the value None to save storage. Returns:
- S_rowndarray(S_ne)
holds the row indices of
in the sparse co-ordinate storage scheme. - S_colndarray(S_ne)
holds the column indices of
in either the sparse co-ordinate, or the sparse row-wise storage scheme. - S_ptrndarray(n+1)
holds the starting position of each row of
, as well as the total number of entries, in the sparse row-wise storage scheme. - S_valndarray(S_ne)
holds the values of the nonzeros in the matrix
.
- [optional] bsc.information()
Provide optional output information.
Returns:
- informdict
- dictionary containing output information:
- statusint
the return status. Possible values are:
0
The call was successful.
-1
An allocation error occurred. A message indicating the offending array is written on unit options[‘error’], and the returned allocation status and a string containing the name of the offending array are held in inform[‘alloc_status’] and inform[‘bad_alloc’] respectively.
-2
A deallocation error occurred. A message indicating the offending array is written on unit options[‘error’] and the returned allocation status and a string containing the name of the offending array are held in inform[‘alloc_status’] and inform[‘bad_alloc’] respectively.
-3
The restriction n > 0 or m > 0 or requirement that type contains its relevant string ‘dense’, ‘coordinate’ or ‘sparse_by_rows’ has been violated.
- alloc_statusint
the status of the last attempted allocation/deallocation.
- bad_allocstr
the name of the array for which an allocation/deallocation error occurred.
- max_col_aint
the maximum number of entries in a column of
. - exceeds_max_colint
the number of columns of
that have more than control.max_col entries. - timefloat
the total CPU time spent in the package.
- clock_timefloat
the total clock time spent in the package.
- bsc.finalize()#
Deallocate all internal private storage.
example code#
from galahad import bsc
import numpy as np
np.set_printoptions(precision=2,suppress=True,floatmode='fixed')
print("\n** python test: bsc")
# set parameters
n = 4
m = 3
# describe matrix
A_type = 'coordinate'
A_ne = 6
A_row = np.array([0,0,1,1,2,2])
A_col = np.array([0,1,2,3,0,3])
A_ptr = None
A_val = np.array([1.0,1.0,1.0,1.0,1.0,1.0])
D = np.array([1.0,2.0,3.0,4.0])
# allocate internal data and set default options
options = bsc.initialize()
# set some non-default options
options['print_level'] = 0
#print("options:", options)
# load data (and optionally non-default options)
S_ne = bsc.load(m, n, A_type, A_ne, A_row, A_col, A_ptr, options)
print(" S_ne:",S_ne)
# form S = A D A'
S_row, S_col, S_ptr, S_val = bsc.form(m, n, A_ne, A_val, S_ne, D)
print(" S_row:",S_row)
print(" S_col:",S_col)
print(" S_ptr:",S_ptr)
print(" S_val:",S_val)
# get information
inform = bsc.information()
print('** bsc exit status:', inform['status'])
# deallocate internal data
bsc.terminate()
This example code is available in $GALAHAD/src/bsc/Python/test_bsc.py .