validation.bench_trees#

Design#

The sparse format defined here is structure storing indices and values (float) in a single float array. The beginning of the structures stores the shape (1D to 5D), the element type and the number of stored elements. The two following functions are used to convert from dense from/to sparse.

Functions#

onnx_extended.validation.cpu._validation.dense_to_sparse_struct#

onnx_extended.validation.cpu._validation.dense_to_sparse_struct(v: numpy.ndarray[numpy.float32]) numpy.ndarray[numpy.float32]#

Converts a dense float tensor into a sparse structure stored in a float tensor.

onnx_extended.validation.cpu._validation.evaluate_sparse#

onnx_extended.validation.cpu._validation.evaluate_sparse(tensor: numpy.ndarray[numpy.float32], n_random: int, n_times: int, repeat: int, dense: int) List[Tuple[float, float, float]]#

Returns computation time about random access to features dense or sparse, initialization time, loop time, sum of the element from the array based on random indices. The goal is to evaluate whether or not it is faster to switch to a dense representation or to keep the sparse representation to do random access to the structures.

Parameters:
  • tensor – dense tensor to access

  • n_random – number of random access

  • n_times – number of times to do n_random random accesses

  • repeat – number of times to repeat the measure

  • dense – if true, measure the conversion from sparse and then operate random access on a dense structure, if false, operator random access directly into the sparse structures

Returns:

3-tuple, intialization time (conversion to dense, or sparse initialization), measure of the random accesses, control sum

onnx_extended.validation.cpu._validation.sparse_struct_indices_values#

onnx_extended.validation.cpu._validation.sparse_struct_indices_values(v: numpy.ndarray[numpy.float32]) tuple#

Returns the indices and the values from a sparse structure stored in a float tensor.

onnx_extended.validation.cpu._validation.sparse_struct_to_dense#

onnx_extended.validation.cpu._validation.sparse_struct_to_dense(v: numpy.ndarray[numpy.float32]) numpy.ndarray[numpy.float32]#

Converts a sparse structure stored in a float tensor into a dense vector.

onnx_extended.validation.cpu._validation.sparse_struct_to_csr#

onnx_extended.validation.cpu._validation.sparse_struct_to_csr(v: numpy.ndarray[numpy.float32]) tuple#

Returns the position of the first elements of each row. The array has n+1 elements if n is the number of non null elements. The second array stores the column index for every element.

onnx_extended.validation.cpu._validation.sparse_struct_to_maps#

onnx_extended.validation.cpu._validation.sparse_struct_to_maps(v: numpy.ndarray[numpy.float32]) list#

Converts a sparse structure stored in a float tensor into a list of dictionaries. The sparse tensor needs to be 2D.