Exemple #1
0
void 
pcl::Permutohedral::compute (std::vector<float> &out, const std::vector<float> &in, 
                             int value_size,
                             int in_offset, int out_offset,
                             int in_size, int out_size) const
{
  if (in_size == -1)  in_size = N_ -  in_offset;
  if (out_size == -1) out_size = N_ - out_offset;
		
  // Shift all values by 1 such that -1 -> 0 (used for blurring)
  std::vector<float> values ((M_+2)*value_size, 0.0f);
  std::vector<float> new_values ((M_+2)*value_size, 0.0f);
	
  // Splatting
  for (int i = 0;  i < in_size; i++)
  {
    for (int j = 0; j <= d_; j++)
    {
      int o = static_cast<int> (offset_[(in_offset + i) * (d_ + 1) + j]) + 1;
      float w = barycentric_[(in_offset + i) * (d_ + 1) + j];
      for (int k = 0; k < value_size; k++)
        values[ o * value_size + k ] += w * in[ i * value_size + k ];
    }
  }
		
  for (int j = 0; j <= d_; j++)
  {
    for (int i = 0; i < M_; i++)
    {
      int old_val_idx = (i+1) * value_size;
      int new_val_idx = (i+1) * value_size;
				
      int n1 = blur_neighbors_[j*M_+i].n1+1;
      int n2 = blur_neighbors_[j*M_+i].n2+1;
      int n1_val_idx = n1 * value_size;
      int n2_val_idx = n2 * value_size;
      
      for (int k = 0; k < value_size; k++)
        new_values[new_val_idx + k] = values[old_val_idx + k] + 
        0.5f * (values[n1_val_idx + k] + values[n2_val_idx + k]);        
    }
    values.swap (new_values);
  }

  // Alpha is a magic scaling constant (write Andrew if you really wanna understand this)
  float alpha = 1.0f / (1.0f + static_cast<float> (pow(2.0f, -d_)));
		
  // Slicing
  for (int i = 0; i < out_size; i++){
    for (int k = 0; k < value_size; k++)
      out[i * value_size + k] = 0;
    for (int j = 0; j <= d_; j++){
      int o = static_cast<int> (offset_[(out_offset + i) * (d_ + 1) + j]) + 1;
      float w = barycentric_[(out_offset + i) * (d_ + 1) + j];
      for (int k = 0; k <value_size; k++)
        out[ i* value_size + k ] += w * values[ o * value_size + k ] * alpha;
    }
  }		
}
Exemple #2
0
inline void inner_panel_mixed_gemm_impl_nn(
        const double alpha,
        const SpParMat<index_type, value_type, SpDCCols<index_type, value_type> > &A,
        const El::DistMatrix<value_type, El::STAR, El::STAR> &S,
        const double beta,
        El::DistMatrix<value_type, col_d, El::STAR> &C) {

    int n_proc_side   = A.getcommgrid()->GetGridRows();
    int output_width  = S.Width();
    int output_height = A.getnrow();

    size_t rank = A.getcommgrid()->GetRank();
    size_t cb_row_offset = utility::cb_my_row_offset(A);

    typedef SpDCCols< index_type, value_type > col_t;
    typedef SpParMat< index_type, value_type, col_t > matrix_type;
    matrix_type &_A = const_cast<matrix_type&>(A);
    col_t &data = _A.seq();

    // 1) compute the local values still using the CombBLAS distribution (2D
    //    processor grid). We assume the result is dense.
    std::vector<double> local_matrix;
    mixed_gemm_local_part_nn(alpha, A, S, 0.0, local_matrix);

    // 2) reduce first along rows so that each processor owns the values in
    //    the output row of the SOMETHING/* matrix and values for processors in
    //    the same processor column.
    boost::mpi::communicator my_row_comm(
            A.getcommgrid()->GetRowWorld(), boost::mpi::comm_duplicate);

    // storage for other procs in same row communicator: rank -> (row, values)
    typedef std::vector<std::pair<int, std::vector<double> > > for_rank_t;
    std::vector<for_rank_t> for_rank(n_proc_side);

    for(size_t local_row = 0; local_row < data.getnrow(); ++local_row) {

        size_t row = local_row + cb_row_offset;

        // the owner for VR/* and VC/* matrices is independent of the column
        size_t target_proc = utility::owner(C, row, static_cast<size_t>(0));

        // if the target processor is not in the current row communicator, get
        // the value in the processor grid sharing the same row.
        if(!A.getcommgrid()->OnSameProcRow(target_proc))
            target_proc = static_cast<int>(rank / n_proc_side) *
                            n_proc_side + target_proc % n_proc_side;

        size_t target_row_rank = A.getcommgrid()->GetRankInProcRow(target_proc);

        // reduce partial row (FIXME: if the resulting matrix is still
        // expected to be sparse, change this to communicate only nnz).
        // Working on local_width columns concurrently per column processing
        // group.
        size_t local_width = S.Width();
        const value_type* buffer = &local_matrix[local_row * local_width];
        std::vector<value_type> new_values(local_width);
        boost::mpi::reduce(my_row_comm, buffer, local_width,
                &new_values[0], std::plus<value_type>(), target_row_rank);

        // processor stores result directly if it is the owning rank of that
        // row, save for subsequent communication along rows otherwise
        if(rank == utility::owner(C, row, static_cast<size_t>(0))) {
            int elem_lrow = C.LocalRow(row);
            for(size_t idx = 0; idx < local_width; ++idx) {
                int elem_lcol = C.LocalCol(idx);
                C.SetLocal(elem_lrow, elem_lcol,
                    new_values[idx] + beta * C.GetLocal(elem_lrow, elem_lcol));
            }
        } else if (rank == target_proc) {
            // store for later comm across rows
            for_rank[utility::owner(C, row, static_cast<size_t>(0)) / n_proc_side].push_back(
                    std::make_pair(row, new_values));
        }
    }

    // 3) gather remaining values along rows: we exchange all the values with
    //    other processors in the same communicator row and then add them to
    //    our local part.
    boost::mpi::communicator my_col_comm(
            A.getcommgrid()->GetColWorld(), boost::mpi::comm_duplicate);

    std::vector<for_rank_t> new_values;
    for(int i = 0; i < n_proc_side; ++i)
        boost::mpi::gather(my_col_comm, for_rank[i], new_values, i);

    // insert new values
    for(size_t proc = 0; proc < new_values.size(); ++proc) {
        const for_rank_t &cur  = new_values[proc];

        for(size_t i = 0; i < cur.size(); ++i) {
            int elem_lrow = C.LocalRow(cur[i].first);
            for(size_t j = 0; j < cur[i].second.size(); ++j) {
                size_t elem_lcol = C.LocalCol(j);
                C.SetLocal(elem_lrow, elem_lcol,
                        cur[i].second[j] + beta *
                        C.GetLocal(elem_lrow, elem_lcol));
            }
        }
    }
}
Exemple #3
0
void MainWindow::changeMoneyDiff()
{
    QVector<bool> is_correct(MONEY_EDIT_FIELDS_COUNT /*= 12*/, true);
    QVector<float> new_values(MONEY_EDIT_FIELDS_COUNT + MONEY_DIFF_FIELDS_COUNT, 0.0f);

    new_values[0] = ui_->CurRubNalEdit->text().toFloat(&is_correct[0]);
    new_values[1] = ui_->CurEurNalEdit->text().toFloat(&is_correct[1]);
    new_values[2] = ui_->CurUsdNalEdit->text().toFloat(&is_correct[2]);
    new_values[3] = ui_->CurRubElecEdit->text().toFloat(&is_correct[3]);
    new_values[4] = ui_->CurEurElecEdit->text().toFloat(&is_correct[4]);
    new_values[5] = ui_->CurUsdElecEdit->text().toFloat(&is_correct[5]);

    new_values[6] = ui_->OldRubNalEdit->text().toFloat(&is_correct[6]);
    new_values[7] = ui_->OldEurNalEdit->text().toFloat(&is_correct[7]);
    new_values[8] = ui_->OldUsdNalEdit->text().toFloat(&is_correct[8]);
    new_values[9] = ui_->OldRubElecEdit->text().toFloat(&is_correct[9]);
    new_values[10] = ui_->OldEurElecEdit->text().toFloat(&is_correct[10]);
    new_values[11] = ui_->OldUsdElecEdit->text().toFloat(&is_correct[11]);

    bool passed = true;
    for (bool elem : is_correct)
        passed &= elem;

    if (passed)
    {
        money_.setCurRubNalValue(new_values[0]);
        money_.setCurEurNalValue(new_values[1]);
        money_.setCurUsdNalValue(new_values[2]);
        money_.setCurRubElecValue(new_values[3]);
        money_.setCurEurElecValue(new_values[4]);
        money_.setCurUsdElecValue(new_values[5]);
        money_.setOldRubNalValue(new_values[6]);
        money_.setOldEurNalValue(new_values[7]);
        money_.setOldUsdNalValue(new_values[8]);
        money_.setOldRubElecValue(new_values[9]);
        money_.setOldEurElecValue(new_values[10]);
        money_.setOldUsdElecValue(new_values[11]);
    }

    QString value_str;

    ui_->CurRubNalEdit->setText(value_str.setNum(money_.getCurRubNalValue()));
    ui_->CurEurNalEdit->setText(value_str.setNum(money_.getCurEurNalValue()));
    ui_->CurUsdNalEdit->setText(value_str.setNum(money_.getCurUsdNalValue()));
    ui_->CurRubElecEdit->setText(value_str.setNum(money_.getCurRubElecValue()));
    ui_->CurEurElecEdit->setText(value_str.setNum(money_.getCurEurElecValue()));
    ui_->CurUsdElecEdit->setText(value_str.setNum(money_.getCurUsdElecValue()));

    ui_->OldRubNalEdit->setText(value_str.setNum(money_.getOldRubNalValue()));
    ui_->OldEurNalEdit->setText(value_str.setNum(money_.getOldEurNalValue()));
    ui_->OldUsdNalEdit->setText(value_str.setNum(money_.getOldUsdNalValue()));
    ui_->OldRubElecEdit->setText(value_str.setNum(money_.getOldRubElecValue()));
    ui_->OldEurElecEdit->setText(value_str.setNum(money_.getOldEurElecValue()));
    ui_->OldUsdElecEdit->setText(value_str.setNum(money_.getOldUsdElecValue()));

    ui_->RubDiffEdit->setText(value_str.setNum(money_.getRubDiffValue()));
    ui_->EurDiffEdit->setText(value_str.setNum(money_.getEurDiffValue()));
    ui_->UsdDiffEdit->setText(value_str.setNum(money_.getUsdDiffValue()));

    setQLineEditColor(ui_->RubDiffEdit, money_.getRubDiffValue());
    setQLineEditColor(ui_->EurDiffEdit, money_.getEurDiffValue());
    setQLineEditColor(ui_->UsdDiffEdit, money_.getUsdDiffValue());
}