From 76eafe029353d23139d936cc65b66147374107a6 Mon Sep 17 00:00:00 2001 From: davidm Date: Wed, 12 Nov 2008 05:17:13 +0000 Subject: [PATCH] * Removed #shift, #unshift, #push, and #pop from GSL::Vector and GSL::Vector::Complex. * Removed #up and #down alises from GSL::Poly. * Vector#concat and Vector::Complex#concat now always return a new instance containing the concatenated contents. These methods no longer modify the recevier in place. git-svn-id: http://rb-gsl.rubyforge.org/svn/trunk/rb-gsl@75 6e764f74-f39f-46f8-8c54-8307d62afe8d --- ext/poly_source.c | 3 - ext/vector_complex.c | 223 ++++++++++++------------------------------ ext/vector_source.c | 225 ++++++++++--------------------------------- html/vector.html | 207 +++++++++++++++++++-------------------- rd/vector.rd | 22 ++--- 5 files changed, 219 insertions(+), 461 deletions(-) diff --git a/ext/poly_source.c b/ext/poly_source.c index f69fcb4..56b6595 100644 --- a/ext/poly_source.c +++ b/ext/poly_source.c @@ -1757,9 +1757,6 @@ void FUNCTION(Init_gsl_poly,init)(VALUE module) rb_define_method(GSL_TYPE(cgsl_poly), "-@", FUNCTION(rb_gsl_poly,uminus), 0); rb_define_method(GSL_TYPE(cgsl_poly), "+@", FUNCTION(rb_gsl_poly,uplus), 0); - rb_define_alias(GSL_TYPE(cgsl_poly), "up", "unshift"); - rb_define_alias(GSL_TYPE(cgsl_poly), "down", "shift"); - rb_define_method(GSL_TYPE(cgsl_poly), "coerce", FUNCTION(rb_gsl_poly,coerce), 1); rb_define_method(GSL_TYPE(cgsl_poly), "to_gv", FUNCTION(rb_gsl_poly,to_gv), 0); diff --git a/ext/vector_complex.c b/ext/vector_complex.c index 0f732cb..e614047 100644 --- a/ext/vector_complex.c +++ b/ext/vector_complex.c @@ -1597,170 +1597,71 @@ static VALUE rb_gsl_vector_complex_arccoth(VALUE obj) return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arccoth); } -static VALUE rb_gsl_vector_complex_shift(int argc, VALUE *argv, VALUE obj) +static VALUE rb_gsl_vector_complex_concat(VALUE obj, VALUE other) { - gsl_vector_complex *v = NULL, *vnew = NULL; - gsl_complex *z = NULL; - int n2; - size_t n; - if(CLASS_OF(obj) != cgsl_vector_complex && CLASS_OF(obj) != cgsl_vector_complex_col) { - rb_raise(rb_eTypeError, "prohibited for %s", rb_class2name(CLASS_OF(obj))); - } - Data_Get_Struct(obj, gsl_vector_complex, v); - if (v->stride != 1) rb_raise(rb_eRuntimeError, "vector must have stride 1"); - if (v->size == 0) return Qnil; - switch (argc) { - case 0: - z = ALLOC(gsl_complex); - *z = gsl_vector_complex_get(v, 0); - v->size -= 1; - memmove(v->block->data, v->block->data+2, sizeof(double)*v->size*2); - return Data_Wrap_Struct(cgsl_complex, 0, free, z); - break; - case 1: - n2 = NUM2INT(argv[0]); - if (n2 <= 0) return Qnil; - n = (size_t) n2; - if (n >= v->size) n = v->size; - vnew = gsl_vector_complex_alloc(n); - memcpy(vnew->data, v->data, sizeof(gsl_complex)*n); - memmove(v->block->data, v->block->data+2*n, sizeof(gsl_complex)*(v->size - n)); - v->size -= n; - return Data_Wrap_Struct(VECTOR_COMPLEX_ROW_COL(obj), 0, gsl_vector_complex_free, vnew); - break; - default: - rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc); - break; - } - /* Should never get here. */ - return Qnil; -} + gsl_vector_complex *v = NULL, *v2 = NULL, *vnew = NULL; + gsl_vector_complex_view vv; + gsl_complex tmp; + VALUE x; + double beg, end; + int step; + size_t i, size2; -static VALUE rb_gsl_vector_complex_pop(int argc, VALUE *argv, VALUE obj) -{ - gsl_vector_complex *v = NULL, *vnew = NULL; - gsl_complex *z = NULL; - int n2; - size_t n; - if(CLASS_OF(obj) != cgsl_vector_complex && CLASS_OF(obj) != cgsl_vector_complex_col) { - rb_raise(rb_eTypeError, "prohibited for %s", rb_class2name(CLASS_OF(obj))); - } Data_Get_Struct(obj, gsl_vector_complex, v); - if (v->stride != 1) rb_raise(rb_eRuntimeError, "vector must have stride 1"); - if (v->size == 0) return Qnil; - switch (argc) { - case 0: - z = ALLOC(gsl_complex); - *z = gsl_vector_complex_get(v, v->size-1); - v->size -= 1; - return Data_Wrap_Struct(cgsl_complex, 0, free, z); - break; - case 1: - n2 = NUM2INT(argv[0]); - if (n2 <= 0) return Qnil; - n = (size_t) n2; - if (n >= v->size) n = v->size; - vnew = gsl_vector_complex_alloc(n); - memcpy(vnew->data, v->data+2*(v->size-n), sizeof(gsl_complex)*n); - v->size -= n; - return Data_Wrap_Struct(VECTOR_COMPLEX_ROW_COL(obj), 0, gsl_vector_complex_free, vnew); - break; - default: - rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc); - break; - } - /* Should never get here. */ - return Qnil; -} -static VALUE rb_gsl_vector_complex_unshift(VALUE obj, VALUE x) -{ - gsl_vector_complex *v = NULL, *other = NULL; - gsl_complex *z, c; - size_t n = 1; - if(CLASS_OF(obj) != cgsl_vector_complex && CLASS_OF(obj) != cgsl_vector_complex_col) { - rb_raise(rb_eTypeError, "prohibited for %s", rb_class2name(CLASS_OF(obj))); - } - switch (TYPE(x)) { - case T_FIXNUM: case T_FLOAT: - c.dat[0] = NUM2DBL(x); c.dat[1] = 0.0; - z = &c; - break; - case T_ARRAY: - c.dat[0] = NUM2DBL(rb_ary_entry(x, 0)); - c.dat[1] = NUM2DBL(rb_ary_entry(x, 1)); - z = &c; - break; - default: - if(VECTOR_COMPLEX_P(x)) { - Data_Get_Struct(x, gsl_vector_complex, other); - if (other->stride != 1) rb_raise(rb_eRuntimeError, "other vector must have stride 1"); - z = (gsl_complex *)other->data; - n = other->size; - } else { - CHECK_COMPLEX(x); - Data_Get_Struct(x, gsl_complex, z); - } - break; - } - if(n > 0) { - Data_Get_Struct(obj, gsl_vector_complex, v); - if (v->stride != 1) { - rb_raise(rb_eRuntimeError, "vector must have stride 1"); - } - if (v->block->size < v->size+n) { - rb_raise(rb_eRuntimeError, "operation would require memory reallocation"); - } - memmove(v->data+2*n, v->data, sizeof(gsl_complex)*v->size); - memmove(v->data, z, sizeof(gsl_complex)*n); - v->size += n; - } - return obj; -} + switch(TYPE(other)) { + case T_FIXNUM: + case T_BIGNUM: + case T_FLOAT: + vnew = gsl_vector_complex_alloc(v->size + 1); + vv = gsl_vector_complex_subvector(vnew, 0, v->size); + gsl_vector_complex_memcpy(&vv.vector, v); + gsl_vector_complex_set(vnew, v->size, rb_gsl_obj_to_gsl_complex(other, NULL)); + break; -static VALUE rb_gsl_vector_complex_push(VALUE obj, VALUE x) -{ - gsl_vector_complex *v = NULL, *other = NULL; - gsl_complex *z, c; - size_t n = 1; - if(CLASS_OF(obj) != cgsl_vector_complex && CLASS_OF(obj) != cgsl_vector_complex_col) { - rb_raise(rb_eTypeError, "prohibited for %s", rb_class2name(CLASS_OF(obj))); - } - switch (TYPE(x)) { - case T_FIXNUM: case T_FLOAT: - c.dat[0] = NUM2DBL(x); c.dat[1] = 0.0; - z = &c; - break; - case T_ARRAY: - c.dat[0] = NUM2DBL(rb_ary_entry(x, 0)); - c.dat[1] = NUM2DBL(rb_ary_entry(x, 1)); - z = &c; - break; - default: - if(VECTOR_COMPLEX_P(x)) { - Data_Get_Struct(x, gsl_vector_complex, other); - if (other->stride != 1) rb_raise(rb_eRuntimeError, "other vector must have stride 1"); - z = (gsl_complex *)other->data; - n = other->size; - } else { - CHECK_COMPLEX(x); - Data_Get_Struct(x, gsl_complex, z); - } - break; - } - if(n > 0) { - Data_Get_Struct(obj, gsl_vector_complex, v); - if (v->stride != 1) { - rb_raise(rb_eRuntimeError, "vector must have stride 1"); - } - if (v->block->size < v->size+n) { - rb_raise(rb_eRuntimeError, "operation would require memory reallocation"); - } - // Use memmove so that v.push(v) will work - memmove(v->data+2*v->size, z, sizeof(gsl_complex)*n); - v->size += n; + case T_ARRAY: + size2 = RARRAY(other)->len; + vnew = gsl_vector_complex_alloc(v->size + size2); + vv = gsl_vector_complex_subvector(vnew, 0, v->size); + gsl_vector_complex_memcpy(&vv.vector, v); + for (i = 0; i < size2; i++) { + x = rb_ary_entry(other, i); + gsl_vector_complex_set(vnew, v->size + i, rb_gsl_obj_to_gsl_complex(x, NULL)); + } + break; + + default: + if(rb_obj_is_kind_of(other, cgsl_complex)) { + vnew = gsl_vector_complex_alloc(v->size + 1); + vv = gsl_vector_complex_subvector(vnew, 0, v->size); + gsl_vector_complex_memcpy(&vv.vector, v); + gsl_vector_complex_set(vnew, v->size, rb_gsl_obj_to_gsl_complex(other, NULL)); + } else if(rb_obj_is_kind_of(other, rb_cRange)) { + get_range_beg_en_n(other, &beg, &end, &size2, &step); + vnew = gsl_vector_complex_alloc(v->size + size2); + vv = gsl_vector_complex_subvector(vnew, 0, v->size); + gsl_vector_complex_memcpy(&vv.vector, v); + GSL_SET_COMPLEX(&tmp, beg, 0.0); + for (i = 0; i < size2; i++) { + gsl_vector_complex_set(vnew, v->size + i, tmp); + GSL_SET_REAL(&tmp, GSL_REAL(tmp) + step); + } + } else if (rb_obj_is_kind_of(other, cgsl_vector_complex)) { + Data_Get_Struct(other, gsl_vector_complex, v2); + size2 = v2->size; + vnew = gsl_vector_complex_alloc(v->size + size2); + vv = gsl_vector_complex_subvector(vnew, 0, v->size); + gsl_vector_complex_memcpy(&vv.vector, v); + vv = gsl_vector_complex_subvector(vnew, v->size, size2); + gsl_vector_complex_memcpy(&vv.vector, v2); + } else { + rb_raise(rb_eTypeError, "wrong argument type %s (Array, Numeric, Range, GSL::Complex, or %s expected)", + rb_class2name(CLASS_OF(other)), rb_class2name(cgsl_vector_complex)); + } + break; } - return obj; + + return Data_Wrap_Struct(VECTOR_COMPLEX_ROW_COL(obj), 0, gsl_vector_complex_free, vnew); } static VALUE rb_gsl_vector_complex_block(VALUE obj) @@ -2121,11 +2022,7 @@ void Init_gsl_vector_complex(VALUE module) rb_define_method(cgsl_vector_complex, "arccoth", rb_gsl_vector_complex_arccoth, 0); /*****/ - rb_define_method(cgsl_vector_complex, "shift", rb_gsl_vector_complex_shift, -1); - rb_define_method(cgsl_vector_complex, "pop", rb_gsl_vector_complex_pop, -1); - rb_define_method(cgsl_vector_complex, "unshift", rb_gsl_vector_complex_unshift, 1); - rb_define_method(cgsl_vector_complex, "push", rb_gsl_vector_complex_push, 1); - rb_define_alias(cgsl_vector_complex, "concat", "push"); + rb_define_method(cgsl_vector_complex, "concat", rb_gsl_vector_complex_concat, 1); rb_define_method(cgsl_vector_complex, "block", rb_gsl_vector_complex_block, 0); rb_define_method(cgsl_vector_complex, "indgen", rb_gsl_vector_complex_indgen, -1); diff --git a/ext/vector_source.c b/ext/vector_source.c index aff7bd9..04acd76 100644 --- a/ext/vector_source.c +++ b/ext/vector_source.c @@ -1943,134 +1943,6 @@ static VALUE FUNCTION(rb_gsl_vector,histogram)(int argc, VALUE *argv, VALUE obj) return Data_Wrap_Struct(cgsl_histogram, 0, gsl_histogram_free, h); } -static VALUE FUNCTION(rb_gsl_vector,shift)(int argc, VALUE *argv, VALUE obj) -{ - GSL_TYPE(gsl_vector) *v = NULL, *vnew = NULL; - BASE x; - int n2; - size_t n; - Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v); - if (v->stride != 1) rb_raise(rb_eRuntimeError, "vector must have stride 1"); - if (v->size == 0) return Qnil; - switch (argc) { - case 0: - x = FUNCTION(gsl_vector,get)(v, 0); - v->size -= 1; - memmove(v->block->data, v->block->data+1, sizeof(BASE)*v->size); - return C_TO_VALUE((BASE)x); - break; - case 1: - n2 = NUM2INT(argv[0]); - if (n2 <= 0) return Qnil; - n = (size_t) n2; - if (n >= v->size) n = v->size; - vnew = FUNCTION(gsl_vector,alloc)(n); - memcpy(vnew->data, v->data, sizeof(BASE)*n); - v->size -= n; - memmove(v->block->data, v->block->data+n, sizeof(BASE)*v->size); - return Data_Wrap_Struct(GSL_TYPE(cgsl_vector), 0, FUNCTION(gsl_vector,free), vnew); - break; - default: - rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc); - break; - } -} - -static VALUE FUNCTION(rb_gsl_vector,pop)(int argc, VALUE *argv, VALUE obj) -{ - GSL_TYPE(gsl_vector) *v = NULL, *vnew = NULL; - BASE x; - int n2; - size_t n; - Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v); - if (v->size == 0) return Qnil; - switch (argc) { - case 0: - x = FUNCTION(gsl_vector,get)(v, v->size-1); - v->size -= 1; - return C_TO_VALUE((BASE)x); - break; - case 1: - n2 = NUM2INT(argv[0]); - if (n2 <= 0) return Qnil; - n = (size_t) n2; - if (n >= v->size) n = v->size; - vnew = FUNCTION(gsl_vector,alloc)(n); - memcpy(vnew->data, v->data+(v->size-n), sizeof(BASE)*n); - v->size -= n; - return Data_Wrap_Struct(GSL_TYPE(cgsl_vector), 0, FUNCTION(gsl_vector,free), vnew); - break; - default: - rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc); - break; - } -} - -static VALUE FUNCTION(rb_gsl_vector,unshift_v)(VALUE obj, VALUE x); -static VALUE FUNCTION(rb_gsl_vector,unshift)(VALUE obj, VALUE x) -{ - GSL_TYPE(gsl_vector) *v = NULL; - BASE xnative; - if (rb_obj_is_kind_of(obj,cgsl_vector_view) - || rb_obj_is_kind_of(obj,cgsl_vector_int_view)) - rb_raise(rb_eRuntimeError, "prohibited for %s", rb_class2name(CLASS_OF(obj))); - if (VECTOR_P(x) || VECTOR_INT_P(x)) return FUNCTION(rb_gsl_vector,unshift_v)(obj, x); - Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v); - if (v->stride != 1) { - rb_raise(rb_eRuntimeError, "vector must have stride 1"); - } - xnative = NUMCONV2(x); - if (v->block->size < (v->size+1)) { - rb_raise(rb_eRuntimeError, "operation would require memory reallocation"); - } - memmove(v->data+1, v->data, sizeof(BASE)*v->size); - v->size += 1; - FUNCTION(gsl_vector,set)(v, 0, xnative); - return obj; -} - -static VALUE FUNCTION(rb_gsl_vector,unshift_v)(VALUE obj, VALUE x) -{ - GSL_TYPE(gsl_vector) *v = NULL, *v2; - if (rb_obj_is_kind_of(obj,QUALIFIED_VIEW(cgsl_vector,view) )) - rb_raise(rb_eRuntimeError, "prohibited for %s", rb_class2name(CLASS_OF(obj))); - if (!rb_obj_is_kind_of(x, CLASS_OF(obj))) - rb_raise(rb_eTypeError, "wrong argument type %s (%s expected)", - rb_class2name(CLASS_OF(x)), rb_class2name(CLASS_OF(obj))); - Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v); - Data_Get_Struct(x, GSL_TYPE(gsl_vector), v2); - if (v->stride != 1) rb_raise(rb_eRuntimeError, "vector must have stride 1"); - if (v2->stride != 1) rb_raise(rb_eRuntimeError, "vector must have stride 1"); - if (v->block->size < (v->size+v2->size)) { - rb_raise(rb_eRuntimeError, "operation would require memory reallocation"); - } - memmove(v->data+v2->size, v->data, sizeof(BASE)*v->size); - memmove(v->data, v2->data, sizeof(BASE)*v2->size); - v->size += v2->size; - return obj; -} - -static VALUE FUNCTION(rb_gsl_vector,concat)(VALUE obj, VALUE other); -static VALUE FUNCTION(rb_gsl_vector,push)(VALUE obj, VALUE x) -{ - GSL_TYPE(gsl_vector) *v = NULL; - BASE xnative; - if (rb_obj_is_kind_of(obj,QUALIFIED_VIEW(cgsl_vector,view) )) - rb_raise(rb_eRuntimeError, "prohibited for %s", rb_class2name(CLASS_OF(obj))); - if (VECTOR_P(x) || VECTOR_INT_P(x) || TYPE(x) == T_ARRAY) { - return FUNCTION(rb_gsl_vector,concat)(obj, x); - } - Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v); - if (v->stride != 1) rb_raise(rb_eRuntimeError, "vector must have stride 1"); - xnative = NUMCONV2(x); - if (v->block->size < (v->size+1)) { - rb_raise(rb_eRuntimeError, "operation would require memory reallocation"); - } - v->size += 1; - FUNCTION(gsl_vector,set)(v, v->size-1, xnative); - return obj; -} - static VALUE FUNCTION(rb_gsl_vector,last)(VALUE obj) { GSL_TYPE(gsl_vector) *v = NULL; @@ -2087,50 +1959,62 @@ static VALUE FUNCTION(rb_gsl_vector,first)(VALUE obj) static VALUE FUNCTION(rb_gsl_vector,concat)(VALUE obj, VALUE other) { - GSL_TYPE(gsl_vector) *v = NULL, *v2 = NULL; + GSL_TYPE(gsl_vector) *v = NULL, *v2 = NULL, *vnew = NULL; + QUALIFIED_VIEW(gsl_vector,view) vv; VALUE x; - BASE xnative; + BASE beg, end; + int step; size_t i, size2; - if (rb_obj_is_kind_of(obj,QUALIFIED_VIEW(cgsl_vector,view))) - rb_raise(rb_eRuntimeError, "prohibited for %s", rb_class2name(CLASS_OF(obj))); - if (!rb_obj_is_kind_of(other, CLASS_OF(obj)) && TYPE(other) != T_ARRAY) - rb_raise(rb_eTypeError, "wrong argument type %s (%s expected)", - rb_class2name(CLASS_OF(other)), rb_class2name(CLASS_OF(obj))); + Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v); - if (v->stride != 1) - rb_raise(rb_eRuntimeError, "vector must have stride 1"); - if (TYPE(other) == T_ARRAY) { - size2 = RARRAY(other)->len; - if (v->block->size < (v->size+size2)) { - rb_raise(rb_eRuntimeError, "operation would require memory reallocation"); - } - for (i = 0; i < size2; i++) { - x = rb_ary_entry(other, i); - switch(TYPE(x)) { - case T_FIXNUM: case T_BIGNUM: case T_FLOAT: - xnative = NUMCONV2(x); - break; - default: - xnative = (BASE)0; + switch(TYPE(other)) { + case T_FIXNUM: + case T_BIGNUM: + case T_FLOAT: + vnew = FUNCTION(gsl_vector,alloc)(v->size + 1); + vv = FUNCTION(gsl_vector,subvector)(vnew, 0, v->size); + FUNCTION(gsl_vector,memcpy)(&vv.vector, v); + FUNCTION(gsl_vector,set)(vnew, v->size, NUMCONV2(other)); + break; + + case T_ARRAY: + size2 = RARRAY(other)->len; + vnew = FUNCTION(gsl_vector,alloc)(v->size + size2); + vv = FUNCTION(gsl_vector,subvector)(vnew, 0, v->size); + FUNCTION(gsl_vector,memcpy)(&vv.vector, v); + for (i = 0; i < size2; i++) { + x = rb_ary_entry(other, i); + FUNCTION(gsl_vector,set)(vnew, v->size + i, NUMCONV2(x)); } - // Cannot increment size until after all array elements have been - // converted because that would alter vector even if an exception is - // rasied. So we cannot use gsl_vector_set. - v->data[v->size+i] = xnative; - } - } else { - Data_Get_Struct(other, GSL_TYPE(gsl_vector), v2); - if (v2->stride != 1) - rb_raise(rb_eRuntimeError, "vector must have stride 1"); - size2 = v2->size; - if (v->block->size < (v->size+size2)) { - rb_raise(rb_eRuntimeError, "operation would require memory reallocation"); - } - memcpy(v->data+v->size, v2->data, sizeof(BASE)*v2->size); - } - v->size += size2; - return obj; + break; + + default: + if(rb_obj_is_kind_of(other, rb_cRange)) { + FUNCTION(get_range,beg_en_n)(other, &beg, &end, &size2, &step); + vnew = FUNCTION(gsl_vector,alloc)(v->size + size2); + vv = FUNCTION(gsl_vector,subvector)(vnew, 0, v->size); + FUNCTION(gsl_vector,memcpy)(&vv.vector, v); + for (i = 0; i < size2; i++) { + FUNCTION(gsl_vector,set)(vnew, v->size + i, beg); + beg += step; + } + } else if (rb_obj_is_kind_of(other, GSL_TYPE(cgsl_vector))) { + Data_Get_Struct(other, GSL_TYPE(gsl_vector), v2); + size2 = v2->size; + vnew = FUNCTION(gsl_vector,alloc)(v->size + size2); + vv = FUNCTION(gsl_vector,subvector)(vnew, 0, v->size); + FUNCTION(gsl_vector,memcpy)(&vv.vector, v); + vv = FUNCTION(gsl_vector,subvector)(vnew, v->size, size2); + FUNCTION(gsl_vector,memcpy)(&vv.vector, v2); + } else { + rb_raise(rb_eTypeError, "wrong argument type %s (Array, Numeric, Range, or %s expected)", + rb_class2name(CLASS_OF(other)), rb_class2name(GSL_TYPE(cgsl_vector))); + } + break; + } + + return Data_Wrap_Struct(VEC_ROW_COL(obj), 0, FUNCTION(gsl_vector,free), vnew); } void FUNCTION(mygsl_vector,diff)(GSL_TYPE(gsl_vector) *vdst, @@ -3338,13 +3222,6 @@ void FUNCTION(Init_gsl_vector,init)(VALUE module) rb_define_method(GSL_TYPE(cgsl_vector), "histogram", FUNCTION(rb_gsl_vector,histogram), -1); - rb_define_method(GSL_TYPE(cgsl_vector), "shift", - FUNCTION(rb_gsl_vector,shift), -1); - rb_define_method(GSL_TYPE(cgsl_vector), "unshift", - FUNCTION(rb_gsl_vector,unshift), 1); - rb_define_method(GSL_TYPE(cgsl_vector), "push", FUNCTION(rb_gsl_vector,push), 1); - rb_define_alias(GSL_TYPE(cgsl_vector), "<<", "push"); - rb_define_method(GSL_TYPE(cgsl_vector), "pop", FUNCTION(rb_gsl_vector,pop), -1); rb_define_method(GSL_TYPE(cgsl_vector), "last", FUNCTION(rb_gsl_vector,last), 0); rb_define_method(GSL_TYPE(cgsl_vector), "first", diff --git a/html/vector.html b/html/vector.html index 2d8a762..4743b60 100644 --- a/html/vector.html +++ b/html/vector.html @@ -628,119 +628,110 @@

