class Dobjects::Dtable

Dtables are a specialized implementation of two-dimensional arrays of double precision floating point numbers. They are intended for use in applications needing efficient processing of large 2D tables of numeric data. Essentially any of the operations you might do with a Ruby Array of numbers can also be done with a Dtable. Dtables follow the same design philosophy as Dvector and uses Dvectors for several operations.

Public Class Methods

_load(p1) click to toggle source

Called by the marshalling mechanism to retrieve a permanent copy of a Dtable.

VALUE dtable_load(VALUE klass, VALUE str)
{
  VALUE ret = Qnil;
  VALUE s = StringValue(str);
  unsigned char * buf = (unsigned char *) StringValuePtr(s);
  unsigned char * dest = buf + RSTRING_LEN(s);
  unsigned i; /* for GET_UNSIGNED */
  unsigned tmp = 0;
  long rows, cols;
  long x,y;
  double ** data;
  double * col;
  /*  depending on the first byte, the decoding will be different */
  switch(*(buf++)) 
    {
    case 1:
      GET_UNSIGNED(tmp, buf);
      rows = tmp;
      GET_UNSIGNED(tmp, buf);
      cols = tmp;
      /* create a new Dtable with the right size */
      ret = dtable_init(dtable_alloc(cDtable), cols, rows);
      data = Dtable_Ptr(ret, NULL, NULL);
      for(x = 0; x < rows; x++) 
        {
          col = data[x];
          for(y = 0; y< cols; y++)
            {
              if(buf + 8 > dest)
                {
                  rb_raise(rb_eRuntimeError, 
                           "corrupted data given to Dtable._load");
                  break;
                }     
              else 
                {
                  col[y] = get_double(buf);
                  buf += 8;
                }
            }
        }
      break;
    default:
      rb_raise(rb_eRuntimeError, "corrupted data given to Dtable._load");
    }
  return ret;
}
new(num_cols, num_rows) → a_dtable click to toggle source

Returns a new Dtable with the requested dimensions.

VALUE dtable_initialize(int argc, VALUE *argv, VALUE ary) {
   if (argc != 2) rb_raise(rb_eArgError, "need 2 args for Dtable.new(num_cols, num_rows)");
   int num_cols = NUM2INT(argv[0]), num_rows = NUM2INT(argv[1]);
   return dtable_init(ary, num_cols, num_rows);
}

Public Instance Methods

%(p1)
Alias for: modulo
*(p1)
Alias for: mul
**(p1)
Alias for: pow
+(p1)
Alias for: add
-(p1)
Alias for: sub
-@()
Alias for: neg
/(p1)
Alias for: div
[](p1, p2)
Alias for: at
dtable[row,col] = number → number click to toggle source

Replaces the element at location row, col by the given number.

VALUE dtable_aset(VALUE ary, VALUE xloc, VALUE yloc, VALUE val) {
   dtable_store(ary, NUM2LONG(xloc), NUM2LONG(yloc), NUM2DBL(val));
   return val;
}
_dump(p1) click to toggle source

Called by the marshalling mechanism to store a permanent copy of a Dtable. limit is simply ignored.

VALUE dtable_dump(VALUE ary, VALUE limit)
{
  int i; /* for STORE_UNSIGNED */
  long rows, cols;
  long x, y;
  double ** data = Dtable_Ptr(ary, &cols, &rows);
  double * col;
  long target_len = 1 /* first signature byte */
    + 8 /* 2 * length */
    + cols * rows * 8 ;
  unsigned u_len;
  VALUE str = rb_str_new2("");
  rb_str_resize(str,target_len); /* This seems to do the trick */
  /* \begin{playing with ruby's internals} */
  unsigned char * ptr = (unsigned char *) RSTRING_PTR(str);
  /* signature byte */
  (*ptr++) = DTABLE_DUMP_VERSION;
  u_len = (unsigned) rows; /* limits to 4 billions rows */
  STORE_UNSIGNED(u_len, ptr); /* destroys u_len */
  u_len = (unsigned) cols; /* limits to 4 billions columns */
  STORE_UNSIGNED(u_len, ptr); /* destroys u_len */
  for(x = 0; x < rows; x++)
    {
      col = data[x];
      for(y = 0; y < cols; y++)
        {
          store_double(*(col++), ptr);
          ptr += 8;
        }
    }
  /*  RSTRING_LEN(str) = target_len;*/
  return str;
  /* \end{playing with ruby's internals} */
}
abs → a_dtable click to toggle source

Returns of copy of dtable with all entries replaced by their absolute values.

VALUE dtable_abs(VALUE ary) {
   return dtable_apply_math_op(ary, fabs);
}
abs! → dtable click to toggle source

Replace each entry x of dtable with abs(x).

VALUE dtable_abs_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, fabs);
}
acos → a_dtable click to toggle source

Returns of copy of dtable with entry x replaced by acos(x).

VALUE dtable_acos(VALUE ary) {
   return dtable_apply_math_op(ary, acos);
}
acos! → dtable click to toggle source

Replace each entry x of dtable with acos(x).

VALUE dtable_acos_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, acos);
}
acosh → a_dtable click to toggle source

Returns of copy of dtable with entry x replaced by acosh(x).

VALUE dtable_acosh(VALUE ary) {
   return dtable_apply_math_op(ary, do_acosh);
}
acosh! → dtable click to toggle source

Replace each entry x of dtable with acosh(x).

