ext/comparison.c
VALUE nm_lt(VALUE self, VALUE another){
  nmatrix* left;
  Data_Get_Struct(self, nmatrix, left);

  nmatrix* result = ALLOC(nmatrix);
  result->dtype = nm_bool;
  result->stype = left->stype;
  result->count = left->count;
  result->ndims = left->ndims;
  result->shape = ALLOC_N(size_t, result->ndims);

  result->shape[0] = left->shape[0];
  result->shape[1] = left->shape[1];

  bool* result_elements = ALLOC_N(bool, result->shape[0] * result->shape[1]);

  switch (left->dtype) {
    case nm_bool: {
      double rha = NUM2DBL(another);
      bool* left_elements = (bool*)left->elements;

      for(size_t index = 0; index < left->count; index++){
        result_elements[index] = (((double)left_elements[index] < rha) ? true : false);
      }
      break;
    }
    case nm_int: {
      double rha = NUM2DBL(another);
      int* left_elements = (int*)left->elements;

      for(size_t index = 0; index < left->count; index++){
        result_elements[index] = (((double)left_elements[index] < rha) ? true : false);
      }
      break;
    }
    case nm_float32: {
      double rha = NUM2DBL(another);
      float* left_elements = (float*)left->elements;

      for(size_t index = 0; index < left->count; index++){
        result_elements[index] = (((double)left_elements[index] < rha) ? true : false);
      }
      break;
    }
    case nm_float64: {
      double rha = NUM2DBL(another);
      double* left_elements = (double*)left->elements;

      for(size_t index = 0; index < left->count; index++){
        result_elements[index] = ((left_elements[index] < rha) ? true : false);
      }
      break;
    }
    case nm_complex32: {
      rb_raise(rb_eSyntaxError, "SyntaxError: nm_complex32 does not support this operator.");
      // float complex rha = CMPLXF(NUM2DBL(rb_funcall(another, rb_intern("real"), 0, Qnil)), NUM2DBL(rb_funcall(another, rb_intern("imaginary"), 0, Qnil)));;
      // float complex* left_elements = (float complex*)left->elements;

      // for(size_t index = 0; index < left->count; index++){
      //   result_elements[index] = ((left_elements[index] < rha) ? true : false);
      // }
      break;
    }
    case nm_complex64: {
      rb_raise(rb_eSyntaxError, "SyntaxError: nm_complex64 does not support this operator.");
      // double complex rha = CMPLXF(NUM2DBL(rb_funcall(another, rb_intern("real"), 0, Qnil)), NUM2DBL(rb_funcall(another, rb_intern("imaginary"), 0, Qnil)));
      // double complex* left_elements = (double complex*)left->elements;

      // for(size_t index = 0; index < left->count; index++){
      //   result_elements[index] = ((left_elements[index] < rha) ? true : false);
      // }
      break;
    }
  }
  result->elements = result_elements;
  return Data_Wrap_Struct(NMatrix, NULL, nm_free, result);
}
/*
 * Greater operator.
 * Returns a single true or false value indicating whether
 * the element in a matrix is greater or smaller
 *
 */
