Constructor and Description |
---|
VectorUtil() |
Modifier and Type | Method and Description |
---|---|
static Vector |
parse(String str)
Parse either a
SparseVector or a DenseVector from a formatted string. |
static DenseVector |
parseDense(String str)
Parse the dense vector from a formatted string.
|
static SparseVector |
parseSparse(String str)
Parse the sparse vector from a formatted string.
|
static String |
toString(DenseVector denseVector)
Serialize the DenseVector to String.
|
static String |
toString(SparseVector sparseVector)
Serialize the SparseVector to string.
|
static String |
toString(Vector vector)
Serialize the vector to a string.
|
public static Vector parse(String str)
SparseVector
or a DenseVector
from a formatted string.
The format of a dense vector is space separated values such as "1 2 3 4". The format of a sparse vector is space separated index-value pairs, such as "0:1 2:3 3:4". If the sparse vector has determined vector size, the size is prepended to the head. For example, the string "$4$0:1 2:3 3:4" represents a sparse vector with size 4.
str
- A formatted string representing a vector.public static DenseVector parseDense(String str)
The format of a dense vector is space separated values such as "1 2 3 4".
str
- A string of space separated values.public static SparseVector parseSparse(String str)
The format of a sparse vector is space separated index-value pairs, such as "0:1 2:3 3:4". If the sparse vector has determined vector size, the size is prepended to the head. For example, the string "$4$0:1 2:3 3:4" represents a sparse vector with size 4.
str
- A formatted string representing a sparse vector.IllegalArgumentException
- If the string is of invalid format.public static String toString(Vector vector)
vector
- The vector to serialize.toString(DenseVector)
,
toString(SparseVector)
public static String toString(SparseVector sparseVector)
The format of the returned is described at parseSparse(String)
sparseVector
- The sparse vector to serialize.public static String toString(DenseVector denseVector)
The format of the returned is described at parseDense(String)
denseVector
- The DenseVector to serialize.Copyright © 2014–2021 The Apache Software Foundation. All rights reserved.