VALUE dtable_acosh_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, do_acosh);
}
add(number) → a_dtable click to toggle source
add(other) → a_dtable
dtable + number → a_dtable
number + dtable → a_dtable
dtable + other → a_dtable

When argument is a number, this operation returns a copy of dtable with each entry x replaced by x + number. When argument is a data array, this operation returns a copy of dtable with each entry x replaced by x + the corresponding entry in the other data array.

VALUE dtable_add(VALUE ary, VALUE arg) {
   return dtable_apply_math_op2(ary, arg, do_add);
}
Also aliased as: +, plus
add!(number) → dtable click to toggle source
add!(other) → dtable

When argument is a number, each entry x in dtable is replaced by x + number. When argument is a data array, each entry x in dtable is replaced by x + the corresponding entry in the other data array.

VALUE dtable_add_bang(VALUE ary, VALUE arg) {
   return dtable_apply_math_op2_bang(ary, arg, do_add);
}
Also aliased as: plus!
as_exponent_of(number) → a_dtable click to toggle source
as_exponent_of(other) → a_dtable

When argument is a number, this operation returns a copy of dtable with each entry x replaced by number ** x. When argument is a data array, this operation returns a copy of dtable with each entry x replaced by the corresponding entry in the other data array raised to the power x.

VALUE dtable_as_exponent_of(VALUE ary, VALUE arg) {
   return dtable_apply_math_op2(ary, arg, do_as_exponent_of);
}
as_exponent_of!(number) → dtable click to toggle source
as_exponent_of!(other) → dtable

When argument is a number, this operation replaces each entry x of dtable by number ** x. When argument is a data array, this operation replaces each entry x of dtable by the corresponding entry in the other data array raised to the power x.

VALUE dtable_as_exponent_of_bang(VALUE ary, VALUE arg) {
   return dtable_apply_math_op2_bang(ary, arg, do_as_exponent_of);
}
asin → a_dtable click to toggle source

Returns of copy of dtable with entry x replaced by asin(x).

VALUE dtable_asin(VALUE ary) {
   return dtable_apply_math_op(ary, asin);
}
asin! → dtable click to toggle source

Replace each entry x of dtable with asin(x).

VALUE dtable_asin_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, asin);
}
asinh → a_dtable click to toggle source

Returns of copy of dtable with entry x replaced by asinh(x).

VALUE dtable_asinh(VALUE ary) {
   return dtable_apply_math_op(ary, do_asinh);
}
asinh! → dtable click to toggle source

Replace each entry x of dtable with asinh(x).

VALUE dtable_asinh_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, do_asinh);
}
dtable[row,col] → number or nil click to toggle source
at(row,col) → number or nil

Returns the element at location row, col. Returns nil if the location is out of range.

VALUE dtable_at(VALUE ary, VALUE xloc, VALUE yloc) {
   return dtable_entry(ary, NUM2LONG(xloc), NUM2LONG(yloc));
}
Also aliased as: []
atan → a_dtable click to toggle source

Returns of copy of dtable with entry x replaced by atan(x).

VALUE dtable_atan(VALUE ary) {
   return dtable_apply_math_op(ary, atan);
}
atan! → dtable click to toggle source

Replace each entry x of dtable with atan(x).

VALUE dtable_atan_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, atan);
}
atan2(number) → a_dtable click to toggle source
atan2(other) → a_dtable

When argument is a number, this operation returns a copy of dtable with each entry x replaced by the angle whose tangent is x/number. When argument is a data array, this operation returns a copy of dtable with each entry x replaced by the angle whose tangent is x divided by the corresponding entry in the other data array.

VALUE dtable_atan2(VALUE ary, VALUE arg) {
   return dtable_apply_math_op2(ary, arg, atan2);
}
atan2!(number) → dtable click to toggle source
atan2!(other) → dtable

When argument is a number, this operation replaces each entry x of dtable by the angle whose tangent is x/number. When argument is a data array, this operation replaces each entry x of dtable by the angle whose tangent is x divided by the corresponding entry in the other data array.

VALUE dtable_atan2_bang(VALUE ary, VALUE arg) {
   return dtable_apply_math_op2_bang(ary, arg, atan2);
}
atanh → a_dtable click to toggle source

Returns of copy of dtable with entry x replaced by atanh(x).

VALUE dtable_atanh(VALUE ary) {
   return dtable_apply_math_op(ary, do_atanh);
}
atanh! → dtable click to toggle source

Replace each entry x of dtable with atanh(x).

VALUE dtable_atanh_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, do_atanh);
}
ceil → a_dtable click to toggle source

Returns of copy of dtable with entry x replaced by smallest integer not less than x.

VALUE dtable_ceil(VALUE ary) {
   return dtable_apply_math_op(ary, ceil);
}
ceil! → dtable click to toggle source

Replace each entry x of dtable with the smallest integer not less than x.

VALUE dtable_ceil_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, ceil);
}
clear → dtable click to toggle source

Sets the entries of dtable array to zero.

VALUE dtable_clear(VALUE ary, VALUE val) {
   set_dtable_vals(ary, 0.0);
   return ary;
}
column(int) → a_dvec click to toggle source

Creates a Dvector holding a copy of the contents of the requested column.

VALUE dtable_column(VALUE ary, VALUE column_num) {
   Dtable *d = Get_Dtable(ary);
   column_num = rb_Integer(column_num);
   int i, column = NUM2INT(column_num), len;
   if (column < 0 || column >= d->num_cols)
      rb_raise(rb_eArgError, "Asking for column i = %i from array with only %li columns", column, d->num_cols);
   VALUE dvec = Dvector_Create();
   len = d->num_rows;
   Dvector_Data_Resize(dvec, len);
   for (i=0; i < len; i++)
      Dvector_Store_Double(dvec, i, d->ptr[i][column]);
   return dvec;
}
cos → a_dtable click to toggle source

