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.



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'ext/numo/narray/step.c', line 112

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)


146
147
148
149
150
# File 'ext/numo/narray/step.c', line 146

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)


160
161
162
163
164
# File 'ext/numo/narray/step.c', line 160

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)


199
200
201
202
203
# File 'ext/numo/narray/step.c', line 199

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)


146
147
148
149
150
# File 'ext/numo/narray/step.c', line 146

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)


160
161
162
163
164
# File 'ext/numo/narray/step.c', line 160

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)


174
175
176
177
178
# File 'ext/numo/narray/step.c', line 174

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)


174
175
176
177
178
# File 'ext/numo/narray/step.c', line 174

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

#stepObject

Returns the step of step.

Returns:

  • (Object)


187
188
189
190
191
# File 'ext/numo/narray/step.c', line 187

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