コード例 #1
0
ファイル: communicator.cpp プロジェクト: huxuan/multiverso
 void Communicator::AddParameterByTableId(DataBlock *data_block, int table_id,
   std::vector<int> &nodes, std::vector<real*> &blocks, std::vector<real*> &recycle_blocks)
 {
   std::function<real*(int)> get_function;
   switch (table_id) {
   case kInputEmbeddingTableId:
     GetRows(worker_input_table_, nodes, blocks, option_->embeding_size);
     get_function = std::bind(&DataBlock::GetWeightIE, data_block, std::placeholders::_1);
     GetDeltaLoop(data_block, blocks, nodes, recycle_blocks, get_function);
     AddRows(worker_input_table_, nodes, blocks, option_->embeding_size);
     break;
   case kEmbeddingOutputTableId:
     GetRows(worker_output_table_, nodes, blocks, option_->embeding_size);
     get_function = std::bind(&DataBlock::GetWeightEO, data_block, std::placeholders::_1);
     GetDeltaLoop(data_block, blocks, nodes, recycle_blocks, get_function);
     AddRows(worker_output_table_, nodes, blocks, option_->embeding_size);
     break;
   case kSumGradient2IETableId:
     GetRows(worker_input_gradient_table_, nodes, blocks, option_->embeding_size);
     get_function = std::bind(&DataBlock::GetSumGradient2IE, data_block, std::placeholders::_1);
     GetDeltaLoop(data_block, blocks, nodes, recycle_blocks, get_function);
     AddRows(worker_input_gradient_table_, nodes, blocks, option_->embeding_size);
     break;
   case kSumGradient2EOTableId:
     GetRows(worker_output_gradient_table_, nodes, blocks, option_->embeding_size);
     get_function = std::bind(&DataBlock::GetSumGradient2EO, data_block, std::placeholders::_1);
     GetDeltaLoop(data_block, blocks, nodes, recycle_blocks, get_function);
     AddRows(worker_output_gradient_table_, nodes, blocks, option_->embeding_size);
     break;
   }
 }