Returns of copy of dtable with entry x replaced by cos(x).

VALUE dtable_cos(VALUE ary) {
   return dtable_apply_math_op(ary, cos);
}
cos! → dtable click to toggle source

Replace each entry x of dtable with cos(x).

VALUE dtable_cos_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, cos);
}
cosh → a_dtable click to toggle source

Returns of copy of dtable with entry x replaced by cosh(x).

VALUE dtable_cosh(VALUE ary) {
   return dtable_apply_math_op(ary, cosh);
}
cosh! → dtable click to toggle source

Replace each entry x of dtable with cosh(x).

VALUE dtable_cosh_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, cosh);
}
div(number) → a_dtable click to toggle source
div(other) → a_dtable
dtable - number → a_dtable
number - dtable → a_dtable
dtable - other → a_dtable

When argument is a number, this operation returns a copy of dtable with each entry x replaced by x / number. When argument is a data array, this operation returns a copy of dtable with each entry x replaced by x / the corresponding entry in the other data array.

VALUE dtable_div(VALUE ary, VALUE arg) {
   return dtable_apply_math_op2(ary, arg, do_div);
}
Also aliased as: /
div!(number) → dtable click to toggle source
div!(other) → dtable

When argument is a number, each entry x in dtable is replaced by x / number. When argument is a data array, each entry x in dtable is replaced by x / the corresponding entry in the other data array.

VALUE dtable_div_bang(VALUE ary, VALUE arg) {
   return dtable_apply_math_op2_bang(ary, arg, do_div);
}
dup → a_dtable click to toggle source

Returns a copy of dtable. For performance sensitive situations involving a series of operations, first make a copy using dup and then do “bang” operations to modify the result without further copying.

VALUE dtable_dup(VALUE ary) {
   Dtable *d = Get_Dtable(ary);
   int i, j, num_cols = d->num_cols, num_rows = d->num_rows;
   VALUE new = dtable_init(dtable_alloc(cDtable), num_cols, num_rows);
   Dtable *d2 = Get_Dtable(new);
   double **src, **dest;
   src = d->ptr; dest = d2->ptr;
   for (i = 0; i < num_rows; i++) {
      for (j = 0; j < num_cols; j++) {
         dest[i][j] = src[i][j];
      }
   }
   return new;
}
each_column{|col| } click to toggle source

Iterates over all columns and executes the given block

VALUE dtable_each_column(VALUE ary){
each_row{|row| } click to toggle source

Iterates over all rows and executes the given block

VALUE dtable_each_row(VALUE ary){
exp → a_dtable click to toggle source

Returns of copy of dtable with each entry x replaced by exp(x).

VALUE dtable_exp(VALUE ary) {
   return dtable_apply_math_op(ary, exp);
}
exp! → dtable click to toggle source

Replace each entry x of dtable with exp(x).

VALUE dtable_exp_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, exp);
}
exp10 → a_dtable click to toggle source

Returns of copy of dtable with each entry x replaced by 10**x.

VALUE dtable_exp10(VALUE ary) {
   return dtable_apply_math_op(ary, do_exp10);
}
exp10! → dtable click to toggle source

Replace each entry x of dtable with 10**x.

VALUE dtable_exp10_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, do_exp10);
}
floor → a_dtable click to toggle source

Returns of copy of dtable with each entry x replaced by largest integer not greater than x.

VALUE dtable_floor(VALUE ary) {
   return dtable_apply_math_op(ary, floor);
}
floor! → dtable click to toggle source

Replace each entry x of dtable with the largest integer not greater than x.

VALUE dtable_floor_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, floor);
}
interpolate(Xs, Ys, nx, ny, x_start, x_end, y_start, y_end) → a_dtable click to toggle source

Returns a copy of dtable with the values interpolated given the proper X and Y axis to create a uniform spaced result in the X- and Y direction consisting of nx- and ny values for each direction.