3.7 Vector operations +
GSL::Vector#concat(x)
+
+Returns a new Vector that contains the concatenation self and +x, which must be an Array, Fixnum, Bignum, +Float, Range, or GSL::Vector.
-

3.8 Vector operations with size changes

+

3.8 Vector operations with size changes

The methods below change vector length of self. A Vector's length may -not extend past its original allocation.

+not extend past its original allocation. Use of these methods is discouraged. +Existing Views may still refer to elements beyond the end of the shortened +Vector. These elements remain allocated, but are effectvely unmanaged.

-
GSL::Vector#pop
-
-Removes the last element from self and returns it, or -nil if empty.
-
GSL::Vector#shift
-
-Returns the first element from self and removes it. Returns -nil if empty.
-
GSL::Vector#push(x)
-
GSL::Vector#concat(x)
-
GSL::Vector#<<(x)
-
-Append x (Numeric or GSL::Vector) to the end of self.
-
GSL::Vector#unshift(x)
-
-Prepends x to the front of self.
-
GSL::Vector#delete(x)
+
GSL::Vector#delete(x)
Deletes items from self that are equal to x. If the item is not found, returns nil, otherwise returns x.
-
GSL::Vector#delete_at(i)
+
GSL::Vector#delete_at(i)
Deletes the element at the specified index i, returning that element, or nil if the index is out of range.
-
GSL::Vector#delete_if { |x| ... }
+
GSL::Vector#delete_if { |x| ... }
Deletes every element of self for which block evaluates to true and returns self.
-

