Class: Array

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Instance Method Summary collapse

Instance Method Details

#to_complex_bufferPaddleC::ComplexBuffer



894
895
896
897
# File 'ext/paddlec/complex_buffer.c', line 894

static VALUE paddlec_array_to_complex_buffer(VALUE self)
{
  return rb_class_new_instance(1, &self, c_ComplexBuffer);
}

#to_float_bufferPaddleC::FloatBuffer



851
852
853
854
# File 'ext/paddlec/float_buffer.c', line 851

static VALUE paddlec_array_to_float_buffer(VALUE self)
{
  return rb_class_new_instance(1, &self, c_FloatBuffer);
}

#to_gplotString

Allow the gnuplot gem to draw PaddleC::FloatBuffer.

Returns:

  • (String)


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'ext/paddlec/paddlec.c', line 89

static VALUE paddlec_array_to_gplot(VALUE self)
{
  int len, i;
  VALUE a, b, res, space, bn;
  VALUE *splat;

  if (rb_obj_is_kind_of(rb_ary_entry(self, 0), rb_cArray) || rb_obj_is_kind_of(rb_ary_entry(self, 0), c_FloatBuffer)) {
    len = rb_array_len(self) - 1;
    if (len < 0)
      len = 0;
    splat = malloc(len*sizeof(VALUE*));
    for (i = 0; i < len; i++)
      splat[i] = rb_ary_entry(self, i+1);
    a = rb_funcallv(rb_ary_entry(self, 0), id_zip, len, splat);
    free(splat);
    len = rb_array_len(a);
    b = rb_ary_new_capa(len + 1);
    space = rb_str_new_cstr(" ");
    for (i = 0; i < len; i++)
      rb_ary_store(b, i, rb_funcallv(rb_ary_entry(a, i), id_join, 1, &space));
    rb_ary_store(b, len, rb_str_new_cstr("e"));
    bn = rb_str_new_cstr("\n");
    res = rb_funcallv(b, id_join, 1, &bn);
  }
  else if (rb_obj_is_kind_of(rb_ary_entry(self, 0), rb_cNumeric)) {
    len = rb_array_len(self);
    res = rb_str_new_cstr("");
    for (i = 0; i < len; i++) {
      a = rb_funcallv(rb_ary_entry(self, i), id_to_s, 0, NULL);
      a = rb_str_cat_cstr(a, "\n");
      res = rb_str_append(res, a);
    }
  }
  else {
    len = rb_array_len(self) - 1;
    if (len < 0)
      len = 0;
    splat = malloc(len*sizeof(VALUE*));
    for (i = 0; i < len; i++)
      splat[i] = rb_ary_entry(self, i+1);
    a = rb_funcallv(rb_ary_entry(self, 0), id_zip, len, splat);
    free(splat);
    res = rb_funcallv(a, id_to_gplot, 0, NULL);
  }

  return res;
}