void construct_supercartesian_tree_bp(const RandomAccessContainer& vec, bit_vector& bp, const bool minimum=true) { typedef typename RandomAccessContainer::size_type size_type; bp.resize(2*vec.size()); // resize bit vector for balanaced parantheses to 2 n bits util::set_to_value(bp, 0); std::stack<typename RandomAccessContainer::value_type> vec_stack; size_type k=0; for (size_type i=0; i < vec.size(); ++i) { typename RandomAccessContainer::value_type l = vec[i]; if (minimum) { while (vec_stack.size() > 0 and l < vec_stack.top()) { vec_stack.pop(); ++k; /*bp[k++] = 0; bp is already initialized to zero*/ // writing a closing parenthesis } } else { while (vec_stack.size() > 0 and l > vec_stack.top()) { vec_stack.pop(); ++k; /*bp[k++] = 0; bp is already initialized to zero*/ // writing a closing parenthesis } } vec_stack.push(l); bp[k++] = 1; // writing an opening parenthesis } while (vec_stack.size() > 0) { vec_stack.pop(); bp[k++] = 0; // writing a closing parenthesis } assert(k == 2*vec.size()); }
void construct_supercartesian_tree_bp_succinct2(const RandomAccessContainer& vec, bit_vector& bp, const bool minimum=true) { typedef typename RandomAccessContainer::size_type size_type; bp.resize(2*vec.size()); // resize bit vector for balanced parentheses to 2 n bits util::set_to_value(bp, 0); sorted_stack_support vec_stack(vec.size()); // <- das ist ein Problem fuer int_vector_file_buffer size_type k=0; // uint64_t wbuf=0; for (size_type i=0/*, cnt64=0*/; i < vec.size(); ++i) { while (vec_stack.size() > 0 and vec[i] < vec[vec_stack.top()]) { vec_stack.pop(); ++k; /*bp[k++] = 0; bp is already initialized to zero*/ // writing a closing parenthesis } vec_stack.push(i); bp[k++] = 1; // writing an opening parenthesis while (i+1 < vec.size() and vec[i+1] >= vec[i]) { vec_stack.push(++i); bp[k++]; } } #ifdef SDSL_DEBUG // not neccessary as bp is already initialized to zero while (vec_stack.size() > 0) { vec_stack.pop(); bp[k++] = 0; // writing a closing parenthesis } assert(k == 2*vec.size()); #endif }
/** * @param[in] space The list of points in space that need to be iterated. */ void operator() (const pfunc::space_1D& space) const { for (size_t i=space.begin(); i<space.end(); ++i) { EdgeListType edge_list = (*set_map)(i); RandomAccessContainer A (M*edge_list.size()); RandomAccessContainer X (edge_list.size()); /* Response is common across all the vertices */ int response; /* Set up A, X, and R */ EdgeListIteratorType list_iter = edge_list.begin (); int index=0; while (list_iter != edge_list.end()) { edge_type current_entry = (*list_iter); const snp_type snp = (*snp_map)(current_entry.source); response = current_entry.target; const float_type weight = current_entry.weight; /* populate A */ (*materializer)(snp, A.begin()+(index*M)); /* populate X */ X[index] = weight; /* populate R */ int int_M = static_cast<int>(M); double* Y_ptr = const_cast<double*>(&((*Y)[0])+(response*M)); double* R_ptr = const_cast<double*>(&((*R)[0])+(response*M)); dcopy_ (&int_M, Y_ptr, &ONE_STEP, R_ptr, &ONE_STEP); ++list_iter; ++index; } /* Now, compute R = AX-R */ double* A_ptr = &(A[0]); double* X_ptr = &(X[0]); double* R_ptr = &((*R)[0])+(response*M); int LDA = static_cast<int>(M); int LDX = static_cast<int>(edge_list.size()); int LDR = static_cast<int>(M); dgemm_ (&NO_TRANS, &NO_TRANS, &LDR, &ONE_STEP, &LDX, &PLUS_ONE, A_ptr, &LDA, X_ptr, &LDX, &MINUS_ONE, R_ptr, &LDR); (*l2_norm)[response] = dnrm2_(&LDR, R_ptr, &ONE_STEP); } }
/** * Construct a CSR format graph from an adjacency_list representation. * \param[in] adjacency_list An adjacency list representation. * \param[in] N The number of vertices. * \param[in] nnz The number of non-zero entries. * * NOTE: We can deduce N and nnz from adjacency_list, but its a lot easier * to just get the whole thing passed as parameters. Avoids going through * the adjacency_list twice. */ weighted_csr_graph (const RandomAccessContainer& adjacency_list, const int& N, const int& nnz): N (adjacency_list.size()), nnz(nnz), sorted (false) { row_indices.resize (N+1); columns.resize (nnz); weights.resize (nnz); /* Start copying over from the first vertex onwards */ int offset = 0; for (int vertex_index=0; vertex_index<N; ++vertex_index) { row_indices[vertex_index] = offset; ForwardContainerIterator edge_iter=adjacency_list[vertex_index].begin(); ForwardContainerIterator edge_end = adjacency_list[vertex_index].end(); while (edge_iter!=edge_end) { columns[offset] = (*edge_iter).first; weights[offset] = (*edge_iter).second; ++offset; ++edge_iter; } } /* check that we have included every edge */ assert (offset==nnz); /* set the offset of the sentinel */ row_indices[N] = offset; }
typename RandomAccessContainer::size_type construct_first_p_index(const RandomAccessContainer& vec, bit_vector& bp, const bool minimum=true) { typedef typename RandomAccessContainer::size_type size_type; size_type nr_of_first_indices = 0; bp = bit_vector(vec.size(), 0); // std::cerr<<"bp.size()="<<bp.size()<<std::endl; sorted_stack_support vec_stack(vec.size()); size_type k=0; for (size_type i=0, t; i < vec.size(); ++i) { if (minimum) { while (vec_stack.size() > 0 and vec[i] < vec[vec_stack.top()]) { t = vec[vec_stack.top()]; vec_stack.pop(); if (vec_stack.size() == 0 or t != vec[vec_stack.top()]) { bp[k] = 1; ++nr_of_first_indices; } ++k; } } else { while (vec_stack.size() > 0 and vec[i] > vec[vec_stack.top()]) { t = vec[vec_stack.top()]; vec_stack.pop(); if (vec_stack.size() == 0 or t != vec[vec_stack.top()]) { bp[k] = 1; ++nr_of_first_indices; } ++k; } } vec_stack.push(i); } while (vec_stack.size() > 0) { size_type t = vec[vec_stack.top()]; vec_stack.pop(); if (vec_stack.size() == 0 or t != vec[vec_stack.top()]) { bp[k] = 1; ++nr_of_first_indices; } ++k; } assert(k == vec.size()); return nr_of_first_indices; }
void construct_supercartesian_tree_bp_succinct(const RandomAccessContainer& vec, bit_vector& bp, const bool minimum=true) { typedef typename RandomAccessContainer::size_type size_type; bp.resize(2*vec.size()); // resize bit vector for balanced parentheses to 2 n bits if (vec.size() > 0) { util::set_to_value(bp, 0); sorted_stack_support vec_stack(vec.size()); // <- das ist ein Problem fuer int_vector_file_buffer size_type k=0; if (minimum) { bp[k++] = 1; for (size_type i=1; i < vec.size(); ++i) { if (vec[i] < vec[i-1]) { ++k; while (vec_stack.size() > 0 and vec[i] < vec[vec_stack.top()]) { vec_stack.pop(); ++k; // writing a closing parenthesis, bp is already initialized to zero } } else { vec_stack.push(i-1); // "lazy stack" trick: speed-up ca. 25% } bp[k++] = 1; // writing an opening parenthesis } /* vec_stack.push(0); bp[k++] = 1; for(size_type i=1,j, start_run=1; i < vec.size(); ++i){ if( vec[i] < vec[i-1] ){ j = i; while( --j >= start_run and vec[i] < vec[j]) ++k; while(start_run <= j){ // auf den stack pushen vec_stack.push(start_run++); } while( vec_stack.size() > 0 and vec[i] < vec[vec_stack.top()] ){ vec_stack.pop(); ++k; } start_run = i; } bp[k++] = 1; } */ } else { // hier noch ohne "lazy stack" trick for (size_type i=0; i < vec.size(); ++i) { while (vec_stack.size() > 0 and vec[i] > vec[vec_stack.top()]) { vec_stack.pop(); ++k; /*bp[k++] = 0; bp is already initialized to zero*/ // writing a closing parenthesis } vec_stack.push(i); bp[k++] = 1; // writing an opening parenthesis } } #ifdef SDSL_DEBUG // not necessary as bp is already initialized to zero while (!vec_stack.empty()) { vec_stack.pop(); bp[k++] = 0; // writing a closing parenthesis } assert(k == 2*vec.size()); #endif } }
/** * @param[in] space The list of candidates that need to be evaluated. */ void operator() (const pfunc::space_1D& space) { /* Loop over each element in the range that is given to us */ for (size_t i=space.begin(); i<space.end(); ++i) { const int candidate = (*map)(i); /* pass this candidate through the filter */ if ((*filter)(candidate)) continue; /* Materialize Xg */ A->materialize_X (candidate, Xg.begin()); /* Materialize Cholesky (Xg'Xg) */ factorizer->materialize (candidate, cholesky_XgtXg.begin()); /* Solve Ax=y, compute cost */ solver (Xg, cholesky_XgtXg); cost (Xg); /* Check if the new gain is worth switching over from the previous */ swap (value_type (candidate, (*weights)[candidate]*cost.get_result())); } }
/** * Materialize as many of the blocks as possible. */ void project_k (int64_t start, int64_t end) { /* Ensure that we can fit this many columns in */ assert (end < std::numeric_limits<int>::max()); assert (start < std::numeric_limits<int>::max()); /* Materialize everything */ int C = 0; for (int64_t i=start; i<end; ++i) { /* Get the SNP */ snp_type SNP = (*map)(i); /* Skip if filter asks us to skip */ if ((*filter)(SNP)) continue; /* Materialize the required vectors */ (*materializer) (SNP, A_ptr+(C*M)); ++C; } /* Compute the projections --- A'Y */ dgemm_ (&TRANS, &NO_TRANS, &block_size, &K, &M, &PLUS_ONE, A_ptr, &M, Y_ptr, &M, &PLUS_ONE, R_ptr, &block_size); /* Figure out the SNP that can be added (and in which position */ for (size_t i=0; i<R.size(); ++i) { if (result.invalid() || (compare (R[i], result.weight))) { result.source = i/block_size; result.target = i%block_size; result.weight = R[i]; } } }
/** * Compute the Frobenius norm from the L2 norms. * * THIS HAS NOT BEEN PARALLELIZED. */ double fro_norm () { double fro_norm = 0.0; for (size_t i=0; i<l2_norm.size(); ++i) fro_norm += pow (l2_norm[i],2); return fro_norm; }
int_type size () const { return elements.size(); }