VALUE dtable_interpolate(VALUE ary, VALUE x_vec, VALUE y_vec, VALUE nx_val, VALUE ny_val, VALUE xstart_val, VALUE xend_val, VALUE ystart_val, VALUE yend_val)
{
   Dtable *d = Get_Dtable(ary);
        int nx = NUM2DBL(rb_Integer(nx_val));
        int ny = NUM2DBL(rb_Integer(ny_val));
        int i, j, num_cols = d->num_cols, num_rows = d->num_rows/*, last_row = num_rows - 1*/;
        
   long xsrc_len, ysrc_len;
   double *xsrc = Dvector_Data_for_Read(x_vec, &xsrc_len);
   double *ysrc = Dvector_Data_for_Read(y_vec, &ysrc_len);
        if(xsrc_len != num_cols) rb_raise(rb_eArgError, "Number of x values (%ld) do not match the number of columns (%d)", xsrc_len, num_cols);
        if(ysrc_len != num_rows) rb_raise(rb_eArgError, "Number of y values (%ld) do not match the number of rows (%d)", ysrc_len, num_rows);
   VALUE new = dtable_init(dtable_alloc(cDtable), nx, ny);
   Dtable *d2 = Get_Dtable(new);
   double **src, **dest;
        xstart_val = rb_Float(xstart_val);
        double xstart = NUM2DBL(rb_Float(xstart_val));
        if(xstart < xsrc[0]) rb_raise(rb_eArgError, "The start x value %g is smaller than the bound (%g)", xstart, xsrc[0]);
        double xend = NUM2DBL(rb_Float(xend_val));
        if(xend > xsrc[xsrc_len-1]) rb_raise(rb_eArgError, "The end x value %g is bigger than the bound (%g)", xend, xsrc[xsrc_len-1]);
        double ystart = NUM2DBL(rb_Float(ystart_val));
        if(ystart < ysrc[0]) rb_raise(rb_eArgError, "The start y value %g is smaller than the bound (%g)", ystart, ysrc[0]);
        double yend = NUM2DBL(rb_Float(yend_val));
        if(yend > ysrc[ysrc_len-1]) rb_raise(rb_eArgError, "The end y value %g is bigger than the bound (%g)", yend, ysrc[ysrc_len-1]);
        double dx = (xend-xstart)/(nx-1);
        double dy = (yend-ystart)/(ny-1);
        double xcurrent = xstart;
        double ycurrent = ystart;
        double intvalue;
        int isrc = 1;
        int jsrc = 1;
   src = d->ptr; dest = d2->ptr;
   for (i = 1; i < ny+1; i++) {
                while(ysrc[isrc] < ycurrent && ycurrent < ysrc[ysrc_len-1]){
                        isrc++;
                }
      for (j = 1; j < nx+1; j++) {
                        while(xsrc[jsrc] < xcurrent && xcurrent < xsrc[xsrc_len-1]){
                                jsrc++;
                        }
                        intvalue = (
                                ( src[isrc-1][jsrc-1]*(ysrc[isrc]-ycurrent)*(xsrc[jsrc]-xcurrent)) +
                                ( src[isrc][jsrc - 1] * (ycurrent - ysrc[isrc - 1]) * (xsrc[jsrc] - xcurrent) ) +
                                ( src[isrc - 1][jsrc] * (ysrc[isrc] - ycurrent) * (xcurrent - xsrc[jsrc - 1]) ) +
                                ( src[isrc][jsrc] * (ycurrent - ysrc[isrc - 1]) * (xcurrent - xsrc[jsrc - 1]) )
                        );
                        intvalue = intvalue / ( (ysrc[isrc] - ysrc[isrc - 1]) * (xsrc[jsrc] - xsrc[jsrc - 1]) );
         dest[i-1][j-1] = intvalue;
                        xcurrent += dx;
      }
                xcurrent = xstart;
                jsrc = 1;
                ycurrent += dy;
   }
   return new;
}
inv → a_dtable click to toggle source

Returns of copy of dtable with each entry x replaced by 1/x.

VALUE dtable_inv(VALUE ary) {
   return dtable_apply_math_op(ary, do_inv);
}
inv! → dtable click to toggle source

Replace each entry x of dtable with 1/x.

VALUE dtable_inv_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, do_inv);
}
log → a_dtable click to toggle source

Returns of copy of dtable with each entry x replaced by log(x).

VALUE dtable_log(VALUE ary) {
   return dtable_apply_math_op(ary, log);
}
log! → dtable click to toggle source

Replace each entry x of dtable with log(x).

VALUE dtable_log_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, log);
}
log10 → a_dtable click to toggle source

Returns of copy of dtable with each entry x replaced by log10(x).

VALUE dtable_log10(VALUE ary) {
   return dtable_apply_math_op(ary, log10);
}
log10! → dtable click to toggle source

Replace each entry x of dtable with log10(x).

VALUE dtable_log10_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, log10);
}
max → float click to toggle source

Returns the maximum entry in dtable.

VALUE dtable_max(VALUE ary) {
   Dtable *d = Get_Dtable(ary);
   double zmax = Max2dGrid(d->ptr, d->num_cols, d->num_rows);
   return rb_float_new(zmax);
}
max_lt(val) → float or nil click to toggle source

Returns the maximum entry in dtable which is less than val, or nil if no such entry if found.

VALUE dtable_max_lt(VALUE ary, VALUE val) {
   Dtable *d = Get_Dtable(ary);
   val = rb_Float(val);
   double zmax, z = NUM2DBL(val);
   if (Max_Lt_2dGrid(d->ptr, z, d->num_cols, d->num_rows, &zmax))
      return rb_float_new(zmax);
   return Qnil;
}
min → float click to toggle source

Returns the minimum entry in dtable.

VALUE dtable_min(VALUE ary) {
   Dtable *d = Get_Dtable(ary);
   double zmin = Min2dGrid(d->ptr, d->num_cols, d->num_rows);
   return rb_float_new(zmin);
}
min_gt(val) → float or nil click to toggle source

Returns the minimum entry in dtable which is greater than val, or nil if no such entry if found.

VALUE dtable_min_gt(VALUE ary, VALUE val) {
   Dtable *d = Get_Dtable(ary);
   val = rb_Float(val);
   double zmin, z = NUM2DBL(val);
   if (Min_Gt_2dGrid(d->ptr, z, d->num_cols, d->num_rows, &zmin))
      return rb_float_new(zmin);
   return Qnil;
}
minus(p1)
Alias for: sub
minus!(p1)
Alias for: sub!
mod(p1)
Alias for: modulo
mod!(p1)
Alias for: modulo!
modulo(number) → a_dtable click to toggle source
mod(number) → a_dtable
modulo(other) → a_dtable
mod(other) → a_dtable
dtable % number → a_dtable
dtable % other → a_dtable

