Class: Numo::NArray::Step

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
ext/numo/narray/step.c

Instance Method Summary collapse

Constructor Details

#new(start, end) ⇒ Object #new(range, step = nil, length = nil) ⇒ Object

Constructs a step using three parameters among start, end, step and length. start, end parameters can be replaced with range. If the step is omitted (or supplied with nil), then calculated from length or definded as 1.



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
# File 'ext/numo/narray/step.c', line 107

static VALUE
step_initialize( int argc, VALUE *argv, VALUE self )
{
    VALUE a, b=Qnil, c=Qnil, d=Qnil, e=Qnil;

    rb_scan_args(argc, argv, "13", &a, &b, &c, &d);
    /* Selfs are immutable, so that they should be initialized only once. */
    if (rb_ivar_defined(self, id_beg)) {
        rb_name_error(rb_intern("initialize"), "`initialize' called twice");
    }
    if (rb_obj_is_kind_of(a,rb_cRange)) {
        if (argc>3) {
            rb_raise(rb_eArgError, "extra argument");
        }
        d = c;
        c = b;
        e = rb_funcall(a, rb_intern("exclude_end?"), 0);
        //b = rb_ivar_get(a, id_end);
        b = rb_funcall(a, id_end, 0);
        //a = rb_ivar_get(a, id_beg);
        a = rb_funcall(a, id_beg, 0);
    }
    step_init(self, a, b, c, d, e);
    return Qnil;
}

Instance Method Details

#beginObject #firstObject

Returns the start of step.

Overloads:

  • #beginObject

    Returns:

    • (Object)
  • #firstObject

    Returns:

    • (Object)


141
142
143
144
145
# File 'ext/numo/narray/step.c', line 141

static VALUE
step_first( VALUE self )
{
    return rb_ivar_get(self, id_beg);
}

#endObject #lastObject

Returns the object that defines the end of step.

Overloads:

  • #endObject

    Returns:

    • (Object)
  • #lastObject

    Returns:

    • (Object)


155
156
157
158
159
# File 'ext/numo/narray/step.c', line 155

static VALUE
step_last( VALUE self )
{
    return rb_ivar_get(self, id_end);
}

#exclude_end?Boolean

Returns true if step excludes its end value.

Returns:

  • (Boolean)


194
195
196
197
198
# File 'ext/numo/narray/step.c', line 194

static VALUE
step_exclude_end_p(VALUE self)
{
    return RTEST(rb_ivar_get(self, id_excl)) ? Qtrue : Qfalse;
}

#beginObject #firstObject

Returns the start of step.

Overloads:

  • #beginObject

    Returns:

    • (Object)
  • #firstObject

    Returns:

    • (Object)


141
142
143
144
145
# File 'ext/numo/narray/step.c', line 141

static VALUE
step_first( VALUE self )
{
    return rb_ivar_get(self, id_beg);
}

#endObject #lastObject

Returns the object that defines the end of step.

Overloads:

  • #endObject

    Returns:

    • (Object)
  • #lastObject

    Returns:

    • (Object)


155
156
157
158
159
# File 'ext/numo/narray/step.c', line 155

static VALUE
step_last( VALUE self )
{
    return rb_ivar_get(self, id_end);
}

#lengthObject #sizeObject

Returns the length of step.

Overloads:

  • #lengthObject

    Returns:

    • (Object)
  • #sizeObject

    Returns:

    • (Object)


169
170
171
172
173
# File 'ext/numo/narray/step.c', line 169

static VALUE
step_length( VALUE self )
{
    return rb_ivar_get(self, id_len);
}

#lengthObject #sizeObject

Returns the length of step.

Overloads:

  • #lengthObject

    Returns:

    • (Object)
  • #sizeObject

    Returns:

    • (Object)


169
170
171
172
173
# File 'ext/numo/narray/step.c', line 169

static VALUE
step_length( VALUE self )
{
    return rb_ivar_get(self, id_len);
}

#stepObject

Returns the step of step.

Returns:

  • (Object)


182
183
184
185
186
# File 'ext/numo/narray/step.c', line 182

static VALUE
step_step( VALUE self )
{
    return rb_ivar_get(self, id_step);
}