3.9 Finding maximum and minimum elements of vectors

+

3.9 Finding maximum and minimum elements of vectors

-
GSL::Vector#max
+
GSL::Vector#max
This method returns the maximum value in the vector.
-
GSL::Vector#min
+
GSL::Vector#min
This method returns the minimum value in the vector.
-
GSL::Vector#minmax
+
GSL::Vector#minmax
This method returns an array of two elements, the minimum and the maximum values in the vector self.
-
GSL::Vector#max_index
+
GSL::Vector#max_index
This method returns the index of the maximum value in the vector. When there are several equal maximum elements then the lowest index is returned.
-
GSL::Vector#min_index
+
GSL::Vector#min_index
This method returns the index of the minimum value in the vector. When there are several equal minimum elements then the lowest index is returned.
-
GSL::Vector#minmax_index
+
GSL::Vector#minmax_index
This method returns an array of two elements which has the indices of the minimum and the maximum values in the vector self.
-

3.10 Vector Properties

+

3.10 Vector Properties

-
GSL::Vector#size
-
GSL::Vector#len
-
GSL::Vector#length
+
GSL::Vector#size
+
GSL::Vector#len
+
GSL::Vector#length
Return the vector length.
-
GSL::Vector#stride
+
GSL::Vector#stride
Return the vector stride.
-
GSL::Vector#sum
+
GSL::Vector#sum
Returns the sum of the vector elements.
-
GSL::Vector#prod
+
GSL::Vector#prod
Returns the product of the vector elements.
-
GSL::Vector#cumsum
+
GSL::Vector#cumsum
Calculate the cumulative sum of elements of self and returns as a new vector.
-
GSL::Vector#cumprod
+
GSL::Vector#cumprod
Calculate the cumulative product of elements of self and returns as a new vector.
-
GSL::Vector#isnull
+
GSL::Vector#isnull
Returns 1 if all the elements of the vector self are zero, and 0 otherwise.
-
GSL::Vector#isnull?
+
GSL::Vector#isnull?
Return true if all the elements of the vector self are zero, and false otherwise.
-
GSL::Vector#ispos
-
GSL::Vector#ispos?
-
GSL::Vector#isneg
-
GSL::Vector#isneg?
+
GSL::Vector#ispos
+
GSL::Vector#ispos?
+
GSL::Vector#isneg
+
GSL::Vector#isneg?
(GSL-1.9 or later) Return 1 (true) if all the elements of the vector self are zero, strictly positive, strictly negative respectively, and 0 (false) otherwise.
-
GSL::Vector#isnonneg
-
GSL::Vector#isnonneg?
+
GSL::Vector#isnonneg
+
GSL::Vector#isnonneg?
(GSL-1.10 or later) Return 1 (true) if all the elements of the vector self are non-negative , and 0 (false) otherwise.
-
GSL::Vector#all?
+
GSL::Vector#all?
Returns true if all the vector elements are non-zero, and false otherwise. If a block is given, the method returns true if the tests are true for all the elements.
-
GSL::Vector#any?
+
GSL::Vector#any?
Returns true if any the vector elements are non-zero, and false otherwise. If a block is given, the method returns true if the tests are true for any of the elements.
-
GSL::Vector#none?
+
GSL::Vector#none?

