Revision d6fa79fc Matrix/matrix.c

View differences:

Matrix/matrix.c
457 457
	{
458 458
		m = *ptr;
459 459
		neo = malloc(sizeof(struct matrix));
460
		matrix_init(neo, pos < m->rows ? m->rows - 1 : m->rows, pos < m->cols ? m->cols - 1 : m->cols);
461
		for(i = 0; i < m->rows; i++)
462
			for(j = 0; j < m->cols; j++)
460
		if (m->rows > 1 && m->cols > 1) // matrix case
461
		{
462
			matrix_init(neo, pos < m->rows ? m->rows - 1 : m->rows, pos < m->cols ? m->cols - 1 : m->cols);
463
			for(i = 0; i < m->rows; i++)
464
				for(j = 0; j < m->cols; j++)
465
				{
466
					if(i < pos)
467
					{
468
						if(j < pos) MAT_SET(neo, i, j, MAT_GET(m, i, j));
469
						if(j > pos) MAT_SET(neo, i, j-1, MAT_GET(m, i, j));
470
					}
471
					if(i > pos)
472
					{
473
						if(j < pos) MAT_SET(neo, i - 1, j, MAT_GET(m, i, j));
474
						if(j > pos) MAT_SET(neo, i - 1, j-1, MAT_GET(m, i, j));
475
					}
476
				}
477
		} else // vector case
478
		{
479
			if(m->rows == 1) // column vector
463 480
			{
464
				if(i < pos)
481
				matrix_init(neo, m->rows, m->cols - 1);
482
				for(i = 0; i < m->cols; i++)
465 483
				{
466
					if(j < pos) MAT_SET(neo, i, j, MAT_GET(m, i, j));
467
					if(j > pos) MAT_SET(neo, i, j-1, MAT_GET(m, i, j));
484
					if(i < pos) MAT_SET(neo, 0, i, MAT_GET(m, 0, i));
485
					if(i > pos) MAT_SET(neo, 0, i-1, MAT_GET(m, 0, i));
468 486
				}
469
				if(i > pos)
487
			}
488
			if(m->cols == 1) // row vector
489
			{
490
				matrix_init(neo, m->rows - 1, m->cols);
491
				for(i = 0; i < m->rows; i++)
470 492
				{
471
					if(j < pos) MAT_SET(neo, i - 1, j, MAT_GET(m, i, j));
472
					if(j > pos) MAT_SET(neo, i - 1, j-1, MAT_GET(m, i, j));
493
					if(i < pos) MAT_SET(neo, i, 0, MAT_GET(m, i, 0));
494
					if(i > pos) MAT_SET(neo, i-1, 0, MAT_GET(m, i, 0));
473 495
				}
474 496
			}
497
		}
475 498
		matrix_destroy(ptr);
476 499
		*ptr = neo;
477 500
	}

Also available in: Unified diff