planc
Parallel Lowrank Approximation with Non-negativity Constraints
ntf_utils.hpp
Go to the documentation of this file.
1 /* Copyright 2017 Ramakrishnan Kannan */
2 
3 #ifndef COMMON_NTF_UTILS_HPP_
4 #define COMMON_NTF_UTILS_HPP_
5 
6 #include "common/ncpfactors.hpp"
7 #include "common/tensor.hpp"
8 
15 void khatrirao(const MAT &i_A, const MAT &i_B, MAT *o_C) {
16  assert(i_A.n_cols == i_B.n_cols);
17  VEC acol = arma::zeros<VEC>(i_A.n_rows);
18  VEC bcol = arma::zeros<VEC>(i_B.n_rows);
19  for (unsigned int i = 0; i < i_A.n_cols; i++) {
20  acol = i_A.col(i);
21  bcol = i_B.col(i);
22  for (unsigned int j = 0; j < acol.n_rows; j++) {
23  (*o_C)(arma::span(j * bcol.n_rows, (j + 1) * bcol.n_rows - 1), i) =
24  acol(j) * bcol;
25  }
26  }
27 }
34 inline void kronecker(const VEC &i_acol, const VEC &i_bcol, VEC *o_c) {
35  for (unsigned int j = 0; j < i_acol.n_rows; j++) {
36  (*o_c).rows(arma::span(j * i_bcol.n_rows, (j + 1) * i_bcol.n_rows - 1)) =
37  i_acol(j) * i_bcol;
38  }
39 }
49 void mttkrp(const int i_n, const planc::Tensor &X, planc::NCPFactors &i_F,
50  MAT *o_mttkrp) {
51  MAT krp = i_F.krp_leave_out_one(i_n);
52  X.mttkrp(i_n, krp, o_mttkrp);
53 }
54 
55 #endif // COMMON_NTF_UTILS_HPP_
Data is stored such that the unfolding is column major.
Definition: tensor.hpp:32
void mttkrp(const int i_n, const MAT &i_krp, MAT *o_mttkrp) const
size of krp must be product of all dimensions leaving out nxk.
Definition: tensor.hpp:242
MAT krp_leave_out_one(const unsigned int i_n)
KRP leaving out the mode i_n.
Definition: ncpfactors.hpp:154
void kronecker(const VEC &i_acol, const VEC &i_bcol, VEC *o_c)
Returns the kronecker product between two vectors.
Definition: ntf_utils.hpp:34
void mttkrp(const int i_n, const planc::Tensor &X, planc::NCPFactors &i_F, MAT *o_mttkrp)
Return the mttkrp of mode i_n of tensor X.
Definition: ntf_utils.hpp:49
#define MAT
Definition: utils.h:52
void khatrirao(const MAT &i_A, const MAT &i_B, MAT *o_C)
Returns the khatri-rao product between two matrices.
Definition: ntf_utils.hpp:15
#define VEC
Definition: utils.h:61