Class: MemoryViewTestUtils::MultiDimensionalView
Relationships & Source Files | |
Inherits: | Object |
Defined in: | ext/-test-/memory_view/memory_view.c |
Class Method Summary
- .new(buf, format, shape, strides) constructor
Instance Method Summary
Constructor Details
.new(buf, format, shape, strides)
[ GitHub ]# File 'ext/-test-/memory_view/memory_view.c', line 334
static VALUE mdview_initialize(VALUE obj, VALUE buf, VALUE format, VALUE shape, VALUE strides) { Check_Type(buf, T_STRING); StringValue(format); Check_Type(shape, T_ARRAY); if (!NIL_P(strides)) Check_Type(strides, T_ARRAY); rb_ivar_set(obj, id_str, buf); rb_ivar_set(obj, SYM2ID(sym_format), format); rb_ivar_set(obj, SYM2ID(sym_shape), shape); rb_ivar_set(obj, SYM2ID(sym_strides), strides); return Qnil; }
Instance Method Details
#[](indices_v)
[ GitHub ]# File 'ext/-test-/memory_view/memory_view.c', line 349
static VALUE mdview_aref(VALUE obj, VALUE indices_v) { Check_Type(indices_v, T_ARRAY); rb_memory_view_t view; if (!rb_memory_view_get(obj, &view, 0)) { rb_raise(rb_eRuntimeError, "rb_memory_view_get: failed"); } if (RARRAY_LEN(indices_v) != view.ndim) { rb_raise(rb_eKeyError, "Indices has an invalid dimension"); } VALUE buf_indices; ssize_t *indices = ALLOCV_N(ssize_t, buf_indices, view.ndim); ssize_t i; for (i = 0; i < view.ndim; ++i) { indices[i] = NUM2SSIZET(RARRAY_AREF(indices_v, i)); } VALUE result = rb_memory_view_get_item(&view, indices); ALLOCV_END(buf_indices); rb_memory_view_release(&view); return result; }