Returns true if all the elements of the vector self are zero, and false otherwise (just as GSL::Vector#isnull?). @@ -762,27 +753,27 @@

3.10 Vector Properties

-
GSL::Vector#all
-
GSL::Vector#any
-
GSL::Vector#none
+
GSL::Vector#all
+
GSL::Vector#any
+
GSL::Vector#none
Returns 1 or 0.
-
GSL::Vector#equal?(other, eps = 1e-10)
-
GSL::Vector#==(other, eps = 1e-10)
+
GSL::Vector#equal?(other, eps = 1e-10)
+
GSL::Vector#==(other, eps = 1e-10)
Returns true if the vectors have same size and elements equal to absolute accurary eps for all the indices, and false otherwise.
-

3.11 Element-wise vector comparison

+

3.11 Element-wise vector comparison

-
GSL::Vector#eq(other)
-
GSL::Vector#ne(other)
-
GSL::Vector#gt(other)
-
GSL::Vector#ge(other)
-
GSL::Vector#lt(other)
-
GSL::Vector#le(other)
+
GSL::Vector#eq(other)
+
GSL::Vector#ne(other)
+
GSL::Vector#gt(other)
+
GSL::Vector#ge(other)
+
GSL::Vector#lt(other)
+
GSL::Vector#le(other)

Return a Block::Byte object with elements 0/1 by comparing the two vectors self and other. Note that the values returned are 0/1, @@ -804,10 +795,10 @@

3.11 Element-wise vector [ 1 0 1 ] irb(main):011:0> a.ge(2) [ 0 1 1 ]

-
GSL::Vector#and(other)
-
GSL::Vector#or(other)
-
GSL::Vector#xor(other)
-
GSL::Vector#not
+
GSL::Vector#and(other)
+
GSL::Vector#or(other)
+
GSL::Vector#xor(other)
+
GSL::Vector#not

Ex:

irb(main):033:0> a = GSL::Vector[1, 0, 3, 0]
@@ -822,8 +813,8 @@ 

3.11 Element-wise vector [ 0 1 0 1 ] irb(main):039:0> b.not [ 0 0 1 1 ]

-
GSL::Vector#where
-
GSL::Vector#where { |elm| ... }
+
GSL::Vector#where
+
GSL::Vector#where { |elm| ... }

Returns the vector indices where the tests are true. If all the test failed nil is returned.

@@ -837,13 +828,13 @@

3.11 Element-wise vector irb(main):009:0> a.where => nil

-

3.12 Histogram

+

3.12 Histogram

-
GSL::Vector#histogram(n)
-
GSL::Vector#histogram(ranges)
-
GSL::Vector#histogram(n, min, max)
-
GSL::Vector#histogram(n, [min, max])
+
GSL::Vector#histogram(n)
+
GSL::Vector#histogram(ranges)
+
GSL::Vector#histogram(n, min, max)
+
GSL::Vector#histogram(n, [min, max])

Creates a histogram filling the vector self.

Example:

@@ -860,14 +851,14 @@

3.12 Histogram

<
h = Histogram.alloc(50, [-4, 4])
 h.increment(v)
-

3.13 Sorting

+

3.13 Sorting

-
GSL::Vector#sort
-
GSL::Vector#sort!
+
GSL::Vector#sort
+
GSL::Vector#sort!
These methods sort the vector self in ascending numerical order.
-
GSL::Vector#sort_index
+
GSL::Vector#sort_index
This method indirectly sorts the elements of the vector self into ascending order, and returns the resulting permutation. @@ -876,10 +867,10 @@

3.13 Sorting

self is not changed.
-
GSL::Vector#sort_smallest(n)
-
GSL::Vector#sort_largest(n)
-
GSL::Vector#sort_smallest_index(n)
-
GSL::Vector#sort_largest_index(n)
+
GSL::Vector#sort_smallest(n)
+
GSL::Vector#sort_largest(n)
+
GSL::Vector#sort_smallest_index(n)
+
GSL::Vector#sort_largest_index(n)

Ex:

irb(main):005:0> v = GSL::Vector::Int[8, 2, 3, 7, 9, 1, 4]
@@ -898,22 +889,22 @@ 

3.13 Sorting

-

3.14 BLAS Methods

+

3.14 BLAS Methods

-
GSL::Vector#nrm2
-
GSL::Vector#dnrm2
+
GSL::Vector#nrm2
+
GSL::Vector#dnrm2
Compute the Euclidean norm ||x||_2 = sqrt {sum x_i^2} of the vector.
-
GSL::Vector#asum
-
GSL::Vector#dasum
+
GSL::Vector#asum
+
GSL::Vector#dasum
Compute the absolute sum \sum |x_i| of the elements of the vector.
-

3.15 Data type conversions

+

3.15 Data type conversions

-
GSL::Vector#to_a
+
GSL::Vector#to_a

This method converts the vector into a Ruby array. A Ruby array also can be converted into a GSL::Vector object with the to_gv method. For example,

@@ -923,7 +914,7 @@

3.15 Data type conversio a[2] = 12.0 v2 = a.to_gv -> a new GSL::Vector object v2.print -> 1.0000e+00 2.0000e+00 1.2000e+01 4.0000e+00 5.0000e+00

-
GSL::Vector#to_m(nrow, ncol)
+
GSL::Vector#to_m(nrow, ncol)

Creates a GSL::Matrix object of nrow rows and ncol columns.

irb(main):011:0> v = GSL::Vector::Int[1..5]
@@ -942,7 +933,7 @@ 

3.15 Data type conversio [ 1 2 3 4 5 0 ]

-
GSL::Vector#to_m_diagonal
+
GSL::Vector#to_m_diagonal

Converts the vector into a diagonal matrix. See also GSL::Matrix.diagonal(v).

@@ -955,7 +946,7 @@

3.15 Data type conversio 0 2 0 0 0 0 3 0 0 0 0 4 ]