When argument is a number, this operation returns a copy of dtable with each entry x replaced by x % number. When argument is a data array, this operation returns a copy of dtable with each entry x replaced by x % the corresponding entry in the other data array.

VALUE dtable_mod(VALUE ary, VALUE arg) {
   return dtable_apply_math_op2(ary, arg, do_mod);
}
Also aliased as: mod, %
modulo!(number) → dtable click to toggle source
mod!(number) → dtable
modulo!(other) → dtable
mod!(other) → dtable

When argument is a number, this operation returns a copy of dtable with each entry x replaced by x % number. When argument is a data array, this operation returns a copy of dtable with each entry x replaced by x % the corresponding entry in the other data array.

VALUE dtable_modulo_bang(VALUE ary, VALUE arg) {
   return dtable_apply_math_op2_bang(ary, arg, do_mod);
}
Also aliased as: mod!
mul(number) → a_dtable click to toggle source
mul(other) → a_dtable
dtable - number → a_dtable
number - dtable → a_dtable
dtable - other → a_dtable

When argument is a number, this operation returns a copy of dtable with each entry x replaced by x * number. When argument is a data array, this operation returns a copy of dtable with each entry x replaced by x * the corresponding entry in the other data array.

VALUE dtable_mul(VALUE ary, VALUE arg) {
   return dtable_apply_math_op2(ary, arg, do_mul);
}
Also aliased as: *, times
mul!(number) → dtable click to toggle source
mul!(other) → dtable

When argument is a number, each entry x in dtable is replaced by x * number. When argument is a data array, each entry x in dtable is replaced by x * the corresponding entry in the other data array.

VALUE dtable_mul_bang(VALUE ary, VALUE arg) {
   return dtable_apply_math_op2_bang(ary, arg, do_mul);
}
Also aliased as: times!
neg → a_dtable click to toggle source

Returns of copy of dtable with each entry x replaced by -x.

VALUE dtable_neg(VALUE ary) {
   return dtable_apply_math_op(ary, do_neg);
}
Also aliased as: -@
neg! → dtable click to toggle source

Replace each entry x of dtable with -x.

VALUE dtable_neg_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, do_neg);
}
num_cols → integer click to toggle source

Returns the number of entries in the x dimension of dtable.

VALUE dtable_num_cols(VALUE ary) {
   Dtable *d = Get_Dtable(ary);
   return LONG2NUM(d->num_cols);
}
num_rows → integer click to toggle source

Returns the number of entries in the y dimension of dtable.

VALUE dtable_num_rows(VALUE ary) {
   Dtable *d = Get_Dtable(ary);
   return LONG2NUM(d->num_rows);
}
plus(p1)
Alias for: add
plus!(p1)
Alias for: add!
pow(number) → a_dtable click to toggle source
pow(other) → a_dtable
raised_to(number) → a_dtable
raised_to(other) → a_dtable
dtable ** number → a_dtable
dtable ** other → a_dtable

When argument is a number, this operation returns a copy of dtable with each entry x replaced by x ** number. When argument is a data array, this operation returns a copy of dtable with each entry x replaced by x ** the corresponding entry in the other data array.

VALUE dtable_pow(VALUE ary, VALUE arg) {
   return dtable_apply_math_op2(ary, arg, pow);
}
Also aliased as: raised_to, **
pow!(number) → dtable click to toggle source
pow!(other) → dtable
raised_to!(number) → dtable
raised_to!(other) → dtable

When argument is a number, this operation returns a copy of dtable with each entry x replaced by x ** number. When argument is a data array, this operation returns a copy of dtable with each entry x replaced by x ** the corresponding entry in the other data array.

VALUE dtable_pow_bang(VALUE ary, VALUE arg) {
   return dtable_apply_math_op1_bang(ary, arg, pow);
}
Also aliased as: raised_to!
raised_to(p1)
Alias for: pow
raised_to!(p1)
Alias for: pow!
read(filename, skip_lines=0) → dtable click to toggle source

The contents of dtable are replaced by the contents of the file, starting after skipping the specified number of lines. The values in the file are listed with row number 0 first.

VALUE dtable_read(int argc, VALUE *argv, VALUE self) {
   if ((argc < 1) || (argc > 2))
      rb_raise(rb_eArgError, "wrong # of arguments(%d for 1 or 2)",argc);
   VALUE filename = argv[0];
   int skip_lines = (argc==2)? NUM2INT(rb_Integer(argv[1])) : 0;
   return Read_Dtable(self, StringValuePtr(filename), skip_lines);
}
remainder(number) → a_dtable click to toggle source
remainder(other) → a_dtable

When the argument is a number, this operation returns a copy of dtable with each entry x replaced by the remainder of x divided by number. When the argument is a data array, this operation returns a copy of dtable with each entry x replaced by the remainder of x divided by the corresponding entry in the other data array.

VALUE dtable_remainder(VALUE ary, VALUE arg) {
   return dtable_apply_math_op2(ary, arg, do_remainder);
}
remainder!(number) → dtable click to toggle source
remainder!(other) → dtable

When the argument is a number, this operation replaces with each entry x of dtable by the remainder of x divided by number. When the argument is a data array, this operation replaces with each entry x of dtable by remainder of x divided by the corresponding entry in the other data array.

VALUE dtable_remainder_bang(VALUE ary, VALUE arg) {
   return dtable_apply_math_op2_bang(ary, arg, do_remainder);
}
reverse_cols → a_dtable click to toggle source

Returns a copy of dtable with the order of columns reversed.

