DiSMEC++
test_utils.cpp
Go to the documentation of this file.
1 // Copyright (c) 2021, Aalto University, developed by Erik Schultheis
2 // All rights reserved.
3 //
4 // SPDX-License-Identifier: MIT
5 
6 #include "test_utils.h"
7 
8 dismec::SparseFeatures dismec::make_uniform_sparse_matrix(int rows, int cols, int nonzeros_per_row) {
9  SparseFeatures matrix(rows, cols);
10  std::vector<Eigen::Triplet<real_t>> content;
11  for(int i = 0; i < rows; ++i) {
12  // and some uniform features
13  for(int j = 0; j < nonzeros_per_row; ++j) {
14  content.emplace_back(i, rand() % cols, 1.f);
15  }
16  }
17  matrix.setFromTriplets(begin(content), end(content));
18  matrix.makeCompressed();
19  return matrix;
20 }
SparseFeatures make_uniform_sparse_matrix(int rows, int cols, int non_zeros_per_row)
Creates a sparse matrix with the given number of rows and columns.
Definition: test_utils.cpp:8
types::SparseRowMajor< real_t > SparseFeatures
Sparse Feature Matrix in Row Major format.
Definition: matrix_types.h:50