-
GSL::Vector#to_m_circulant
+
GSL::Vector#to_m_circulant

Creates a circulant matrix.

irb(main):002:0> v = GSL::Vector::Int[1..5]
@@ -968,8 +959,8 @@ 

3.15 Data type conversio 3 4 5 1 2 2 3 4 5 1 1 2 3 4 5 ]

-
GSL::Vector#to_complex
-
GSL::Vector#to_complex2
+
GSL::Vector#to_complex
+
GSL::Vector#to_complex2

Example:

irb(main):002:0> v = GSL::Vector[1..4]
@@ -981,17 +972,17 @@ 

3.15 Data type conversio irb(main):004:0> v.to_complex2 [ [1.000e+00 2.000e+00] [3.000e+00 4.000e+00] ] => #<GSL::Vector::Complex:0x6d6424>

-
GSL::Vector#to_tensor(rank, dimension)
+
GSL::Vector#to_tensor(rank, dimension)
-

3.16 GSL::Vector <---> NArray

NArray" --> +

3.16 GSL::Vector <---> NArray

NArray" -->
-
GSL::Vector#to_na
+
GSL::Vector#to_na
Converts a vector self into an NArray object. The data are copied to newly allocated memory.
-
GSL::Vector#to_na2
-
GSL::Vector#to_na_ref
+
GSL::Vector#to_na2
+
GSL::Vector#to_na_ref