コード例 #2
0
bool GeneralMatrix::Jointer_bottom(GeneralMatrix& other)
{
	if(other.nCol()!=nCol()) return FALSE;
	
	if(!AddRows(other.nRow(),ERRORVAL))
		return FALSE;	
	
return Paste(other,nRow()-other.nRow(),0);
}
コード例 #3
0
bool GeneralMatrix::ReSize(int iRow,int iCol, ELEMTYPE Val)const
{
	if(iRow<0||iCol<0) return FALSE;

	if(iRow==0) iCol = 0;

	AddRows(iRow-nRow(),Val);
	AddCols(iCol-nCol(),Val);

return TRUE;
}
コード例 #4
0
ファイル: StackPackEngine.c プロジェクト: steelwil/Kolumnz
/*----------------------------------------------------------------------------*/
void GameCreate(struct GameData* pGameData,
							int wnd,
						    int msgId,
						    int base,  
							int height,
							int startingLevel,
							int startingRows,
							int preview,
							int blkType,
							int lastLevel)
{
	int i;
	
	pGameData->m_MoveCount = 0;
	pGameData->m_DropCount = 0;
	pGameData->m_FullRowCount = 0;
	pGameData->m_FallingRow = -1;
	pGameData->m_FallingCol = 0;
	pGameData->m_FallingPiece = 0;
	pGameData->m_BlkRot = 0;
	pGameData->m_Score = 0;
	pGameData->m_Lines = 0;
	pGameData->m_GameOver = 0;
	pGameData->m_Paused = 0;
	
	pGameData->m_Parent = wnd;
	pGameData->m_MessageId = msgId;
	pGameData->m_Base = base;
	pGameData->m_Height = height;
	pGameData->m_Level = startingLevel;
	pGameData->m_StepDuration = 640-55*pGameData->m_Level;	// speedInt[m_Level-1];
	pGameData->m_PiecePreview = preview;
	pGameData->m_LastLevel = lastLevel;

	memset(&pGameData->m_Grid, 0, sizeof(pGameData->m_Grid));

	pGameData->m_MaxPieces = 0;
	for (i=0; i<32; i++)
	{
		if (blkType&(1<<i))
		{
			memcpy(&pGameData->m_Shapes[pGameData->m_MaxPieces], &Shapes[i], sizeof(long[4]));
			pGameData->m_MaxPieces++;
		}
	}

	AddRows(pGameData, startingRows);

	srand((unsigned)clock());
	pGameData->m_BlkPreviewNum = (int)(rand()/(double)0x7fffffff*pGameData->m_MaxPieces);
	pGameData->m_Preview = pGameData->m_Shapes[pGameData->m_BlkPreviewNum][pGameData->m_BlkRot];
	pGameData->m_Center = (pGameData->m_Base-4)/2;
};
コード例 #5
0
GeneralMatrix::GeneralMatrix(int iRow,int iCol)
{
	pHead = new HeadNode;
	
	 pHead->nRow = 0;
	 pHead->nCol = 0;
   pHead->pFirst = NULL;

	if(iRow<=0||iCol<=0) return;

     AddRows(iRow,0.0);
	 AddCols(iCol-1,0.0);
}
コード例 #6
0
bool GeneralMatrix::Jointer_Diagonal(GeneralMatrix& other,ELEMTYPE Val)
{
	int iCol;
	
	iCol = nRow()==0 ? other.nCol()-1 : other.nCol();

	if(!AddRows(other.nRow(),Val))
		return FALSE;
	if(!AddCols(iCol,Val))
	    return FALSE;

return Paste(other,nRow()-other.nRow(),nCol()-other.nCol()); 
}
コード例 #7
0
GeneralMatrix::GeneralMatrix(const GeneralMatrix& other)
{
	pHead = new HeadNode;
	
	 pHead->nRow = 0;
	 pHead->nCol = 0;
   pHead->pFirst = NULL;

	  AddRows(other.nRow(),0.0);
	  AddCols(other.nCol()-1,0.0);

	  *this += other; 
}
コード例 #8
0
ファイル: SMatrix.cpp プロジェクト: wsysuper/Synthesizer
SMatrix::SMatrix(int iRow,int iCol,ELEMTYPE Val)
{
	pHead = new HeadNode;
	
	 pHead->nRow = 0;
	 pHead->nCol = 0;
   pHead->pFirst = NULL;

	if(iRow<=0||iCol<=0) return;

	  AddRows(iRow,Val);
	  AddCols(iCol-1,Val);
}
コード例 #9
0
bool GeneralMatrix::T_Self()
{
    GeneralMatrix Temp(this->nCol(),this->nRow());

	int i,j;

	if(this->nCol()<2&&this->nRow()<2)
		return TRUE;

    Temp = this->Transpose();

    i = this->nCol() - this->nRow();
	j = this->nRow() - this->nCol();

    AddRows(i,0.0);
	AddCols(j,0.0);

	*this = Temp;

 return TRUE;   
}
コード例 #10
0
ファイル: Matrix.cpp プロジェクト: timothyandrew/minigolf
// Reduces all elements in a column except the diagonal element
// Returns 0 on success, 1 if the column cannot be reduced
int Matrix::ReduceColumn(int column, Matrix &inverse)
{
	// loop variable for working down column
	int row, pivot = column;

	// find the first non-zero element in the column
	// that is not above the diagonal
	for (row = pivot; row < 4; row++)
		if (fabs(Element(row, pivot)) > ERROR_TOLERANCE)
			break;

	// if we didn't find one, return an error code
	if (row == 4) return 1;

	// if we did, but it wasn't on the diagonal, swap with the pivot row
	// this makes sure we never get divide by zero errors
	if (row != pivot)
	{
		SwapRows(pivot, row);
		inverse.SwapRows(pivot, row);
	}

	// now scale the pivot row so the pivot element is one
	float scaleFactor = 1.0 / Element(pivot, pivot);
	ScaleRow(pivot, scaleFactor);
	inverse.ScaleRow(pivot, scaleFactor);

	// for each row
	for (row = 0; row < 4; row++)
	{
		// skip the row we're pivoting on
		if (row == column) continue;
		scaleFactor = -Element(row, pivot);
		AddRows(row, scaleFactor, pivot);
		inverse.AddRows(row, scaleFactor, pivot);
	}

	// and we're done
	return 0;
}
コード例 #11
0
ファイル: QRTestWidget.cpp プロジェクト: albertpadin/SAES
QRTestWidget::QRTestWidget(bool show_header)
{
	// TestTree

	m_TestTreeModel = Gtk::ListStore::create (m_TestTreeModelColumns);
	m_TestTreeView.set_model (m_TestTreeModel);
	m_TestTreeView.set_headers_visible(show_header);
	m_TestTreeView.set_headers_clickable(false);

	Glib::RefPtr<Gtk::TreeSelection> selection = m_TestTreeView.get_selection ();
//	selection->set_select_function (sigc::mem_fun (*this, &QRTestWidget::selection_callback));

	// Level Combo initialization

	m_TestTreeLevelComboModel = Gtk::ListStore::create (m_TestTreeModelLevelCombo);
	(*m_TestTreeLevelComboModel->append())[m_TestTreeModelLevelCombo.m_level_choices] = "Level L";
	(*m_TestTreeLevelComboModel->append())[m_TestTreeModelLevelCombo.m_level_choices] = "Level M";
	(*m_TestTreeLevelComboModel->append())[m_TestTreeModelLevelCombo.m_level_choices] = "Level Q";
	(*m_TestTreeLevelComboModel->append())[m_TestTreeModelLevelCombo.m_level_choices] = "Level H";


	// Test id

//	m_TestTreeView.append_column ("Test ID", m_TestTreeModelColumns.m_test_id);


	// data size

	Gtk::TreeView::Column* pDataColumn = Gtk::manage (new Gtk::TreeView::Column ("Data Size"));

	Gtk::CellRendererSpin* data_size_spin_renderer = Gtk::manage (new Gtk::CellRendererSpin() );
	Gtk::Adjustment* data_adj = manage (new Gtk::Adjustment (0.0, 0.0, .0, 1.0, 10.0, 100.0));

	data_size_spin_renderer->set_property ("digits", 0);
	data_size_spin_renderer->set_property ("adjustment", data_adj);
	data_size_spin_renderer->set_property ("editable", true);

	data_size_spin_renderer->property_alignment() = Pango::ALIGN_RIGHT;
	data_size_spin_renderer->property_editable () = true;
	data_size_spin_renderer->property_width() = 40;
	data_size_spin_renderer->property_height() = 40;

	data_size_spin_renderer->signal_edited().connect (sigc::mem_fun (*this, &QRTestWidget::on_data_size_edited));

	pDataColumn->pack_start (m_TestTreeModelColumns.m_data_label, false);
	pDataColumn->pack_start (*data_size_spin_renderer, true);
	pDataColumn->add_attribute (data_size_spin_renderer->property_text (), m_TestTreeModelColumns.m_data_size);
	m_TestTreeView.append_column (*pDataColumn);


	// version

	Gtk::TreeView::Column* pVersionColumn = Gtk::manage (new Gtk::TreeView::Column ("Version"));

	Pango::AttrList attr;

	Gtk::CellRendererText* version_text_renderer  = Gtk::manage (new Gtk::CellRendererText() );
	version_text_renderer->property_alignment() = Pango::ALIGN_RIGHT;

	Gtk::CellRendererSpin* version_spin_renderer = Gtk::manage (new Gtk::CellRendererSpin() );
	Gtk::Adjustment* ver_adj = manage (new Gtk::Adjustment (0.0, 0.0, 100.0, 1.0, 10.0, 100.0));

	version_spin_renderer->set_property ("digits", 0);
	version_spin_renderer->set_property ("adjustment", ver_adj);
	version_spin_renderer->set_property ("editable", true);
	version_spin_renderer->set_property ("width", 40);

	version_spin_renderer->signal_edited().connect (sigc::mem_fun (*this, &QRTestWidget::on_version_edited));

//	pVersionColumn->pack_start (m_TestTreeModelColumns.m_version_label, false);
	pVersionColumn->pack_start (*version_text_renderer, false);
	pVersionColumn->add_attribute(version_text_renderer->property_text (), m_TestTreeModelColumns.m_version_label);

	pVersionColumn->pack_start (*version_spin_renderer, true);
	pVersionColumn->add_attribute(version_spin_renderer->property_text (), m_TestTreeModelColumns.m_version);
	m_TestTreeView.append_column (*pVersionColumn);

//	m_TestTreeView.get_column (m_TestTreeView.append_column ("Data Size", *version_spin_renderer) - 1)
//			->add_attribute(version_spin_renderer->property_text (), m_TestTreeModelColumns.m_version);


	// correction level

	Gtk::TreeView::Column* pCorrectionColumn = Gtk::manage (new Gtk::TreeView::Column ("Correction Level"));

	m_ComboRenderer.property_model () = m_TestTreeLevelComboModel;
	m_ComboRenderer.property_has_entry () = false;
	m_ComboRenderer.property_text_column () = 0;
	m_ComboRenderer.property_editable () = true;
	m_ComboRenderer.property_width () = 80;

	m_ComboRenderer.signal_edited().connect (sigc::mem_fun (*this, &QRTestWidget::on_correction_edited));

	pCorrectionColumn->pack_start (m_TestTreeModelColumns.m_level_label, false);
	pCorrectionColumn->pack_start (m_ComboRenderer, true);
	pCorrectionColumn->add_attribute(m_ComboRenderer.property_text (), m_TestTreeModelColumns.m_correction_level);
	m_TestTreeView.append_column (*pCorrectionColumn);


	// Use Image

	Gtk::TreeView::Column* pImageColumn = Gtk::manage (new Gtk::TreeView::Column ("Image Based"));

	Gtk::CellRendererToggle* image_toggle_renderer = Gtk::manage (new Gtk::CellRendererToggle() );
	image_toggle_renderer->property_activatable() = true;
	image_toggle_renderer->property_sensitive() = true;
	image_toggle_renderer->property_width() = 70;

	image_toggle_renderer->signal_toggled().connect (sigc::mem_fun (*this, &QRTestWidget::on_use_image_edited));

	pImageColumn->pack_start(*image_toggle_renderer, true);
	pImageColumn->add_attribute(image_toggle_renderer->property_active() , m_TestTreeModelColumns.m_image_based);
	pImageColumn->add_attribute(image_toggle_renderer->property_visible() , m_TestTreeModelColumns.m_image_option_visible);
	m_TestTreeView.append_column (*pImageColumn);


	// pixel size

	Gtk::TreeView::Column* pPixelColumn = Gtk::manage (new Gtk::TreeView::Column ("Pixel Size"));

	Gtk::CellRendererSpin* pixel_size_spin_renderer = Gtk::manage (new Gtk::CellRendererSpin() );
	Gtk::Adjustment* pix_adj = manage (new Gtk::Adjustment (0.0, 0.0, 100.0, 1.0, 10.0, 100.0));

	pixel_size_spin_renderer->set_property ("digits", 0);
	pixel_size_spin_renderer->set_property ("adjustment", pix_adj);
	pixel_size_spin_renderer->set_property ("editable", true);
	pixel_size_spin_renderer->property_alignment() = Pango::ALIGN_RIGHT;
	pixel_size_spin_renderer->property_width () = 40;

	pixel_size_spin_renderer->signal_edited().connect (sigc::mem_fun (*this, &QRTestWidget::on_pixel_size_edited));

	pPixelColumn->pack_start (m_TestTreeModelColumns.m_pixel_label, false);
	pPixelColumn->pack_start (*pixel_size_spin_renderer, true);
	pPixelColumn->add_attribute(pixel_size_spin_renderer->property_text (), m_TestTreeModelColumns.m_pixel_size);
	pPixelColumn->add_attribute(pixel_size_spin_renderer->property_editable (), m_TestTreeModelColumns.m_image_based);
	pPixelColumn->add_attribute(pixel_size_spin_renderer->property_sensitive (), m_TestTreeModelColumns.m_image_based);
	m_TestTreeView.append_column (*pPixelColumn);


	// Use Background

	Gtk::TreeView::Column* pBgColumn = Gtk::manage (new Gtk::TreeView::Column ("Use Background"));

	Gtk::CellRendererToggle* bg_toggle_renderer = Gtk::manage (new Gtk::CellRendererToggle() );

	bg_toggle_renderer->property_width() = 90;
	bg_toggle_renderer->signal_toggled().connect (sigc::mem_fun (*this, &QRTestWidget::on_use_bkg_edited));

	pBgColumn->pack_start(*bg_toggle_renderer, true);
	pBgColumn->add_attribute(bg_toggle_renderer->property_active() , m_TestTreeModelColumns.m_use_background);
	pBgColumn->add_attribute(bg_toggle_renderer->property_visible() , m_TestTreeModelColumns.m_use_background_visible);
	pBgColumn->add_attribute(bg_toggle_renderer->property_activatable() , m_TestTreeModelColumns.m_image_based);
	pBgColumn->add_attribute(bg_toggle_renderer->property_sensitive() , m_TestTreeModelColumns.m_image_based);
	m_TestTreeView.append_column (*pBgColumn);


	// margin

	Gtk::TreeView::Column* pMarginColumn = Gtk::manage (new Gtk::TreeView::Column ("Margin Size"));

	Gtk::CellRendererSpin* margin_spin_renderer = Gtk::manage (new Gtk::CellRendererSpin() );
	Gtk::Adjustment* mar_adj = manage (new Gtk::Adjustment (0.0, 0.0, 100.0, 1.0, 10.0, 100.0));

	margin_spin_renderer->set_property ("digits", 0);
	margin_spin_renderer->set_property ("adjustment", mar_adj);
	margin_spin_renderer->set_property ("editable", true);
	margin_spin_renderer->set_property ("height", 40);
	margin_spin_renderer->set_property ("width", 40);

	margin_spin_renderer->signal_edited().connect (sigc::mem_fun (*this, &QRTestWidget::on_margin_edited));

	pMarginColumn->pack_start (m_TestTreeModelColumns.m_margin_label, false);
	pMarginColumn->pack_start (*margin_spin_renderer, true);
	pMarginColumn->add_attribute(margin_spin_renderer->property_text (), m_TestTreeModelColumns.m_margin);
	pMarginColumn->add_attribute(margin_spin_renderer->property_editable (), m_TestTreeModelColumns.m_use_background);
	pMarginColumn->add_attribute(margin_spin_renderer->property_sensitive (), m_TestTreeModelColumns.m_use_background);
	m_TestTreeView.append_column (*pMarginColumn);

	// Add Rows

	AddRows ();

	this->add (m_TestTreeView);
	this->show_all_children ();
}