VALUE dtable_reverse_cols(VALUE ary)
{
   Dtable *d = Get_Dtable(ary);
   int i, j, num_cols = d->num_cols, num_rows = d->num_rows, last_col = num_cols - 1;
   VALUE new = dtable_init(dtable_alloc(cDtable), num_cols, num_rows);
   Dtable *d2 = Get_Dtable(new);
   double **src, **dest;
   src = d->ptr; dest = d2->ptr;
   for (i = 0; i < num_rows; i++) {
      for (j = 0; j < num_cols; j++) {
         dest[i][last_col-j] = src[i][j];
      }
   }
   return new;
}
reverse_rows → a_dtable click to toggle source

Returns a copy of dtable with the order of rows reversed.

VALUE dtable_reverse_rows(VALUE ary)
{
   Dtable *d = Get_Dtable(ary);
   int i, j, num_cols = d->num_cols, num_rows = d->num_rows, last_row = num_rows - 1;
   VALUE new = dtable_init(dtable_alloc(cDtable), num_cols, num_rows);
   Dtable *d2 = Get_Dtable(new);
   double **src, **dest;
   src = d->ptr; dest = d2->ptr;
   for (i = 0; i < num_rows; i++) {
      for (j = 0; j < num_cols; j++) {
         dest[last_row-i][j] = src[i][j];
      }
   }
   return new;
}
rotate_ccw90 → a_dtable click to toggle source

Returns a copy of dtable rotated 90 degrees counter-clockwise.

VALUE dtable_rotate_ccw90(VALUE ary)
{
   Dtable *d = Get_Dtable(ary);
   int i, j, num_cols = d->num_cols, num_rows = d->num_rows, last_col = num_cols - 1;
   VALUE new = dtable_init(dtable_alloc(cDtable), num_rows, num_cols);
   Dtable *d2 = Get_Dtable(new);
   double **src, **dest;
   src = d->ptr; dest = d2->ptr;
   for (i = 0; i < num_rows; i++) {
      for (j = 0; j < num_cols; j++) {
         dest[last_col-j][i] = src[i][j];
      }
   }
   return new;
}
rotate_cw90 → a_dtable click to toggle source

Returns a copy of dtable rotated 90 degrees clockwise.

VALUE dtable_rotate_cw90(VALUE ary)
{
   Dtable *d = Get_Dtable(ary);
   int i, j, num_cols = d->num_cols, num_rows = d->num_rows, last_row = num_rows - 1;
   VALUE new = dtable_init(dtable_alloc(cDtable), num_rows, num_cols);
   Dtable *d2 = Get_Dtable(new);
   double **src, **dest;
   src = d->ptr; dest = d2->ptr;
   for (i = 0; i < num_rows; i++) {
      for (j = 0; j < num_cols; j++) {
         dest[j][last_row-i] = src[i][j];
      }
   }
   return new;
}
round → a_dtable click to toggle source

Returns of copy of dtable with each entry x replaced by round(x). (Numbers midway between integers round away from zero.)

VALUE dtable_round(VALUE ary) {
   return dtable_apply_math_op(ary, do_round);
}
round! → dtable click to toggle source

Replace each entry x of dtable with the integer closest to x. (Numbers midway between integers round away from zero.)

VALUE dtable_round_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, do_round);
}
row(int) → a_dvec click to toggle source

Creates a Dvector holding a copy of the contents of the requested row.

VALUE dtable_row(VALUE ary, VALUE row_num) {
   Dtable *d = Get_Dtable(ary);
   row_num = rb_Integer(row_num);
   int row = NUM2INT(row_num);
   if (row < 0 || row >= d->num_rows)
      rb_raise(rb_eArgError, "Asking for row i = %i from array with only %li rows", row, d->num_rows);
   VALUE dvec = Dvector_Create();
   Dvector_Data_Replace(dvec, d->num_cols, d->ptr[row]);
   return dvec;
}
safe_acos → a_dtable click to toggle source

Returns a copy of dtable with each entry x replaced by acos(max(-1,min(1,x))).

VALUE dtable_safe_acos(VALUE ary) {
   return dtable_apply_math_op(ary, do_safe_acos);
}
safe_acos! → dtable click to toggle source

Replaces each entry x in dtable by acos(max(-1,min(1,x)))..

VALUE dtable_safe_acos_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, do_safe_acos);
}
safe_asin → a_dtable click to toggle source

Returns a copy of dtable with each entry x replaced by asin(max(-1,min(1,x))).

VALUE dtable_safe_asin(VALUE ary) {
   return dtable_apply_math_op(ary, do_safe_asin);
}
safe_asin! → dtable click to toggle source

Replaces each entry x in dtable by asin(max(-1,min(1,x)))..

VALUE dtable_safe_asin_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, do_safe_asin);
}
safe_inv(cutoff=1e-99) → a_dtable click to toggle source

Returns a copy of dtable with each entry x replaced by sign(x)/cutoff if abs(x) < cutoff, 1/x otherwise.

VALUE dtable_safe_inv(int argc, VALUE *argv, VALUE self) {
   VALUE arg1;
   if ((argc < 0) || (argc > 1))
      rb_raise(rb_eArgError, "wrong # of arguments(%d for 0 or 1)",argc);
   arg1 = (argc > 0)? argv[0] : rb_float_new(1e-99);
   return dtable_apply_math_op1(self, arg1, do_safe_inv);
}
safe_inv!(cutoff) → dtable click to toggle source