Create an NArray reference of the vector self.

Example:

@@ -1014,13 +1005,13 @@

3.16 GSL::Vector & irb(main):026:0> v => GSL::Vector::Int [ 1 99 3 4 ]

-
NArray#to_gv
-
NArray#to_gslv
+
NArray#to_gv
+
NArray#to_gslv
Create GSL::Vector object from the NArray object self.
-
NArray#to_gv_view
-
NArray#to_gv2
-
NArray#to_gslv_view
+
NArray#to_gv_view
+
NArray#to_gv2
+
NArray#to_gslv_view

A GSL::Vector::View object is created from the NArray object self. This method does not allocate memory for the data: the data of self @@ -1067,15 +1058,15 @@

3.16 GSL::Vector & => NArray.float(6): [ 1.0, 2.0, 3.0, 4.0, 5.0, 9.0 ]

-

3.17 Graphics

+

3.17 Graphics

-
GSL::Vector.graph(y)
-
GSL::Vector.graph(y, options)
-
GSL::Vector.graph(x, y)
-
GSL::Vector.graph(x, y, options)
-
GSL::Vector#graph(options)
-
GSL::Vector#graph(x, options)
+
GSL::Vector.graph(y)
+
GSL::Vector.graph(y, options)
+
GSL::Vector.graph(x, y)
+
GSL::Vector.graph(x, y, options)
+
GSL::Vector#graph(options)
+
GSL::Vector#graph(x, options)

