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 }
/** * 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 } }
/** * 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(); }