public class SparseBlockCSR extends SparseBlock
SparseBlock.Type
INIT_CAPACITY, RESIZE_FACTOR1, RESIZE_FACTOR2
Constructor and Description |
---|
SparseBlockCSR(int rlen) |
SparseBlockCSR(int[] rowPtr,
int[] colInd,
double[] values,
int nnz) |
SparseBlockCSR(int rlen,
int capacity) |
SparseBlockCSR(int rows,
int[] rowInd,
int[] colInd,
double[] values)
Copy constructor for COO representation
|
SparseBlockCSR(int rows,
int nnz,
int[] colInd)
Copy constructor for given array of column indexes, which
identifies rows by position and implies values of 1.
|
SparseBlockCSR(SparseBlock sblock)
Copy constructor sparse block abstraction.
|
SparseBlockCSR(SparseRow[] rows,
int nnz)
Copy constructor old sparse row representation.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(int r,
int c,
double v)
Add a value to a matrix cell (r,c).
|
void |
allocate(int r)
Allocate the underlying data structure holding non-zero values
of row r if necessary.
|
void |
allocate(int r,
int nnz)
Allocate the underlying data structure holding non-zero values
of row r if necessary, w/ given size.
|
void |
allocate(int r,
int ennz,
int maxnnz)
Allocate the underlying data structure holding non-zero values
of row r w/ the specified estimated nnz and max nnz.
|
void |
append(int r,
int c,
double v)
Append a value to the end of the physical representation.
|
boolean |
checkValidity(int rlen,
int clen,
long nnz,
boolean strict)
Validate the correctness of the internal data structures of the different
sparse block implementations.
|
void |
compact(int r)
Re-allocate physical row if physical size exceeds
logical size plus resize factor.
|
void |
deleteIndexRange(int r,
int cl,
int cu)
Deletes all non-zero values of the given column range [cl,cu) in row r.
|
static long |
estimateMemory(long nrows,
long ncols,
double sparsity)
Get the estimated in-memory size of the sparse block in CSR
with the given dimensions w/o accounting for overallocation.
|
SparseRow |
get(int r)
Get values of row r in the format of a sparse row.
|
double |
get(int r,
int c)
Get value of matrix cell (r,c).
|
int[] |
indexes()
Get raw access to underlying array of column indices
For use in GPU code
|
int[] |
indexes(int r)
Get the sorted array of column indexes of all non-zero entries in
row r.
|
void |
initSparse(int rlen,
int nnz,
DataInput in)
Initializes the CSR sparse block from an ordered input
stream of sparse rows (rownnz, jv-pairs*).
|
void |
initUltraSparse(int nnz,
DataInput in)
Initializes the CSR sparse block from an ordered input
stream of ultra-sparse ijv triples.
|
boolean |
isAllocated(int r)
Indicates if the underlying data structure for a given row
is already allocated.
|
boolean |
isContiguous()
Indicates if the underlying data structures returned by values
and indexes are contiguous arrays, which can be exploited for
more efficient operations.
|
boolean |
isEmpty(int r)
Get information if row r is empty, i.e., does not contain non-zero
values.
|
boolean |
isThreadSafe()
Indicates if the underlying implementation allows thread-safe row
updates if concurrent threads update disjoint rows.
|
int |
numRows()
Get the number of rows in the sparse block.
|
int |
pos(int r)
Get the starting position of row r in the indexes/values arrays returned
by indexes(r) and values(r).
|
int |
posFIndexGT(int r,
int c)
Get position of first column index greater than column c in row r.
|
int |
posFIndexGTE(int r,
int c)
Get position of first column index greater than or equal column c
in row r.
|
int |
posFIndexLTE(int r,
int c)
Get position of first column index lower than or equal column c
in row r.
|
void |
reset()
Clears the sparse block by deleting non-zero values.
|
void |
reset(int ennz,
int maxnnz)
Clears the sparse block by deleting non-zero values.
|
void |
reset(int r,
int ennz,
int maxnnz)
Clears row r of the sparse block by deleting non-zero values.
|
int[] |
rowPointers()
Get raw access to underlying array of row pointers
For use in GPU code
|
boolean |
set(int r,
int c,
double v)
Set the value of a matrix cell (r,c).
|
void |
set(int r,
SparseRow row,
boolean deep)
Set the values of row r to the given sparse row.
|
void |
setIndexRange(int r,
int cl,
int cu,
double[] v,
int[] vix,
int vpos,
int vlen)
Sets a sparse array of non-zeros values and indexes into the column range [cl,cu)
in row r.
|
void |
setIndexRange(int r,
int cl,
int cu,
double[] v,
int vix,
int vlen)
Sets a dense array of non-zeros values into the column range [cl,cu)
in row r.
|
void |
setIndexRange(int rl,
int ru,
int cl,
int cu,
double[] v,
int vix,
int vlen)
Inserts a sorted row-major array of non-zero values into the row and column
range [rl,ru) and [cl,cu).
|
void |
setIndexRange(int rl,
int ru,
int cl,
int cu,
SparseBlock sb)
Inserts a sparse block into the row and column range [rl,ru) and [cl,cu).
|
long |
size()
Get the number of non-zero values in the sparse block.
|
int |
size(int r)
Get the number of non-zero values in row r.
|
long |
size(int rl,
int ru)
Get the number of non-zeros values in the row range
of [rl, ru).
|
long |
size(int rl,
int ru,
int cl,
int cu)
Get the number of non-zeros values in the row and column
range of [rl/cl, ru/cu);
|
void |
sort()
Sort all non-zero value/index pairs of the sparse block by row
and column index.
|
void |
sort(int r)
Sort all non-zero value/index pairs of row r column index.
|
String |
toString() |
double[] |
values()
Get raw access to underlying array of values
For use in GPU code
|
double[] |
values(int r)
Get the array of all non-zero entries in row r, sorted by their column
indexes.
|
getIterator, getIterator, getIterator, isAligned, isAligned
public SparseBlockCSR(int rlen)
public SparseBlockCSR(int rlen, int capacity)
public SparseBlockCSR(int[] rowPtr, int[] colInd, double[] values, int nnz)
public SparseBlockCSR(SparseBlock sblock)
sblock
- sparse block to copypublic SparseBlockCSR(SparseRow[] rows, int nnz)
rows
- array of sparse rowsnnz
- number of non-zeroespublic SparseBlockCSR(int rows, int[] rowInd, int[] colInd, double[] values)
rows
- number of rowsrowInd
- row indicescolInd
- column indicesvalues
- non zero valuespublic SparseBlockCSR(int rows, int nnz, int[] colInd)
rows
- number of rowsnnz
- number of non-zeroscolInd
- column indexespublic void initUltraSparse(int nnz, DataInput in) throws IOException
nnz
- number of non-zeros to readin
- data input stream of ijv triples, ordered by ijIOException
- if deserialization error occurspublic void initSparse(int rlen, int nnz, DataInput in) throws IOException
rlen
- number of rowsnnz
- number of non-zeros to readin
- data input stream of sparse rows, ordered by iIOException
- if deserialization error occurspublic static long estimateMemory(long nrows, long ncols, double sparsity)
nrows
- number of rowsncols
- number of columnssparsity
- sparsity ratiopublic int[] rowPointers()
public int[] indexes()
public double[] values()
public void allocate(int r)
SparseBlock
allocate
in class SparseBlock
r
- row indexpublic void allocate(int r, int nnz)
SparseBlock
allocate
in class SparseBlock
r
- row indexnnz
- number of non-zerospublic void allocate(int r, int ennz, int maxnnz)
SparseBlock
allocate
in class SparseBlock
r
- row indexennz
- estimated non-zerosmaxnnz
- max non-zerospublic void compact(int r)
SparseBlock
compact
in class SparseBlock
r
- row indexpublic int numRows()
SparseBlock
numRows
in class SparseBlock
public boolean isThreadSafe()
SparseBlock
isThreadSafe
in class SparseBlock
public boolean isContiguous()
SparseBlock
isContiguous
in class SparseBlock
public boolean isAllocated(int r)
SparseBlock
isAllocated
in class SparseBlock
r
- row indexpublic void reset()
SparseBlock
reset
in class SparseBlock
public void reset(int ennz, int maxnnz)
SparseBlock
reset
in class SparseBlock
ennz
- estimated non-zerosmaxnnz
- max non-zerospublic void reset(int r, int ennz, int maxnnz)
SparseBlock
reset
in class SparseBlock
r
- row indexennz
- estimated non-zerosmaxnnz
- max non-zerospublic long size()
SparseBlock
size
in class SparseBlock
public int size(int r)
SparseBlock
size
in class SparseBlock
r
- row index starting at 0public long size(int rl, int ru)
SparseBlock
size
in class SparseBlock
rl
- row lower indexru
- row upper indexpublic long size(int rl, int ru, int cl, int cu)
SparseBlock
size
in class SparseBlock
rl
- row lower indexru
- row upper indexcl
- column lower indexcu
- column upper indexpublic boolean isEmpty(int r)
SparseBlock
isEmpty
in class SparseBlock
r
- row index starting at 0public int[] indexes(int r)
SparseBlock
indexes
in class SparseBlock
r
- row index starting at 0public double[] values(int r)
SparseBlock
values
in class SparseBlock
r
- row index starting at 0public int pos(int r)
SparseBlock
pos
in class SparseBlock
r
- row index starting at 0public boolean set(int r, int c, double v)
SparseBlock
set
in class SparseBlock
r
- row index starting at 0c
- column index starting at 0v
- zero or non-zero valuepublic boolean add(int r, int c, double v)
SparseBlock
add
in class SparseBlock
r
- row index starting at 0c
- column index starting at 0v
- zero or non-zero valuepublic void set(int r, SparseRow row, boolean deep)
SparseBlock
set
in class SparseBlock
r
- row index starting at 0row
- sparse rowdeep
- indicator to create deep copy of sparse rowpublic void append(int r, int c, double v)
SparseBlock
append
in class SparseBlock
r
- row index starting at 0c
- column index starting at 0v
- zero or non-zero valuepublic void setIndexRange(int r, int cl, int cu, double[] v, int vix, int vlen)
SparseBlock
setIndexRange
in class SparseBlock
r
- row index starting at 0cl
- lower column index starting at 0cu
- upper column index starting at 0v
- value arrayvix
- start index in value arrayvlen
- number of relevant valuespublic void setIndexRange(int r, int cl, int cu, double[] v, int[] vix, int vpos, int vlen)
SparseBlock
setIndexRange
in class SparseBlock
r
- row index starting at 0cl
- lower column index starting at 0cu
- upper column index starting at 0v
- value arrayvix
- column index arrayvpos
- start index in value and index arraysvlen
- number of relevant valuespublic void setIndexRange(int rl, int ru, int cl, int cu, double[] v, int vix, int vlen)
rl
- lower row index, starting at 0, inclusiveru
- upper row index, starting at 0, exclusivecl
- lower column index, starting at 0, inclusivecu
- upper column index, starting at 0, exclusivev
- right-hand-side dense blockvix
- right-hand-side dense block indexvlen
- right-hand-side dense block value lengthpublic void setIndexRange(int rl, int ru, int cl, int cu, SparseBlock sb)
rl
- lower row index, starting at 0, inclusiveru
- upper row index, starting at 0, exclusivecl
- lower column index, starting at 0, inclusivecu
- upper column index, starting at 0, exclusivesb
- right-hand-side sparse blockpublic void deleteIndexRange(int r, int cl, int cu)
SparseBlock
deleteIndexRange
in class SparseBlock
r
- row index starting at 0cl
- lower column index starting at 0cu
- upper column index starting at 0public void sort()
SparseBlock
sort
in class SparseBlock
public void sort(int r)
SparseBlock
sort
in class SparseBlock
r
- row index starting at 0public double get(int r, int c)
SparseBlock
get
in class SparseBlock
r
- row index starting at 0c
- column index starting at 0public SparseRow get(int r)
SparseBlock
get
in class SparseBlock
r
- row index starting at 0public int posFIndexLTE(int r, int c)
SparseBlock
posFIndexLTE
in class SparseBlock
r
- row index starting at 0c
- column index starting at 0public int posFIndexGTE(int r, int c)
SparseBlock
posFIndexGTE
in class SparseBlock
r
- row index starting at 0c
- column index starting at 0public int posFIndexGT(int r, int c)
SparseBlock
posFIndexGT
in class SparseBlock
r
- row index starting at 0c
- column index starting at 0public String toString()
toString
in class SparseBlock
public boolean checkValidity(int rlen, int clen, long nnz, boolean strict)
SparseBlock
checkValidity
in class SparseBlock
rlen
- number of rowsclen
- number of columnsnnz
- number of non zerosstrict
- enforce optional propertiesCopyright © 2018 The Apache Software Foundation. All rights reserved.