These methods use the GNU plotutils graph application to plot a vector self. The options of graph as "-T X -C" can be given by a String.

diff --git a/rd/vector.rd b/rd/vector.rd index 38bd29f..8fa65f1 100644 --- a/rd/vector.rd +++ b/rd/vector.rd @@ -609,21 +609,17 @@ in the elements of the (({View})) object affect to the original vector. [ 5.000e+00 2.000e+00 0.000e+00 ], [ 6.000e+00 0.000e+00 0.000e+00 ]] +--- GSL::Vector#concat(x) + Returns a new Vector that contains the concatenation ((|self|)) and + ((|x|)), which must be an (({Array})), (({Fixnum})), (({Bignum})), + (({Float})), (({Range})), or (({GSL::Vector})). + === Vector operations with size changes The methods below change vector length of ((|self|)). A Vector's length may -not extend past its original allocation. ---- GSL::Vector#pop - Removes the last element from ((|self|)) and returns it, or - (({nil})) if empty. ---- GSL::Vector#shift - Returns the first element from ((|self|)) and removes it. Returns - (({nil})) if empty. ---- GSL::Vector#push(x) ---- GSL::Vector#concat(x) ---- GSL::Vector#<<(x) - Append ((|x|)) ((({Numeric})) or (({GSL::Vector}))) to the end of ((|self|)). ---- GSL::Vector#unshift(x) - Prepends ((|x|)) to the front of ((|self|)). +not extend past its original allocation. Use of these methods is discouraged. +Existing Views may still refer to elements beyond the end of the shortened +Vector. These elements remain allocated, but are effectvely unmanaged. + --- GSL::Vector#delete(x) Deletes items from ((|self|)) that are equal to ((|x|)). If the item is not found, returns (({nil})), otherwise returns ((|x|)).