CRSSparsity reshape(const CRSSparsity& a, int n, int m){
  casadi_assert_message(a.numel() == n*m,
     "reshape: number of elements must remain the same." << endl <<
     "Input argument has shape " << a.size1() << " x " << a.size2() << " =  " << a.numel() << ", while you request a reshape to " <<
     n << " x " << m << " =  " << n*m
  );

  // our strategy is: (col,rowind) -> (col,row) -> modulus calculus -> (col_new, row_new) -> sp_NZ
  std::vector<int> row = a.getRow();
  const std::vector<int> &col = a.col();

  std::vector<int> row_new(a.size());
  std::vector<int> col_new(a.size());
  
//  int i=0;int j=0; int z =0;
  for(int k=0; k<a.size(); ++k){
    int i = row[k];
    int j = col[k];
    int z = j+i*a.size2();
    row_new[k] = z/m;
    col_new[k] = z%m;
  }
  
  return  sp_triplet(n,m,row_new,col_new);
}
Beispiel #2
0
/* Make up a new definition.
 */
Symbol *
workspace_add_def( Workspace *ws, const char *str )
{
	Column *col = workspace_column_pick( ws );
	Symbol *sym;
	char *name;

#ifdef DEBUG
	printf( "workspace_add_def: %s\n", str );
#endif /*DEBUG*/

        if( !str || strspn( str, WHITESPACE ) == strlen( str ) )
		return( NULL );

	/* Try parsing as a "fred = 12" style def. 
	 */
	attach_input_string( str );
	if( (name = parse_test_define()) ) {
		sym = symbol_new( ws->sym->expr->compile, name );
		IM_FREE( name );
		attach_input_string( str + 
			IM_CLIP( 0, input_state.charpos - 1, strlen( str ) ) );
	}
	else {
		/* That didn't work. Make a sym from the col name.
		 */
		sym = workspace_add_symbol( ws );
		attach_input_string( str );
	}

	if( !symbol_user_init( sym ) || 
		!parse_rhs( sym->expr, PARSE_RHS ) ) {
		/* Another parse error.
		 */
		expr_error_get( sym->expr );

		/* Block changes to error_string ... symbol_destroy() 
		 * can set this for compound objects.
		 */
		error_block();
		IDESTROY( sym );
		error_unblock();

		return( NULL );
	}

	/* If we're redefining a sym, it might have a row already.
	 */
	if( !sym->expr->row )
		(void) row_new( col->scol, sym, &sym->expr->root );
	symbol_made( sym );
	workspace_set_modified( ws, TRUE );

	return( sym );
}
Beispiel #3
0
environment_t test_environment()
{
    row_t*row = row_new(4);
    row->inputs[0] = variable_new_continuous(1.0);
    row->inputs[1] = variable_new_continuous(2.0);
    row->inputs[2] = variable_new_continuous(4.0);
    row->inputs[3] = variable_new_categorical(5);

    environment_t e;
    e.row = row;
    return e;
}
Beispiel #4
0
void
RecordView::AddSheetRecord (Sheet * sheet) {
	ASSERT (sheet != NULL);
	GtkSheet * gtksheet = GTK_SHEET (sheet->gtk_sheet);
	GtkSheetRange range = {gtksheet->range.row0, 0, gtksheet->range.rowi, 0};
	Row * tuple = row_new (gtksheet->maxcol + 1);
	gint sheet_rows = 1;
	
	// More than one row is selected; we must transpose them all into the RV sheet.
	if (range.row0 != range.rowi) {
		sheet_rows = range.rowi - range.row0 + 1;
	}
			
	Sheet * record_sheet = this->wb->add_new_sheet (this->wb,sheet->name,gtksheet->maxcol + 1,sheet_rows);
	int column = 0, row = 0;

	do {
		sheet->get_row (sheet, range.row0, tuple->cells, tuple->size);

		// Change the titles of the columns to the row titles. This is only going to work if the
		// row titles have been explicitly set somewhere inside of the plugin.
		record_sheet->set_column_title (record_sheet,
												  row,
												  sheet->row_titles->cells[range.row0]->value->str);
		
		for (int ii = 0; ii < tuple->size; ii++) {
			// We only need to change the row titles once. This can happen on our last iteration.
			if (range.row0 == range.rowi) {
				record_sheet->set_row_title (record_sheet,
													  ii,
													  sheet->column_titles->cells[ii]->value->str);

			}
			
			record_sheet->set_cell (record_sheet,
											ii,
											column,
											tuple->cells[ii]->value->str);

			if (sheet->cells[range.row0][ii]->attributes.highlighted == TRUE) {
				record_sheet->set_cell_background (record_sheet, ii, column, "#ffffcc");
			}
			else if (((ii + 1) % 2) == 0) {
				record_sheet->set_cell_background (record_sheet, ii, column, "#f9f7f9");
			}
		}
		
		range.row0++; column++; row++;
	} while (range.row0 <= range.rowi);

	tuple->destroy (tuple);
}
Beispiel #5
0
void convert_row(DataPage * page, std::vector<Cell> cells)
{
	if (cells.size() <= 0) {
		return;
	}
	
	DataRow * row = row_new(cells[0].key.row.c_str());
	std::vector<Hypertable::ThriftGen::Cell>::iterator it = cells.begin();
	int index = 1;
	for (; it != cells.end(); it++) {
		DataCell * cell = cell_new(NULL, NULL);
		cell_set(cell, it->key.column_family.c_str(),
				 it->key.column_qualifier.c_str(),
				 it->value.c_str(),
				 it->key.revision);
		row_append(row, cell);
		index++;
	}
	
	//add row
	page_append(page, row);
}