Greater operator.
Returns a single true or false value indicating whether
the element in a matrix is greater or smaller
Greater operator . Returns a single true or false value indicating whether the element in a matrix is greater or smaller
VALUE nm_lt(VALUE self, VALUE another){
  nmatrix* left;
  Data_Get_Struct(self, nmatrix, left);
  nmatrix* result = ALLOC(nmatrix);
  result->dtype = nm_bool;
  result->stype = left->stype;
  result->count = left->count;
  result->ndims = left->ndims;
  result->shape = ALLOC_N(size_t, result->ndims);
  result->shape[0] = left->shape[0];
  result->shape[1] = left->shape[1];
  bool* result_elements = ALLOC_N(bool, result->shape[0] * result->shape[1]);
  switch (left->dtype) {
    case nm_bool: {
      double rha = NUM2DBL(another);
      bool* left_elements = (bool*)left->elements;
      for(size_t index = 0; index < left->count; index++){
        result_elements[index] = (((double)left_elements[index] < rha) ? true : false);
      }
      break;
    }
    case nm_int: {
      double rha = NUM2DBL(another);
      int* left_elements = (int*)left->elements;
      for(size_t index = 0; index < left->count; index++){
        result_elements[index] = (((double)left_elements[index] < rha) ? true : false);
      }
      break;
    }
    case nm_float32: {
      double rha = NUM2DBL(another);
      float* left_elements = (float*)left->elements;
      for(size_t index = 0; index < left->count; index++){
        result_elements[index] = (((double)left_elements[index] < rha) ? true : false);
      }
      break;
    }
    case nm_float64: {
      double rha = NUM2DBL(another);
      double* left_elements = (double*)left->elements;
      for(size_t index = 0; index < left->count; index++){
        result_elements[index] = ((left_elements[index] < rha) ? true : false);
      }
      break;
    }
    case nm_complex32: {
      rb_raise(rb_eSyntaxError, "SyntaxError: nm_complex32 does not support this operator.");
      break;
    }
    case nm_complex64: {
      rb_raise(rb_eSyntaxError, "SyntaxError: nm_complex64 does not support this operator.");
      break;
    }
  }
  result->elements = result_elements;
  return Data_Wrap_Struct(NMatrix, NULL, nm_free, result);
}
VALUE nm_lt ( VALUE self , VALUE another ) { nmatrix * left ; Data_Get_Struct ( self , nmatrix , left ) ; nmatrix * result = ALLOC ( nmatrix ) ; result -> dtype = nm_bool ; result -> stype = left -> stype ; result -> count = left -> count ; result -> ndims = left -> ndims ; result -> shape = ALLOC_N ( size_t , result -> ndims ) ; result -> shape [ 0 ] = left -> shape [ 0 ] ; result -> shape [ 1 ] = left -> shape [ 1 ] ; bool * result_elements = ALLOC_N ( bool , result -> shape [ 0 ] * result -> shape [ 1 ] ) ; switch ( left -> dtype ) { case nm_bool : { double rha = NUM2DBL ( another ) ; bool * left_elements = ( bool * ) left -> elements ; for ( size_t index = 0 ; index < left -> count ; index ++ ) { result_elements [ index ] = ( ( ( double ) left_elements [ index ] < rha ) ? true : false ) ; } break ; } case nm_int : { double rha = NUM2DBL ( another ) ; int * left_elements = ( int * ) left -> elements ; for ( size_t index = 0 ; index < left -> count ; index ++ ) { result_elements [ index ] = ( ( ( double ) left_elements [ index ] < rha ) ? true : false ) ; } break ; } case nm_float32 : { double rha = NUM2DBL ( another ) ; float * left_elements = ( float * ) left -> elements ; for ( size_t index = 0 ; index < left -> count ; index ++ ) { result_elements [ index ] = ( ( ( double ) left_elements [ index ] < rha ) ? true : false ) ; } break ; } case nm_float64 : { double rha = NUM2DBL ( another ) ; double * left_elements = ( double * ) left -> elements ; for ( size_t index = 0 ; index < left -> count ; index ++ ) { result_elements [ index ] = ( ( left_elements [ index ] < rha ) ? true : false ) ; } break ; } case nm_complex32 : { rb_raise ( rb_eSyntaxError , " " ) ; break ; } case nm_complex64 : { rb_raise ( rb_eSyntaxError , " " ) ; break ; } } result -> elements = result_elements ; return Data_Wrap_Struct ( NMatrix , NULL , nm_free , result ) ; }
Greater operator.
Greater operator .
// float complex rha = CMPLXF(NUM2DBL(rb_funcall(another, rb_intern("real"), 0, Qnil)), NUM2DBL(rb_funcall(another, rb_intern("imaginary"), 0, Qnil)));; // float complex* left_elements = (float complex*)left->elements; // for(size_t index = 0; index < left->count; index++){ //   result_elements[index] = ((left_elements[index] < rha) ? true : false); // } // double complex rha = CMPLXF(NUM2DBL(rb_funcall(another, rb_intern("real"), 0, Qnil)), NUM2DBL(rb_funcall(another, rb_intern("imaginary"), 0, Qnil))); // double complex* left_elements = (double complex*)left->elements; // for(size_t index = 0; index < left->count; index++){ //   result_elements[index] = ((left_elements[index] < rha) ? true : false); // }