Exemplo n.º 1
0
s8 udu(u32 n, double *M, double *U, double *D) //todo: replace with DSYTRF
{
  double alpha, beta;
  triu(n, M);
  eye(n, U);
  memset(D, 0, n * sizeof(double));

  for (u32 j=n; j>=2; j--) {
    D[j - 1] = M[(j-1)*n + j-1];
    if (D[j-1] > 0) {
      alpha = 1.0 / D[j-1];
    } else {
      alpha = 0.0;
    }
    for (u32 k=1; k<j; k++) {
      beta = M[(k-1)*n + j-1];
      U[(k-1)*n + j-1] = alpha * beta;
      for (u32 kk = 0; kk < k; kk++) {
        M[kk*n + k-1] = M[kk*n + k-1] - beta * U[kk*n + j-1];
      }
    }

  }
  D[0] = M[0];
  return 0;
}
Exemplo n.º 2
0
 /// INTERNAL ONLY: 2i 1o upper_: x  = qr(a, upper_)
 BOOST_FORCEINLINE
 void eval2_1 ( A0& a0, A1& a1
                , const nt2::policy<ext::upper_>&
                ) const
 {
    nt2::container::table<type_t> work;
    NT2_AS_TERMINAL_INOUT(o_semantic
                         , r, boost::proto::child_c<0>(a0), work);
    o_semantic tau(of_size(height(r), 1));
    NT2_LAPACK_VERIFY(nt2::geqrf( boost::proto::value(r)
                                ,tau));
    boost::proto::child_c<0>(a1) = triu(r);
 }
Exemplo n.º 3
0
/*
 * Preserves a given proportion of the strongest weights in an undirected graph.
 * All other weights, as well as those on the main diagonal, are set to zero.
 */
MATRIX_T* BCT_NAMESPACE::threshold_proportional_und(const MATRIX_T* W, FP_T p) {
	if (safe_mode) check_status(W, SQUARE | UNDIRECTED, "threshold_proportional_und");
	
	// n=size(W,1);
	int n = W->size1;
	
	// W(1:n+1:end)=0;
	MATRIX_T* W_thr = triu(W, 1);
	
	// ind=find(W);
	VECTOR_T* ind = find(W_thr);
	
	// E=sortrows([ind W(ind)], -2);
	VECTOR_T* W_thr_ind = ordinal_index(W_thr, ind);
	VECTOR_T* sort_ind;
	VECTOR_T* sort_W_thr_ind = sort(W_thr_ind, "descend", &sort_ind);
	VECTOR_ID(free)(W_thr_ind);
	VECTOR_ID(free)(sort_W_thr_ind);
	
	// en=round((n^2-n)*p);
	int en = (int)std::floor(0.5 * n * (n - 1) * p + 0.5);
	
	// W(E(en+1:end,1))=0;
	for (int i = en; i < (int)sort_ind->size; i++) {
		int index = VECTOR_ID(get)(ind, VECTOR_ID(get)(sort_ind, i));
		ordinal_index_assign(W_thr, index, 0.0);
	}
	for (int i = 0; i < (int)W_thr->size1; i++) {
		for (int j = i + 1; j < (int)W_thr->size2; j++) {
			FP_T value = MATRIX_ID(get)(W_thr, i, j);
			MATRIX_ID(set)(W_thr, j, i, value);
		}
	}
	
	VECTOR_ID(free)(ind);
	VECTOR_ID(free)(sort_ind);
	return W_thr;
}
T Linalg< T, H >::triu(const T &x) {
  T r(x.allocator());
  return *triu(x, &r);
}