Replaces each entry x in dtable by sign(x)/cutoff if abs(x) < cutoff, 1/x otherwise.

VALUE dtable_safe_inv_bang(int argc, VALUE *argv, VALUE self) {
   VALUE arg1;
   if ((argc < 0) || (argc > 1))
      rb_raise(rb_eArgError, "wrong # of arguments(%d for 0 or 1)",argc);
   arg1 = (argc > 0)? argv[0] : rb_float_new(1e-99);
   return dtable_apply_math_op1_bang(self, arg1, do_safe_inv);
}
safe_log(cutoff=1e-99) → a_dtable click to toggle source

Returns a copy of dtable with each entry x replaced by log(max(x,cutoff)).

VALUE dtable_safe_log(int argc, VALUE *argv, VALUE self) {
   VALUE arg1;
   if ((argc < 0) || (argc > 1))
      rb_raise(rb_eArgError, "wrong # of arguments(%d for 0 or 1)",argc);
   arg1 = (argc > 0)? argv[0] : rb_float_new(1e-99);
   return dtable_apply_math_op1(self, arg1, do_safe_log);
}
safe_log!(cutoff=1e-99) → dtable click to toggle source

Replaces each entry x in dtable by log(max(x,cutoff)).

VALUE dtable_safe_log_bang(int argc, VALUE *argv, VALUE self) {
   VALUE arg1;
   if ((argc < 0) || (argc > 1))
      rb_raise(rb_eArgError, "wrong # of arguments(%d for 0 or 1)",argc);
   arg1 = (argc > 0)? argv[0] : rb_float_new(1e-99);
   return dtable_apply_math_op1_bang(self, arg1, do_safe_log);
}
safe_log10(cutoff=1e-99) → a_dtable click to toggle source

Returns a copy of dtable with each entry x replaced by log10(max(x,cutoff)).

VALUE dtable_safe_log10(int argc, VALUE *argv, VALUE self) {
   VALUE arg1;
   if ((argc < 0) || (argc > 1))
      rb_raise(rb_eArgError, "wrong # of arguments(%d for 0 or 1)",argc);
   arg1 = (argc > 0)? argv[0] : rb_float_new(1e-99);
   return dtable_apply_math_op1(self, arg1, do_safe_log10);
}
safe_log10!(cutoff) → dtable click to toggle source

Replaces each entry x in dtable by log10(max(x,cutoff)).

VALUE dtable_safe_log10_bang(int argc, VALUE *argv, VALUE self) {
   VALUE arg1;
   if ((argc < 0) || (argc > 1))
      rb_raise(rb_eArgError, "wrong # of arguments(%d for 0 or 1)",argc);
   arg1 = (argc > 0)? argv[0] : rb_float_new(1e-99);
   return dtable_apply_math_op1_bang(self, arg1, do_safe_log10);
}
safe_sqrt → a_dtable click to toggle source

Returns a copy of dtable with each entry x replaced by sqrt(max(x,0)).

VALUE dtable_safe_sqrt(VALUE ary) {
   return dtable_apply_math_op(ary, do_safe_sqrt);
}
safe_sqrt! → dtable click to toggle source

Replaces each entry x in dtable by sqrt(max(x,0)).

VALUE dtable_safe_sqrt_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, do_safe_sqrt);
}
set(float) → dtable click to toggle source
set(a_dtable) → dtable

Modifies the entries of dtable array. If the argument is a float, then all of the entries are set to that value. If the argument is another Dtable array, then it must be the size as dtable, and its contents are copied to dtable.

VALUE dtable_set(VALUE ary, VALUE val) {
   if (is_a_dtable(val)) {
      Dtable *d = Get_Dtable(ary);
      Dtable *d2 = Get_Dtable(val);
      int num_cols = d->num_cols, num_rows = d->num_rows, i, j;
      double **data = d->ptr;
      double **data2 = d2->ptr;
      if (d2->num_cols != num_cols || d2->num_rows != num_rows)
         rb_raise(rb_eArgError, "Arrays must be same size for Dtable set");
      for (i = 0; i < num_rows; i++) {
         for (j = 0; j < num_cols; j++) {
            data[i][j] = data2[i][j];
         }
      }
   } else {
      double v = NUM2DBL(val);
      set_dtable_vals(ary, v);
   }
   return ary;
}
set_column(int,a_dvec) → a_dvec click to toggle source

Stores the contents of a_dec in the specified column of the array. The length of the vector must equal the number of rows in the array.

VALUE dtable_set_column(VALUE ary, VALUE col_num, VALUE dvec) {
   Dtable *d = Get_Dtable(ary);
   long len, i;
   double *data = Dvector_Data_for_Read(dvec, &len);
   col_num = rb_Integer(col_num);
   int col = NUM2INT(col_num);
   if (col < 0 || col >= d->num_cols)
      rb_raise(rb_eArgError, "Asking for column i = %i from array with only %li columns", col, d->num_cols);
   if (len != d->num_rows)
      rb_raise(rb_eArgError, "Length of vector (%li) does not match number of rows (%li)", len, d->num_rows);
   for (i=0; i < len; i++)
      d->ptr[i][col] = data[i];
   return dvec;
}
set_row(int,a_dvec) → a_dvec click to toggle source

Stores the contents of a_dec in the specified row of the array. The length of the vector must equal the number of columns in the array.

