Beispiel #1
0
static int _equalf(CMATRIX *a, double f)
{
	bool result;
	
	if (COMPLEX(a))
	{
		if (f == 0.0)
			return gsl_matrix_complex_isnull(CMAT(a));
		
		gsl_matrix_complex *m = gsl_matrix_complex_alloc(WIDTH(a), HEIGHT(a));
		gsl_matrix_complex_set_identity(m);
		gsl_matrix_complex_scale(m, gsl_complex_rect(f, 0));
		result = gsl_matrix_complex_equal(CMAT(a), m);
		gsl_matrix_complex_free(m);
	}
	else
	{
		if (f == 0.0)
			return gsl_matrix_isnull(MAT(a));
		
		gsl_matrix *m = gsl_matrix_alloc(WIDTH(a), HEIGHT(a));
		gsl_matrix_set_identity(m);
		gsl_matrix_scale(m, f);
		result = gsl_matrix_equal(MAT(a), m);
		gsl_matrix_free(m);
	}
	
	return result;
}
Beispiel #2
0
static int _equal(CMATRIX *a, CMATRIX *b)
{
	if (WIDTH(a) != WIDTH(b) || HEIGHT(a) != HEIGHT(b))
		return FALSE;
	
	if (COMPLEX(a) || COMPLEX(b))
	{
		MATRIX_ensure_complex(a);
		MATRIX_ensure_complex(b);
		return gsl_matrix_complex_equal(CMAT(a), CMAT(b));
	}
	else
		return gsl_matrix_equal(MAT(a), MAT(b));
}
Beispiel #3
0
int
main (void)
{
  int i, j, k = 0;
  size_t n = 100;

  gsl_matrix * a = gsl_matrix_alloc (n, n);
  gsl_matrix * b = gsl_matrix_alloc (n, n);
  gsl_matrix * c = gsl_matrix_alloc (n, n);

  for (i = 0; i < n; i++)
    {
      for (j = 0; j < n; j++)
        {
          gsl_matrix_set (a, i, j, 0.0);
          gsl_matrix_set (b, i, j, sin(i) + cos(j) + 3.0);
          gsl_matrix_set (c, i, j, -1.0 * (sin(i) + cos(j) + 3.0));
        }
    }

  // All the elements of a are zero (null).
  k += gsl_matrix_isnull (a);

  // All the elements of b are positive.
  k += gsl_matrix_ispos (b);

  // All the elements of c are negative.
  k += gsl_matrix_isneg (c);

  // All the elements of b are non-negative (zero).
  k += gsl_matrix_isnonneg (b);

  // The elements of c are multiplied by -1.0.
  // The matrix b and c are equal.
  gsl_matrix_scale (c, -1.0);
  k += gsl_matrix_equal (b, c);

  gsl_matrix_free (a);
  gsl_matrix_free (b);
  gsl_matrix_free (c);

  printf ("k = %d (should be 5)\n", k);

  return 0;
}