VALUE dtable_set_row(VALUE ary, VALUE row_num, VALUE dvec) {
   Dtable *d = Get_Dtable(ary);
   long len, j;
   double *data = Dvector_Data_for_Read(dvec, &len);
   row_num = rb_Integer(row_num);
   int row = NUM2INT(row_num);
   if (row < 0 || row >= d->num_rows)
      rb_raise(rb_eArgError, "Asking for row i = %i from array with only %li rows", row, d->num_rows);
   if (len != d->num_cols)
      rb_raise(rb_eArgError, "Length of vector (%li) does not match number of columns (%li)", len, d->num_cols);
   for (j=0; j < len; j++)
      d->ptr[row][j] = data[j];
   return dvec;
}
sin → a_dtable click to toggle source

Returns of copy of dtable with entry x replaced by sin(x).

VALUE dtable_sin(VALUE ary) {
   return dtable_apply_math_op(ary, sin);
}
sin! → dtable click to toggle source

Replace each entry x of dtable with sin(x).

VALUE dtable_sin_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, sin);
}
sinh → a_dtable click to toggle source

Returns of copy of dtable with entry x replaced by sinh(x).

VALUE dtable_sinh(VALUE ary) {
   return dtable_apply_math_op(ary, sinh);
}
sinh! → dtable click to toggle source

Replace each entry x of dtable with sinh(x).

VALUE dtable_sinh_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, sinh);
}
sqrt → a_dtable click to toggle source

Returns of copy of dtable with each entry x replaced by sqrt(x).

VALUE dtable_sqrt(VALUE ary) {
   return dtable_apply_math_op(ary, sqrt);
}
sqrt! → dtable click to toggle source

Replace each entry x of dtable with sqrt(x).

VALUE dtable_sqrt_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, sqrt);
}
sub(number) → a_dtable click to toggle source
sub(other) → a_dtable
dtable - number → a_dtable
number - dtable → a_dtable
dtable - other → a_dtable

When argument is a number, this operation returns a copy of dtable with each entry x replaced by x - number. When argument is a data array, this operation returns a copy of dtable with each entry x replaced by x - the corresponding entry in the other data array.

VALUE dtable_sub(VALUE ary, VALUE arg) {
   return dtable_apply_math_op2(ary, arg, do_sub);
}
Also aliased as: -, minus
sub!(number) → dtable click to toggle source
sub!(other) → dtable

When argument is a number, each entry x in dtable is replaced by x - number. When argument is a data array, each entry x in dtable is replaced by x - the corresponding entry in the other data array.

VALUE dtable_sub_bang(VALUE ary, VALUE arg) {
   return dtable_apply_math_op2_bang(ary, arg, do_sub);
}
Also aliased as: minus!
sum → number click to toggle source

Returns the sum of the entries in dtable. Returns 0.0 if dtable is empty.

a = Dtable.new(2,4)
a.set_column(0, Dvector[1,2,3,4])
a.set_column(1, Dvector[0, 1, 0, 1])
a.sum        -> 12.0
Dtable.new(2,2).sum   -> 0.0
VALUE dtable_sum(VALUE tabl){
tan → a_dtable click to toggle source

Returns of copy of dtable with entry x replaced by tan(x).

VALUE dtable_tan(VALUE ary) {
   return dtable_apply_math_op(ary, tan);
}
tan! → dtable click to toggle source

Replace each entry x of dtable with tan(x).

VALUE dtable_tan_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, tan);
}
tanh → a_dtable click to toggle source

Returns of copy of dtable with entry x replaced by tanh(x).

VALUE dtable_tanh(VALUE ary) {
   return dtable_apply_math_op(ary, tanh);
}
tanh! → dtable click to toggle source

Replace each entry x of dtable with tanh(x).

VALUE dtable_tanh_bang(VALUE ary) {
   return dtable_apply_math_op_bang(ary, tanh);
}
times(p1)
Alias for: mul
times!(p1)
Alias for: mul!
transpose → a_dtable click to toggle source

Returns a transposed copy of dtable (i.e., exchange rows and columns).

VALUE dtable_transpose(VALUE ary) {
   Dtable *d = Get_Dtable(ary);
   int i, j, num_cols = d->num_cols, num_rows = d->num_rows;
   VALUE new = dtable_init(dtable_alloc(cDtable), num_rows, num_cols);
   Dtable *d2 = Get_Dtable(new);
   double **src, **dest;
   src = d->ptr; dest = d2->ptr;
   for (i = 0; i < num_rows; i++) {
      for (j = 0; j < num_cols; j++) {
         dest[j][i] = src[i][j];
      }
   }
   return new;
}
trim(cutoff=1e-6) → a_dtable click to toggle source

Returns a copy of dtable with any entry with absolute value less than cutoff replaced by 0.

VALUE dtable_trim(int argc, VALUE *argv, VALUE self) {
   VALUE arg1;
   if ((argc < 0) || (argc > 1))
      rb_raise(rb_eArgError, "wrong # of arguments(%d for 0 or 1)",argc);
   arg1 = (argc > 0)? argv[0] : rb_float_new(1e-6);
   return dtable_apply_math_op1(self, arg1, do_trim);
}
trim!(cutoff=1e-6) → dtable click to toggle source

Each entry x in dtable having absolute value less than cutoff is replaced by 0.

VALUE dtable_trim_bang(int argc, VALUE *argv, VALUE self) {
   VALUE arg1;
   if ((argc < 0) || (argc > 1))
      rb_raise(rb_eArgError, "wrong # of arguments(%d for 0 or 1)",argc);
   arg1 = (argc > 0)? argv[0] : rb_float_new(1e-6);
   return dtable_apply_math_op1_bang(self, arg1, do_trim);
}