Class: P1788::IntervalVector

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
ext/p1788/p1788.cc,
ext/p1788/p1788.cc

Overview

An interval vector (or box) is an n-dimensional interval, i.e. a tuple (𝒙₁, 𝒙₂, ..., 𝒙ₙ) ∈ 𝕀ℝⁿ where the 𝒙i are intervals. An interval vector is empty if and only if any of its components 𝒙i is empty.

Interval vectors as Ruby objects

#initialize #dup #clone #inspect #to_s #to_latex #to_a #eql? #hash #coerce

Interval vectors as a collections

#length #resize #at IntervalVector.[] #[]= #first #last #<< #push #pop #each #map #collect #collect! #select #select! #reject #reject! #compact #compact! #reverse #reverse!

Boolean functions on interval vectors

#== #!= #empty? #nonempty? #flat? #bounded? #unbounded? #common? #bisectable? #disjoint_from? #intersect? #overlap? #subset_of? #strict_subset_of? #superset_of? #contain? #strict_superset_of? #interior_subset_of? #contain_interior_of? #include? #bisectable? #inclusion_test

Operations on interval vectors

#bisect #& #| #inflate

Numeric functions on interval vectors

#volume #perimeter #min_width #max_width #lower_bounds #upper_bounds #widths #radii #midpoints #bisectable_dimensions

Arithmetic and non-linear functions on interval vectors

#-@ #+@ #+ #- <em> #/ </em>* #pow #pown #min #max #cancel_minus #cancel_plus #abs #recip #sqr #sqrt #exp #exp2 #exp10 #log #log2 #log10 #sin #cos #tan #asin #acos #atan #sinh #cosh #tanh #asinh #acosh #atanh #sign #ceil #floor #floorceil #trunc #round_ties_to_even #round_ties_to_away

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#newIntervalVector #new(interval_vector) ⇒ IntervalVector #new(array) ⇒ IntervalVector #new(size, value = Interval::ALL_REALS) ⇒ IntervalVector #new(size) {|index| ... } ⇒ IntervalVector

Overloads:

  • #newIntervalVector

    Returns an empty vector

  • #new(interval_vector) ⇒ IntervalVector

    Parameters:

  • #new(array) ⇒ IntervalVector

    Returns a new vector formed from the elements of the array.

    Parameters:

    • array (Array<Interval>)

      an array of interval or objects that can be converted to intervals (Numeric, Range, two elements Array)

  • #new(size, value = Interval::ALL_REALS) ⇒ IntervalVector

    Returns a vector of given size filled with the given value.

    Parameters:

    • size (Integer)

      size of the vector

    • value (Interval) (defaults to: Interval::ALL_REALS)

      value to fill each element of the vector with

  • #new(size) {|index| ... } ⇒ IntervalVector

    Returns a vector of given size, the block is called with each successive integer index; the element for that index is the return value from the block.

    Parameters:

    • size (Integer)

      size of the vector

    Yield Parameters:

    • index (Integer)

      index of the element that is being filled by the block

    Yield Returns:

    • (Interval)

      an object that can be converted to an interval (Interval, Integer, Float, Rational, Range or an Array)



4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
# File 'ext/p1788/p1788.cc', line 4014

static VALUE p1788_vector_initialize(int argc, VALUE *argv, VALUE self)
{
  VALUE a1, a2;
  int len = 0; 
  int nb_scaned_args = rb_scan_args(argc, argv, "02", &a1, &a2);
  IntervalVector& v = p1788_vector_rb2ref(self);
  if (rb_block_given_p()) {
    if (nb_scaned_args != 1)
      rb_raise(rb_eArgError, "if a block is given, %sthe size of the vector must be provided as argument", (nb_scaned_args > 1) ? "only " : "");
    if (!RB_INTEGER_TYPE_P(a1) || (len = NUM2INT(a1)) < 0)
      rb_raise(rb_eArgError, "if a block is given, the vector size must be provided as a positive integer");
    v.resize(len);
    for (int i = 0; i < len; i++)
      v[i] = p1788_rbobj2interval(rb_yield(INT2NUM(i)));
  }
  else if (nb_scaned_args == 2) {
    if (!RB_INTEGER_TYPE_P(a1) || (len = NUM2INT(a1)) < 0)
      rb_raise(rb_eArgError, "if two arguments are given, the vector size must be provided as a positive integer");
    v.resize(len, p1788_rbobj2interval(a2));
  }
  else if (nb_scaned_args == 1) {
    if (RB_INTEGER_TYPE_P(a1)) {
      if ((len = NUM2INT(a1)) < 0)
        rb_raise(rb_eArgError, "the vector size must be provided as a positive integer");
      v.resize(len, Interval(-INF, INF));
    }
    else if (RB_TYPE_P(a1, T_ARRAY)) {
      len = rb_array_len(a1);
      v.resize(len);
      for (int i = 0; i < len; i++)
        v[i] = p1788_rbobj2interval(rb_ary_entry(a1, i));
    }
    else if (rb_obj_is_kind_of(a1, c_IntervalVector)) {
      const IntervalVector& u = p1788_vector_rb2ref(a1);
      v = u;
    }
    else
      rb_raise(rb_eTypeError, "argument one is expected to be an integer, an array or another %" PRIsVALUE ", not a %" PRIsVALUE,
          rb_class_name(c_IntervalVector), rb_class_name(rb_class_of(a1)));
  }
  return self;
}

Class Method Details

.[](obj, ...) ⇒ IntervalVector

Return a new interval vector initialized with elements.

Examples:

P1788::IntervalVector[1, 2.3, [4, 5], 6..7, P1788::Interval[8, 9], Rational(1, 10)]
# => IntervalVector[{1}, {2.3}, [4, 5], [6, 7], [8, 9], [0.09999999999999999, 0.1]]

Parameters:

  • obj (Interval, Integer, Float Rational, Range, Array)

    objects that can be converted to intervals

Returns:



4066
4067
4068
4069
4070
4071
4072
4073
4074
# File 'ext/p1788/p1788.cc', line 4066

static VALUE p1788_vector_from_array(int argc, VALUE *argv, VALUE self)
{
  VALUE r = rb_class_new_instance(0, NULL, c_IntervalVector);
  IntervalVector& v = p1788_vector_rb2ref(r);
  v.resize(argc);
  for (int i = 0; i < argc; i++)
    v[i] = p1788_rbobj2interval(argv[i]);
  return r;
}

Instance Method Details

#!=(other) ⇒ Boolean

Returns true if other is not an P1788::IntervalVector or if self.length != other.length or if for any index i in self, self[i] != other[i].

Returns:

  • (Boolean)


4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
# File 'ext/p1788/p1788.cc', line 4954

static VALUE p1788_vector_not_equal(VALUE self, VALUE other)
{
  if (self == other)
    return Qfalse;
  if (!rb_obj_is_kind_of(other, c_IntervalVector))
    return Qtrue;
  const IntervalVector& v = p1788_vector_rb2ref(self);
  const IntervalVector& u = p1788_vector_rb2ref(other);
  const size_t l = v.size();
  if (u.size() != l)
    return Qtrue;
  for (size_t i = 0; i < l; i++) {
    if (!Interval::equal(v[i], u[i]))
      return Qtrue;
  }
  return Qfalse;
}

#&(y) ⇒ IntervalVector

Vector intersection.

Returns:



6180
6181
6182
6183
# File 'ext/p1788/p1788.cc', line 6180

static VALUE p1788_vector_intersection(VALUE self, VALUE y)
{
  P1788_VECTOR_BINARY_OP(self, y, intersection);
}

#*(y) ⇒ IntervalVector

Arithmetic multiplication.

Returns:



6212
6213
6214
6215
# File 'ext/p1788/p1788.cc', line 6212

static VALUE p1788_vector_mul(VALUE self, VALUE y)
{
  P1788_VECTOR_BINARY_OP(self, y, mul);
}

#**(y) ⇒ IntervalVector

Power operator

Returns:



6295
6296
6297
6298
6299
6300
# File 'ext/p1788/p1788.cc', line 6295

static VALUE p1788_vector_powop(VALUE self, VALUE y)
{
  if (RB_INTEGER_TYPE_P(y))
    return p1788_vector_pown(self, y);
  return p1788_vector_pow(self, y);
}

#+(y) ⇒ IntervalVector

Arithmetic addition.

Returns:



6196
6197
6198
6199
# File 'ext/p1788/p1788.cc', line 6196

static VALUE p1788_vector_add(VALUE self, VALUE y)
{
  P1788_VECTOR_BINARY_OP(self, y, add);
}

#+@IntervalVector

+self

Returns:

See Also:



6134
6135
6136
# File 'ext/p1788/p1788.cc', line 6134

static VALUE p1788_vector_pos(VALUE self) {
  P1788_VECTOR_UNARIOP(self, pos);
}

#-(y) ⇒ IntervalVector

Arithmetic subtraction.

Returns:



6204
6205
6206
6207
# File 'ext/p1788/p1788.cc', line 6204

static VALUE p1788_vector_sub(VALUE self, VALUE y)
{
  P1788_VECTOR_BINARY_OP(self, y, sub);
}

#-@IntervalVector

Arithmetic opposite

Returns:

See Also:



6126
6127
6128
# File 'ext/p1788/p1788.cc', line 6126

static VALUE p1788_vector_neg(VALUE self) {
  P1788_VECTOR_UNARIOP(self, neg);
}

#/(y) ⇒ IntervalVector

Arithmetic division.

Returns:



6220
6221
6222
6223
# File 'ext/p1788/p1788.cc', line 6220

static VALUE p1788_vector_div(VALUE self, VALUE y)
{
  P1788_VECTOR_BINARY_OP(self, y, div);
}

#<<(obj) ⇒ self

Appends obj to self.

Parameters:

Returns:

  • (self)


5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
# File 'ext/p1788/p1788.cc', line 5007

static VALUE p1788_vector_pushpush(VALUE self, VALUE obj)
{
  IntervalVector& v = p1788_vector_rb2ref(self);
  if (rb_class_of(obj) == c_IntervalVector) {
    const IntervalVector& u = p1788_vector_rb2ref(obj);
    const int m = u.size();
    int i, j, l = v.size();
    v.resize(l+m);
    for (i = 0, j = l; i < m; i++, j++)
      v[j] = u[i];
  }
  else
    v.push_back(p1788_rbobj2interval(obj));
  return self;
}

#==(other) ⇒ Boolean

Returns true if both other is an P1788::IntervalVector and self.length == other.length and for each index i in self, self[i] == other[i].

Returns:

  • (Boolean)


4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
# File 'ext/p1788/p1788.cc', line 4930

static VALUE p1788_vector_equal(VALUE self, VALUE other)
{
  if (self == other)
    return Qtrue;
  if (!rb_obj_is_kind_of(other, c_IntervalVector))
    return Qfalse;
  const IntervalVector& v = p1788_vector_rb2ref(self);
  const IntervalVector& u = p1788_vector_rb2ref(other);
  const size_t l = v.size();
  if (u.size() != l)
    return Qfalse;
  for (size_t i = 0; i < l; i++) {
    if (!Interval::equal(v[i], u[i]))
      return Qfalse;
  }
  return Qtrue;
}

#[](index) ⇒ Interval? #[](range) ⇒ IntervalVector #[](array) ⇒ IntervalVector #[](start, length) ⇒ IntervalVector

Returns elements from self, does not modify self.

Overloads:

  • #[](index) ⇒ Interval?

    Returns the interval at offset index. If index is negative, counts relative to the end of self. If index is out of range, returns nil.

    Parameters:

    • index (Integer)

    Returns:

  • #[](range) ⇒ IntervalVector

    Parameters:

    • range (Range<Integer>)

    Returns:

  • #[](array) ⇒ IntervalVector

    Returns a new P1788::IntervalVector containing intervals from self indexed from elements of array. If indexes are negative, counts relative to the end of self. When indexes are out of range, empty intervals are returned.

    Parameters:

    • array (Array<Integer>)

    Returns:

  • #[](start, length) ⇒ IntervalVector

    Parameters:

    • start (Integer)

      start offset of the returned sequence

    • length (Integer)

      length of the returned sequence

    Returns:

Returns:



4066
4067
4068
4069
4070
4071
4072
4073
4074
# File 'ext/p1788/p1788.cc', line 4066

static VALUE p1788_vector_from_array(int argc, VALUE *argv, VALUE self)
{
  VALUE r = rb_class_new_instance(0, NULL, c_IntervalVector);
  IntervalVector& v = p1788_vector_rb2ref(r);
  v.resize(argc);
  for (int i = 0; i < argc; i++)
    v[i] = p1788_rbobj2interval(argv[i]);
  return r;
}

#[]=(index, interval) ⇒ Object #[]=(range, interval) ⇒ Object #[]=(range, vect) ⇒ Object #[]=(array, interval) ⇒ Object #[]=(array, vect) ⇒ Object #[]=(start, length, interval) ⇒ Object #[]=(start, length, vect) ⇒ Object

Assign intervals in self.

Overloads:

  • #[]=(index, interval) ⇒ Object

    Parameters:

  • #[]=(range, interval) ⇒ Object

    Parameters:

  • #[]=(range, vect) ⇒ Object

    Parameters:

  • #[]=(array, interval) ⇒ Object

    Parameters:

    • array (Array<Integer>)
    • interval (Interval)
  • #[]=(array, vect) ⇒ Object

    Parameters:

    • array (Array<Integer>)

      an array of indexes

    • vect (IntervalVector)

      a vector the same size as the array of indexes

  • #[]=(start, length, interval) ⇒ Object

    Parameters:

    • start (Integer)

      start offset of the modified sequence

    • length (Integer)

      length of the modified sequence

    • interval (Interval)
  • #[]=(start, length, vect) ⇒ Object

    Parameters:

    • start (Integer)

      start offset of the modified sequence

    • length (Integer)

      length of the modified sequence

    • vect (IntervalVector)

      a vector of size length

Returns:

  • (Object)


4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
# File 'ext/p1788/p1788.cc', line 4490

static VALUE p1788_vector_aset(int argc, VALUE *argv, VALUE self)
{
  if (argc == 2) {
    VALUE index = argv[0];
    VALUE elem  = argv[1];
    if (RB_INTEGER_TYPE_P(index))
      p1788_vector_aset_index(self, index, elem);
    else if (rb_class_of(index) == rb_cRange)
      p1788_vector_aset_range(self, index, elem);
    else if (RB_TYPE_P(index, T_ARRAY))
      p1788_vector_aset_array(self, index, elem);
    else
      rb_raise(rb_eArgError, "the index in P1788::IntervalVector#[]= should be an Integer, a Range or an Array, not a %" PRIsVALUE, 
          rb_class_name(rb_class_of(index)));
  }
  else if (argc == 3) {
    if (!RB_INTEGER_TYPE_P(argv[0]) || !RB_INTEGER_TYPE_P(argv[1]))
      rb_raise(rb_eArgError, "start and length in P1788::IntervalVector#[start,length]=val should be two integers");
    p1788_vector_aset_start_and_length(self, argv[0], argv[1], argv[2]);
  }
  else
    rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 2..3)", argc);

  return self;
}

#absIntervalVector

Absolute value

Returns:

See Also:



6118
6119
6120
# File 'ext/p1788/p1788.cc', line 6118

static VALUE p1788_vector_abs(VALUE self) {
  P1788_VECTOR_UNARIOP(self, abs);
}

#acosIntervalVector

Arc cosine

Returns:

See Also:



5992
5993
5994
# File 'ext/p1788/p1788.cc', line 5992

static VALUE p1788_vector_acos(VALUE self) {
  P1788_VECTOR_UNARIOP(self, acos);
}

#acoshIntervalVector

Inverse hyperbolic cosine

Returns:

See Also:



6040
6041
6042
# File 'ext/p1788/p1788.cc', line 6040

static VALUE p1788_vector_acosh(VALUE self) {
  P1788_VECTOR_UNARIOP(self, acosh);
}

#asinIntervalVector

Arc sine

Returns:

See Also:



5984
5985
5986
# File 'ext/p1788/p1788.cc', line 5984

static VALUE p1788_vector_asin(VALUE self) {
  P1788_VECTOR_UNARIOP(self, asin);
}

#asinhIntervalVector

Inverse hyperbolic sine

Returns:

See Also:



6032
6033
6034
# File 'ext/p1788/p1788.cc', line 6032

static VALUE p1788_vector_asinh(VALUE self) {
  P1788_VECTOR_UNARIOP(self, asinh);
}

#at(index) ⇒ Interval?

Returns the element at offset index. If index is negative, counts relative to the end of self. If index is out of range, returns nil.

Parameters:

  • index (Integer)

Returns:



4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
# File 'ext/p1788/p1788.cc', line 4192

static VALUE p1788_vector_at(VALUE self, VALUE index)
{
  int ind = NUM2INT(index);
  const IntervalVector &v = p1788_vector_rb2ref(self);
  const int l = v.size();
  if (ind < 0)
    ind = l+ind;
  if (ind < 0 || ind >= l)
    return Qnil;
  VALUE r;
  P1788_NEW_RB_INTERVAL(r, v[ind]);
  return r;
}

#atanIntervalVector

Arc tangent

Returns:

See Also:



6000
6001
6002
# File 'ext/p1788/p1788.cc', line 6000

static VALUE p1788_vector_atan(VALUE self) {
  P1788_VECTOR_UNARIOP(self, atan);
}

#atanhIntervalVector

Inverse hyperbolic tangent

Returns:

See Also:



6048
6049
6050
# File 'ext/p1788/p1788.cc', line 6048

static VALUE p1788_vector_atanh(VALUE self) {
  P1788_VECTOR_UNARIOP(self, atanh);
}

#bisect(dim = nil, ratio = 0.5) ⇒ Array<IntervalVector>

Bisect self into two interval vectors along dimension dim and split point ratio. Raise an exception if self cannot be bisected along the given dimension.

If the dimension is not specified, it will be choosen randomly among the widest intervals of self.

Parameters:

  • dim (Integer) (defaults to: nil)

    index of the dimension on which to perform the bisection

  • ratio (Float) (defaults to: 0.5)

    tell where to split the interval self[dim], 0 < ratio < 1

Returns:

See Also:



5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
# File 'ext/p1788/p1788.cc', line 5520

static VALUE p1788_vector_bisect(int argc, VALUE *argv, VALUE self)
{
  VALUE dimr, ratior;
  int dim = -1;
  double ratio = 0.5;
  IntervalVector &v = p1788_vector_rb2ref(self);
  const size_t l = v.size();

  rb_scan_args(argc, argv, "02", &dimr, &ratior);
  if (dimr != Qnil) {
    dim = NUM2INT(dimr);
    if (dim < 0 || dim >= (int)l)
      rb_raise(rb_eRangeError, "given bisection dimension out of range");
  }
  if (ratior != Qnil) {
    ratio = NUM2DBL(ratior);
    if (ratio <= 0.0 || ratio >= 1.0)
      rb_raise(rb_eRuntimeError, "the given bisection ratio must be > 0 and < 1");
  }
  /* Choose a dimension */
  if (dim < 0) {
    size_t i;
    double max_width = -1.0;
    for (i = 0; i < l; i++) {
      double w = Interval::wid(v[i]);
      if (w > 0.0 && max_width < w)
        max_width = w;
    }
    if (max_width <= 0.0)
      rb_raise(rb_eRuntimeError, "the interval vector is not bisectable");
    std::vector<int> max_width_indexes;
    for (i = 0; i < l; i++) {
      if (Interval::wid(v[i]) >= max_width)
        max_width_indexes.push_back((int)i);
    }
    dim = max_width_indexes[(unsigned int)rb_genrand_int32() % (unsigned int)(max_width_indexes.size())];
  }

  /* Bisect the interval */
  const Interval &inter = v[dim];
  double lb = Interval::inf(inter);
  double mp = Interval::mid(inter);
  double ub = Interval::sup(inter);
  Interval bleft, bright;
  if (Interval::is_empty(inter) || Interval::inf(inter) >= mp || mp >= Interval::sup(inter))
    rb_raise(rb_eRuntimeError, "the interval vector is not bisectable at dimension %d", dim);
  if (ratio == 0.5 || lb == -INF || ub == INF) {
    bleft  = Interval(lb, mp);
    bright = Interval(mp, ub);
  }
  else {
    mp = lb+ratio*Interval::wid(inter);
    if (mp >= ub)
      mp = std::nextafter(lb, INF);
    if (mp >= ub)
      rb_raise(rb_eRuntimeError, "the interval vector is not bisectable at dimension %d", dim);
    bleft  = Interval(lb, mp);
    bright = Interval(mp, ub);
  }

  IntervalVector *vl = new IntervalVector(v);
  IntervalVector *vr = new IntervalVector(v);
  (*vl)[dim] = bleft;
  (*vr)[dim] = bright;

  return rb_ary_new_from_args(2,
      p1788_vector_alloc_from_pointer(vl),
      p1788_vector_alloc_from_pointer(vr));
}

#bisectable?Boolean

Tells if self can be bisected in at least one dimension. Return [Boolean]

Returns:

  • (Boolean)

See Also:



5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
# File 'ext/p1788/p1788.cc', line 5257

static VALUE p1788_vector_is_bisectable(VALUE self)
{
  IntervalVector &v = p1788_vector_rb2ref(self);
  const size_t l = v.size();
  if (l < 1)
    return Qfalse;
  for (size_t i = 0; i < l; i++) {
    if (p1788_interval_is_bisectable(v[i]))
      return Qtrue;
  }
  return Qfalse;
}

#bisectable_dimensionsArray<Integer>

Returns an array containing the indices of the dimensions of self that can be bisected.

Returns:

  • (Array<Integer>)


5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
# File 'ext/p1788/p1788.cc', line 5457

static VALUE p1788_vector_bisectable_dimensions(VALUE self)
{
  IntervalVector &v = p1788_vector_rb2ref(self);
  const size_t l = v.size();
  VALUE ar = rb_ary_new();
  for (size_t i = 0; i < l; i++) {
    if (p1788_interval_is_bisectable(v[i]))
      rb_ary_push(ar, SIZET2NUM(i));
  }
  return ar;
}

#bounded?Boolean

self is empty or a bounded interval vector.

Returns:

  • (Boolean)

See Also:



5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
# File 'ext/p1788/p1788.cc', line 5202

static VALUE p1788_vector_is_bounded(VALUE self)
{
  IntervalVector &v = p1788_vector_rb2ref(self);
  const int l = v.size();
  if (l < 1)
    return Qtrue;
  for (int i = 0; i < l; i++) {
    if (!(Interval::is_empty(v[i]) || Interval::is_common_interval(v[i])))
      return Qfalse;
  }
  return Qtrue;
}

#cancel_minus(y) ⇒ IntervalVector



6254
6255
6256
6257
# File 'ext/p1788/p1788.cc', line 6254

static VALUE p1788_vector_cancel_minus(VALUE self, VALUE y)
{
  P1788_VECTOR_BINARY_OP(self, y, cancel_minus);
}

#cancel_plus(y) ⇒ IntervalVector



6262
6263
6264
6265
# File 'ext/p1788/p1788.cc', line 6262

static VALUE p1788_vector_cancel_plus(VALUE self, VALUE y)
{
  P1788_VECTOR_BINARY_OP(self, y, cancel_plus);
}

#ceilIntervalVector

Round bounds towards +∞

Returns:

See Also:



6064
6065
6066
# File 'ext/p1788/p1788.cc', line 6064

static VALUE p1788_vector_ceil(VALUE self) {
  P1788_VECTOR_UNARIOP(self, ceil);
}

#cloneIntervalVector

Return a new P1788::IntervalVector equal to self, also copying its singleton class.

Returns:



5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
# File 'ext/p1788/p1788.cc', line 5104

static VALUE p1788_vector_clone(VALUE self)
{
  VALUE c = rb_call_super(0, NULL);
  IntervalVector& v = p1788_vector_rb2ref(self);
  IntervalVector& w = p1788_vector_rb2ref(c);
  const int l = v.size();
  w.resize(l);
  for (int i = 0; i < l; i++)
    w[i] = v[i];
  return c;
}

#coerce(other) ⇒ Array<Interval, IntervalVector>

The coerce method provides support for Ruby type coercion. This coercion mechanism is used by Ruby to handle mixed-type numeric operations: it is intended to find a compatible common type between the two operands of the operator.

In case of Numeric op IntervalVector, the numeric is transformed in an interval, and this interval should know how to handle the vector.

Parameters:

  • other (Numeric)

Returns:



6148
6149
6150
6151
6152
6153
# File 'ext/p1788/p1788.cc', line 6148

static VALUE p1788_vector_coerce(VALUE self, VALUE other)
{
  VALUE rbo;
  P1788_NEW_RB_INTERVAL(rbo, p1788_rbobj2interval(other));
  return rb_ary_new_from_args(2, rbo, self);
}

#collect {|interval| ... } ⇒ IntervalVector #collectEnumerator

Calls the block with each interval of self; returns a new P1788::IntervalVector whose elements are the intervals returned from the block, self is not modified. Returns a new Enumerator if no block is given.

Examples:

v = P1788::IntervalVector.new(5) { |i| P1788::Interval[i] }
# => IntervalVector[{0}, {1}, {2}, {3}, {4}]
u = v.collect { |inter| inter + 3 }
u # => IntervalVector[{3}, {4}, {5}, {6}, {7}]
v # => IntervalVector[{0}, {1}, {2}, {3}, {4}]

Overloads:

  • #collect {|interval| ... } ⇒ IntervalVector

    Returns a new vector or an Enumerator.

    Yield Parameters:

    Yield Returns:

    • (Interval, Integer, Float, Rational, Range, Array)

      an object that can be converted to an interval

    Returns:

  • #collectEnumerator

    Returns:

    • (Enumerator)

Returns:



4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
# File 'ext/p1788/p1788.cc', line 4600

static VALUE p1788_vector_collect(VALUE self)
{
  RETURN_SIZED_ENUMERATOR(self, 0, 0, p1788_vector_enum_length);
  IntervalVector &v = p1788_vector_rb2ref(self);
  const int l = v.size();
  VALUE r = p1788_vector_alloc(c_IntervalVector);
  IntervalVector &u = p1788_vector_rb2ref(r);
  u.resize(l);
  for (int i = 0; i < l; i++) {
    VALUE y;
    P1788_NEW_RB_INTERVAL(y, v[i]);
    u[i] = p1788_rbobj2interval(rb_yield(y));
  }
  return r;
}

#collect! {|interval| ... } ⇒ self #collect!Enumerator

Calls the block, if given, with each interval of self; replaces the interval with the block's return value. Returns a new Enumerator if no block is given.

Examples:

v = P1788::IntervalVector.new(5) { |i| P1788::Interval[i] }
# => IntervalVector[{0}, {1}, {2}, {3}, {4}]
v.collect! { |inter| inter + 1.5 }
# => IntervalVector[{1.5}, {2.5}, {3.5}, {4.5}, {5.5}]
v
# => IntervalVector[{1.5}, {2.5}, {3.5}, {4.5}, {5.5}]
v.collect!
# => #<Enumerator: IntervalVector[{0}, {1}, {2}, {3}, {4}]:collect!>

Overloads:

  • #collect! {|interval| ... } ⇒ self

    Yield Parameters:

    Yield Returns:

    • (Interval)

      an object that can be converted to an interval (Interval, Integer, Float, Rational, Range or Array)

    Returns:

    • (self)
  • #collect!Enumerator

    Returns:

    • (Enumerator)

Returns:

  • (self, Enumerator)


4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
# File 'ext/p1788/p1788.cc', line 4637

static VALUE p1788_vector_collect_bang(VALUE self)
{
  RETURN_SIZED_ENUMERATOR(self, 0, 0, p1788_vector_enum_length);
  IntervalVector& v = p1788_vector_rb2ref(self);
  const int l = v.size();
  for (int i = 0; i < l; i++) {
    VALUE y;
    P1788_NEW_RB_INTERVAL(y, v[i]);
    v[i] = p1788_rbobj2interval(rb_yield(y));
  }
  return self;
}

#common?Boolean

self is a bounded nonempty interval vector

Returns:

  • (Boolean)


5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
# File 'ext/p1788/p1788.cc', line 5239

static VALUE p1788_vector_is_common(VALUE self)
{
  IntervalVector &v = p1788_vector_rb2ref(self);
  const int l = v.size();
  if (l < 1)
    return Qfalse;
  for (int i = 0; i < l; i++) {
    if (!Interval::is_common_interval(v[i]))
      return Qfalse;
  }
  return Qtrue;
}

#compactIntervalVector

Returns a new vector containing all nonempty intervals from self.

Returns:



4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
# File 'ext/p1788/p1788.cc', line 4774

static VALUE p1788_vector_compact(VALUE self)
{
  IntervalVector &v = p1788_vector_rb2ref(self);
  VALUE r = p1788_vector_alloc(c_IntervalVector);
  IntervalVector &u = p1788_vector_rb2ref(r);
  const int l = v.size();
  for (int i = 0; i < l; i++) {
    if (!Interval::is_empty(v[i]))
      u.push_back(v[i]);
  }
  return r;
}

#compact!self

Removes all empty intervals from self.

Returns:

  • (self)


4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
# File 'ext/p1788/p1788.cc', line 4791

static VALUE p1788_vector_compact_bang(VALUE self)
{
  IntervalVector &v = p1788_vector_rb2ref(self);
  IntervalVector u;
  const int l = v.size();
  for (int i = 0; i < l; i++) {
    if (!Interval::is_empty(v[i]))
      u.push_back(v[i]);
  }
  v = std::move(u);
  return self;
}

#contain_interior_of?(y) ⇒ Boolean

[𝒔𝒆𝒍𝒇] âȘŸ [𝒚]

y is in the interior of self.

∀ 𝑖 ∈ (0, ..., 𝑛-1), [𝒔𝒆𝒍𝒇]i âȘŸ [𝒚]i

y and self must have the same length ; returns true if length is zero.

Returns:

  • (Boolean)


5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
# File 'ext/p1788/p1788.cc', line 5806

static VALUE p1788_vector_contains_interior(VALUE self, VALUE y)
{
  const IntervalVector &v = p1788_vector_rb2ref(self);
  const size_t l = v.size();
  if (l == 0)
    return Qtrue;
  const IntervalVector &u = p1788_raise_if_not_vector_of_given_length(y, l);
  for (size_t i = 0; i < l; i++) {
    if (!(Interval::contains_interior(v[i], u[i])))
      return Qfalse;
  }
  return Qtrue;
}

#cosIntervalVector

Cosine

Returns:

See Also:



5968
5969
5970
# File 'ext/p1788/p1788.cc', line 5968

static VALUE p1788_vector_cos(VALUE self) {
  P1788_VECTOR_UNARIOP(self, cos);
}

#coshIntervalVector

Hyperbolic cosine

Returns:

See Also:



6016
6017
6018
# File 'ext/p1788/p1788.cc', line 6016

static VALUE p1788_vector_cosh(VALUE self) {
  P1788_VECTOR_UNARIOP(self, cosh);
}

#disjoint_from?(y) ⇒ Boolean

[𝒔𝒆𝒍𝒇] ∩ [𝒚] = ∅

∃ 𝑖 ∈ (0, ..., 𝑛-1), ∀ đ‘„ ∈ [𝒔𝒆𝒍𝒇]𝑖, ∀ 𝑩 ∈ [𝒚]𝑖, đ‘„ ≠ 𝑩

true if there is an index i for which self[i] is dijoint from y[i].

y and self must have the same length ; returns true if length is zero.

Returns:

  • (Boolean)


5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
# File 'ext/p1788/p1788.cc', line 5612

static VALUE p1788_vector_disjoint(VALUE self, VALUE y)
{
  const IntervalVector &v = p1788_vector_rb2ref(self);
  const size_t l = v.size();
  if (l == 0)
    return Qtrue;
  const IntervalVector &u = p1788_raise_if_not_vector_of_given_length(y, l);
  for (size_t i = 0; i < l; i++) {
    if (Interval::disjoint(v[i], u[i]))
      return Qtrue;
  }
  return Qfalse;
}

#dupIntervalVector

Return a new P1788::IntervalVector equal to self.

Returns:



5095
5096
5097
5098
# File 'ext/p1788/p1788.cc', line 5095

static VALUE p1788_vector_dup(VALUE self)
{
  return rb_class_new_instance(1, &self, c_IntervalVector);
}

#each {|interval| ... } ⇒ IntervalVector #eachEnumerator

Calls the given block, if given, once for each interval in self. The intervals are passed as parameters to the block.

Returns self, or, if no block is given, an Enumerator is returned.

Overloads:

Returns:

  • (self, Enumerator)


4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
# File 'ext/p1788/p1788.cc', line 4534

static VALUE p1788_vector_each(VALUE self)
{
  RETURN_SIZED_ENUMERATOR(self, 0, 0, p1788_vector_enum_length);
  IntervalVector& v = p1788_vector_rb2ref(self);
  const int l = v.size();
  for (int i = 0; i < l; i++) {
    VALUE r;
    P1788_NEW_RB_INTERVAL(r, v[i]);
    rb_yield(r);
  }
  return self;
}

#empty?Boolean

[𝒔𝒆𝒍𝒇] = ∅. self is empty if any of its intervals is empty, or if it has a length of 0. Not to be confused with Array#empty?, because an IntervalVector of length > 0 can be empty.

Returns:

  • (Boolean)


5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
# File 'ext/p1788/p1788.cc', line 5148

static VALUE p1788_vector_is_empty(VALUE self)
{
  IntervalVector &v = p1788_vector_rb2ref(self);
  const int l = v.size();
  if (l < 1)
    return Qtrue;
  for (int i = 0; i < l; i++) {
    if (Interval::is_empty(v[i]))
      return Qtrue;
  }
  return Qfalse;
}

#eql?(other) ⇒ Boolean

Returns true if both other is an P1788::IntervalVector and self.length == other.length and for each index i in self, self[i] == other[i].

Returns:

  • (Boolean)


4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
# File 'ext/p1788/p1788.cc', line 4930

static VALUE p1788_vector_equal(VALUE self, VALUE other)
{
  if (self == other)
    return Qtrue;
  if (!rb_obj_is_kind_of(other, c_IntervalVector))
    return Qfalse;
  const IntervalVector& v = p1788_vector_rb2ref(self);
  const IntervalVector& u = p1788_vector_rb2ref(other);
  const size_t l = v.size();
  if (u.size() != l)
    return Qfalse;
  for (size_t i = 0; i < l; i++) {
    if (!Interval::equal(v[i], u[i]))
      return Qfalse;
  }
  return Qtrue;
}

#expIntervalVector

Exponential

Returns:

See Also:



5911
5912
5913
# File 'ext/p1788/p1788.cc', line 5911

static VALUE p1788_vector_exp(VALUE self) {
  P1788_VECTOR_UNARIOP(self, exp);
}

#exp10IntervalVector

Base 10 exponential

Returns:

See Also:



5927
5928
5929
# File 'ext/p1788/p1788.cc', line 5927

static VALUE p1788_vector_exp10(VALUE self) {
  P1788_VECTOR_UNARIOP(self, exp10);
}

#exp2IntervalVector

Base 2 exponential

Returns:

See Also:



5919
5920
5921
# File 'ext/p1788/p1788.cc', line 5919

static VALUE p1788_vector_exp2(VALUE self) {
  P1788_VECTOR_UNARIOP(self, exp2);
}

#firstInterval? #first(n) ⇒ IntervalVector

Returns first intervals from self. Does not modify self.

Overloads:

  • #firstInterval?

    When no argument is given, returns the first interval. If self has length 0, returns nil.

    Returns:

  • #first(n) ⇒ IntervalVector

    When non-negative Integer argument n is given, returns the first n intervals in an new vector. If n >= self.length, returns all elements. If n <= 0, returns a new vector with no intervals.

    Parameters:

    • n (Integer)

      number of intervals to return

    Returns:

Returns:



4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
# File 'ext/p1788/p1788.cc', line 4854

static VALUE p1788_vector_first(int argc, VALUE *argv, VALUE self)
{
  const IntervalVector &v = p1788_vector_rb2ref(self);
  const int l = v.size();
  int rl;
  VALUE n, r;
  if (rb_scan_args(argc, argv, "01", &n)) {
    rl = NUM2INT(n);
    if (rl < 0)
      rl = 0;
    else if (rl > l)
      rl = l;
    r = p1788_vector_alloc(c_IntervalVector);
    IntervalVector &u = p1788_vector_rb2ref(r);
    u.resize(rl);
    for (int i = 0; i < rl; i++)
      u[i] = v[i];
  }
  else {
    if (l > 0)
      P1788_NEW_RB_INTERVAL(r, v[0]);
    else
      r = Qnil;
  }
  return r;
}

#flat?Boolean

Note:

An empty interval vector is considered as flat.

An interval vector is "flat" if the width is 0 on at least one dimension.

Returns:

  • (Boolean)


5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
# File 'ext/p1788/p1788.cc', line 5184

static VALUE p1788_vector_is_flat(VALUE self)
{
  IntervalVector &v = p1788_vector_rb2ref(self);
  const int l = v.size();
  if (l < 1)
    return Qtrue;
  for (int i = 0; i < l; i++) {
    if (Interval::is_empty(v[i]) || Interval::is_singleton(v[i]))
      return Qtrue;
  }
  return Qfalse;
}

#floorIntervalVector

Round bounds towards -∞

Returns:

See Also:



6072
6073
6074
# File 'ext/p1788/p1788.cc', line 6072

static VALUE p1788_vector_floor(VALUE self) {
  P1788_VECTOR_UNARIOP(self, floor);
}

#floorceilIntervalVector

Inflate intervals towards nearest integer boundsRound bounds



6080
6081
6082
6083
6084
6085
6086
6087
6088
# File 'ext/p1788/p1788.cc', line 6080

static VALUE p1788_vector_floorceil(VALUE self)
{
  const IntervalVector &v = p1788_vector_rb2ref(self);
  const size_t l = v.size();
  IntervalVector *t = new IntervalVector(l);
  for (size_t i = 0; i < l; i++)
    (*t)[i] = Interval(std::floor(Interval::inf(v[i])), std::ceil(Interval::sup(v[i])));
  return p1788_vector_alloc_from_pointer(t);
}

#hashInteger

Returns the integer hash value for self. Two P1788::IntervalVectors with the same content will have the same hash code (and will compare using #eql?.

Returns:

  • (Integer)


4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
# File 'ext/p1788/p1788.cc', line 4978

static VALUE p1788_vector_hash(VALUE self)
{
  st_index_t h, ih[2];
  const IntervalVector& v = p1788_vector_rb2ref(self);
  const int l = v.size();
  VALUE n;


  h = rb_hash_start(l);
  h = rb_hash_uint(h, (st_index_t)p1788_vector_hash);
  for (int i = 0; i < l; i++) {
    n = rb_hash(DBL2NUM(Interval::inf(v[i])));
    ih[0] = NUM2LONG(n);
    n = rb_hash(DBL2NUM(Interval::sup(v[i])));
    ih[1] = NUM2LONG(n);
    n = ST2FIX(rb_memhash(ih, sizeof(ih)));
    h = rb_hash_uint(h, NUM2LONG(n));
  }
  h = rb_hash_end(h);

  return ST2FIX(h);
}

#include?(array) ⇒ Boolean

array ∈ self.

true if array and self have the same length and for each index, array[i] ∈ self[i].

Parameters:

  • array (Array<Float>)

Returns:

  • (Boolean)


5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
# File 'ext/p1788/p1788.cc', line 5827

static VALUE p1788_vector_include(VALUE self, VALUE array)
{
  if (!RB_TYPE_P(array, T_ARRAY))
    rb_raise(rb_eTypeError, "expecting an array, not a %" PRIsVALUE,
        rb_class_name(rb_class_of(array)));
  const IntervalVector &v = p1788_vector_rb2ref(self);
  const size_t l = v.size();
  if (rb_array_len(array) != (long int)l)
    rb_raise(rb_eRangeError, "interval vector and array do not have the same length: %lu and %lu",
        l, rb_array_len(array));
  for (size_t i = 0; i < l; i++) {
    if (!Interval::is_member(NUM2DBL(rb_ary_entry(array, i)), v[i]))
      return Qfalse;
  }
  return Qtrue;
}

#inclusion_test(y) ⇒ Boolean?

Test if self is included in y, disjoint from y, or if self and y intersect.

Returns:
flase if self and y are disjoint; else
true if self is included in y; else
nil : self and y intersect.

Parameters:

Returns:

  • (Boolean, nil)


5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
# File 'ext/p1788/p1788.cc', line 5854

static VALUE p1788_vector_inclusion_test(VALUE self, VALUE y)
{
  const IntervalVector &v = p1788_vector_rb2ref(self);
  const size_t l = v.size();
  if (l == 0)
    return Qfalse;
  const IntervalVector &u = p1788_raise_if_not_vector_of_given_length(y, l);

  bool all_subsets = true;
  for (size_t i = 0; i < l; i++) {
    if (Interval::disjoint(v[i], u[i]))
      return Qfalse;
    if (!Interval::subset(v[i], u[i]))
      all_subsets = false;

  }
  return all_subsets ? Qtrue : Qnil;
}

#inflate(rad) ⇒ Interval #inflate(delta, chi) ⇒ Interval

Inflate (or deflate) the interval vector on each dimensions.

Overloads:

  • #inflate(rad) ⇒ Interval

    Add [-rad, rad] to self

    Parameters:

    • rad (Float)

      rad < 0 : deflate; rad = 0 : no change; rad > 0 : inflate

  • #inflate(delta, chi) ⇒ Interval

    Relative and absolute inflation. Return `self.midpoint + delta*(self - self.midpoint) + chi*[-1, +1]1

    Parameters:

    • delta (Float)

      Relative coefficient. delta < 1 : deflate; delta = 1 : no change; delta > 1 : inflate

    • chi (Float)

      Absolute coefficient. chi < 0 : deflate; chi = 0 : no change; chi > 0 : inflate



5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
# File 'ext/p1788/p1788.cc', line 5480

static VALUE p1788_vector_inflate(int argc, VALUE *argv, VALUE self)
{
  IntervalVector &v = p1788_vector_rb2ref(self);
  const size_t l = v.size();
  IntervalVector *t;
  if (argc == 1) {
    double rad = NUM2DBL(argv[0]);
    Interval radrad(-rad, rad);
    t = new IntervalVector(l);
    for (size_t i = 0; i < l; i++)
      (*t)[i] = Interval::add(v[i], radrad);
  }
  else if (argc == 2) {
    double delta = NUM2DBL(argv[0]);
    double chi   = NUM2DBL(argv[1]);
    Interval d(delta, delta);
    Interval chichi(-chi, chi);
    t = new IntervalVector(l);
    for (size_t i = 0; i < l; i++) {
      double mid = Interval::mid(v[i]);
      Interval m(mid, mid);
      (*t)[i] = m + d*(v[i]-m) + chichi;
    }
  }
  else
    rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 1..2)", argc);
  return p1788_vector_alloc_from_pointer(t);
}

#inspectString

String representation of the vector. If the vector has more than 32 elements, the returned string will be ellipsed with ", ..."

Returns:

  • (String)


4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
# File 'ext/p1788/p1788.cc', line 4081

static VALUE p1788_vector_inspect(VALUE self)
{
  const IntervalVector &v = p1788_vector_rb2ref(self);
  //std::string r(p1788_obj2cppstring(rb_class_name(c_IntervalVector)) + "[");
  std::string r("IntervalVector[");
  const std::string jn(", ");
  int l = v.size();
  if (l > 0)
    r += p1788_interval_to_cppstring(v[0]);
  for (int i = 1; i < l && i < 32; i++)
    r += jn + p1788_interval_to_cppstring(v[i]);
  if (l > 32)
    r += ", ...";
  r += "]";
  return rb_utf8_str_new(r.c_str(), r.length());
}

#interior_subset_of?(y) ⇒ Boolean

[𝒔𝒆𝒍𝒇] âȘœ [𝒚]

self is in the interior of y

∀ 𝑖 ∈ (0, ..., 𝑛-1), [𝒔𝒆𝒍𝒇]i âȘœ [𝒚]i

y and self must have the same length ; returns true if length is zero.

Returns:

  • (Boolean)


5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
# File 'ext/p1788/p1788.cc', line 5782

static VALUE p1788_vector_interior(VALUE self, VALUE y)
{
  const IntervalVector &v = p1788_vector_rb2ref(self);
  const size_t l = v.size();
  if (l == 0)
    return Qtrue;
  const IntervalVector &u = p1788_raise_if_not_vector_of_given_length(y, l);
  for (size_t i = 0; i < l; i++) {
    if (!(Interval::interior(v[i], u[i])))
      return Qfalse;
  }
  return Qtrue;
}

#intersect?(y) ⇒ Boolean

[𝒔𝒆𝒍𝒇] ∩ [𝒚] ≠ ∅

∀ 𝑖 ∈ (0, ..., 𝑛-1), ∃ đ‘„ ∈ [𝒔𝒆𝒍𝒇]i, ∃ 𝑩 ∈ [𝒚]i, đ‘„ = 𝑩

true if for each index i, self[i] intersects y[i].

y and self must have the same length ; returns false if length is zero.

Returns:

  • (Boolean)


5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
# File 'ext/p1788/p1788.cc', line 5636

static VALUE p1788_vector_intersect(VALUE self, VALUE y)
{
  const IntervalVector &v = p1788_vector_rb2ref(self);
  const size_t l = v.size();
  if (l == 0)
    return Qfalse;
  const IntervalVector &u = p1788_raise_if_not_vector_of_given_length(y, l);
  for (size_t i = 0; i < l; i++) {
    if (Interval::disjoint(v[i], u[i]))
      return Qfalse;
  }
  return Qtrue;
}

#lastInterval? #last(n) ⇒ IntervalVector

Returns the last intervals form selfs. Does not modify self.

Overloads:

  • #lastInterval?

    When no argument is given, returns the last interval. If self has length 0, returns nil.

    Returns:

  • #last(n) ⇒ IntervalVector

    When non-negative Integer argument n is given, returns the last n intervals in an new vector. If n >= self.length, returns all elements. If n <= 0, returns a new vector with no intervals.

    Parameters:

    • n (Integer)

      number of intervals to return

    Returns:

Returns:



4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
# File 'ext/p1788/p1788.cc', line 4897

static VALUE p1788_vector_last(int argc, VALUE *argv, VALUE self)
{
  const IntervalVector &v = p1788_vector_rb2ref(self);
  const int l = v.size();
  int rl;
  VALUE n, r;
  if (rb_scan_args(argc, argv, "01", &n)) {
    rl = NUM2INT(n);
    if (rl < 0)
      rl = 0;
    else if (rl > l)
      rl = l;
    r = p1788_vector_alloc(c_IntervalVector);
    IntervalVector &u = p1788_vector_rb2ref(r);
    u.resize(rl);
    for (int i = 0; i < rl; i++)
      u[i] = v[l+i-rl];
  }
  else {
    if (l > 0)
      P1788_NEW_RB_INTERVAL(r, v[l-1]);
    else
      r = Qnil;
  }
  return r;
}

#lengthInteger

Number of elements stored in the vector

Returns:

  • (Integer)


4166
4167
4168
4169
# File 'ext/p1788/p1788.cc', line 4166

static VALUE p1788_vector_length(VALUE self)
{
  return SIZET2NUM(p1788_vector_rb2ref(self).size());
}

#logIntervalVector

Natural logarithm.

Returns:

See Also:



5935
5936
5937
# File 'ext/p1788/p1788.cc', line 5935

static VALUE p1788_vector_log(VALUE self) {
  P1788_VECTOR_UNARIOP(self, log);
}

#log10IntervalVector

Base 10 logarithm

Returns:

See Also:



5951
5952
5953
# File 'ext/p1788/p1788.cc', line 5951

static VALUE p1788_vector_log10(VALUE self) {
  P1788_VECTOR_UNARIOP(self, log10);
}

#log2IntervalVector

Base 2 logarithm

Returns:

See Also:



5943
5944
5945
# File 'ext/p1788/p1788.cc', line 5943

static VALUE p1788_vector_log2(VALUE self) {
  P1788_VECTOR_UNARIOP(self, log2);
}

#lower_boundsArray<Float, nil>

Returns an array conaining the lower bounds of the elements in self. nil is returned for empty elements.

Returns:

  • (Array<Float, nil>)


5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
# File 'ext/p1788/p1788.cc', line 5363

static VALUE p1788_vector_lower_bounds(VALUE self)
{
  IntervalVector &v = p1788_vector_rb2ref(self);
  const size_t l = v.size();
  VALUE ar = rb_ary_new_capa(l);
  for (size_t i = 0; i < l; i++) {
    if (Interval::is_empty(v[i]))
      rb_ary_store(ar, i, Qnil);
    else
      rb_ary_store(ar, i, DBL2NUM(Interval::inf(v[i])));
  }
  return ar;
}

#map {|interval| ... } ⇒ Array #mapEnumerator

Calls the block, if given, with each interval of self; returns a new Array whose elements are the return values from the block.

Returns a new Enumerator if no block is given.

Examples:

v = P1788::IntervalVector.new(5) { |i| P1788::Interval[i] }
# => IntervalVector[{0}, {1}, {2}, {3}, {4}]
v.map { |inter| inter.mignitude }
# => [0.0, 1.0, 2.0, 3.0, 4.0]
v.map
# => #<Enumerator: IntervalVector[{0}, {1}, {2}, {3}, {4}]:map>

Overloads:

  • #map {|interval| ... } ⇒ Array

    Returns an array the length of self containing the return value of each block call.

    Yield Parameters:

    Returns:

    • (Array)

      an array the length of self containing the return value of each block call

  • #mapEnumerator

    Returns:

    • (Enumerator)

Returns:

  • (Array, Enumerator)

See Also:



4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
# File 'ext/p1788/p1788.cc', line 4567

static VALUE p1788_vector_map(VALUE self)
{
  RETURN_SIZED_ENUMERATOR(self, 0, 0, p1788_vector_enum_length);
  IntervalVector& v = p1788_vector_rb2ref(self);
  const int l = v.size();
  VALUE ar = rb_ary_new_capa(l);
  for (int i = 0; i < l; i++) {
    VALUE r;
    P1788_NEW_RB_INTERVAL(r, v[i]);
    rb_ary_store(ar, i, rb_yield(r));
  }
  return ar;
}

#max(y) ⇒ IntervalVector

Returns:

See Also:



6246
6247
6248
6249
# File 'ext/p1788/p1788.cc', line 6246

static VALUE p1788_vector_max(VALUE self, VALUE y)
{
  P1788_VECTOR_BINARY_OP(self, y, max);
}

#max_widthFloat?

Returns the maximum width of the components of self. Returns nil if self is empty.

Returns:

  • (Float, nil)


5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
# File 'ext/p1788/p1788.cc', line 5343

static VALUE p1788_vector_max_width(VALUE self)
{
  IntervalVector &v = p1788_vector_rb2ref(self);
  const size_t l = v.size();
  if (l < 1)
    return Qnil;
  double res = Interval::wid(v[0]);
  for (size_t i = 1; i < l; i++) {
    if (Interval::is_empty(v[i]))
      return Qnil;
    res = std::max(res, Interval::wid(v[i]));
  }
  return DBL2NUM(res);
}

#midpointsArray<Float, nil>

Returns an array conaining the midpoints of the elements in self. nil is returned for empty elements.

Returns:

  • (Array<Float, nil>)


5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
# File 'ext/p1788/p1788.cc', line 5439

static VALUE p1788_vector_midpoints(VALUE self)
{
  IntervalVector &v = p1788_vector_rb2ref(self);
  const size_t l = v.size();
  VALUE ar = rb_ary_new_capa(l);
  for (size_t i = 0; i < l; i++) {
    if (!Interval::is_common_interval(v[i]))
      rb_ary_store(ar, i, Qnil);
    else
      rb_ary_store(ar, i, DBL2NUM(Interval::mid(v[i])));
  }
  return ar;
}

#min(y) ⇒ IntervalVector

Returns:

See Also:



6238
6239
6240
6241
# File 'ext/p1788/p1788.cc', line 6238

static VALUE p1788_vector_min(VALUE self, VALUE y)
{
  P1788_VECTOR_BINARY_OP(self, y, min);
}

#min_widthFloat?

Returns the minimum width of the components of self. Returns nil if self is empty.

Returns:

  • (Float, nil)


5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
# File 'ext/p1788/p1788.cc', line 5323

static VALUE p1788_vector_min_width(VALUE self)
{
  IntervalVector &v = p1788_vector_rb2ref(self);
  const size_t l = v.size();
  if (l < 1)
    return Qnil;
  double res = Interval::wid(v[0]);
  for (size_t i = 1; i < l; i++) {
    if (Interval::is_empty(v[i]))
      return Qnil;
    res = std::min(res, Interval::wid(v[i]));
  }
  return DBL2NUM(res);
}

#nonempty?Boolean

[𝒔𝒆𝒍𝒇] ≠ ∅. self is nonempty if it has at least one element and all of its intervals are nonempty.

Returns:

  • (Boolean)


5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
# File 'ext/p1788/p1788.cc', line 5166

static VALUE p1788_vector_is_nonempty(VALUE self)
{
  IntervalVector &v = p1788_vector_rb2ref(self);
  const int l = v.size();
  if (l < 1)
    return Qfalse;
  for (int i = 0; i < l; i++) {
    if (Interval::is_empty(v[i]))
      return Qfalse;
  }
  return Qtrue;
}

#overlap?(y) ⇒ Boolean

volume([𝒔𝒆𝒍𝒇] ∩ [𝒚]) > 0

∀ 𝑖 ∈ (0, ..., 𝑛-1), width([𝒔𝒆𝒍𝒇]i ∩ [𝒚]i) > 0

true if y intersects self and their intersection has a non null volume.

y and self must have the same length ; returns false if length is zero.

Returns:

  • (Boolean)


5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
# File 'ext/p1788/p1788.cc', line 5660

static VALUE p1788_vector_overlap(VALUE self, VALUE y)
{
  const IntervalVector &v = p1788_vector_rb2ref(self);
  const size_t l = v.size();
  if (l == 0)
    return Qfalse;
  const IntervalVector &u = p1788_raise_if_not_vector_of_given_length(y, l);
  for (size_t i = 0; i < l; i++) {
    if (!(Interval::wid(Interval::intersection(v[i], u[i])) > 0.0))
      return Qfalse;
  }
  return Qtrue;
}

#perimeterFloat

Returns the sum of the width of all dimensions.

Returns +∞ if self is unbounded.

Returns:

  • (Float)


5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
# File 'ext/p1788/p1788.cc', line 5302

static VALUE p1788_vector_perimeter(VALUE self)
{
  IntervalVector &v = p1788_vector_rb2ref(self);
  const int l = v.size();
  if (l < 1)
    return DBL2NUM(0.0);
  double res = 0.0;
  for (int i = 0; i < l; i++) {
    if (Interval::is_common_interval(v[i]))
      res += Interval::wid(v[i]);
    else if (!Interval::is_empty(v[i]))
      return DBL2NUM(INF);
  }
  return DBL2NUM(res);
}

#pop(n = nil) ⇒ Interval, ...

Removes and returns trailing intervals. When no argument is given, removes and returns the last interval, or nil if the vector has no element.

When a non-negative Integer argument n is given, removes and return the last n intervals in a new P1788::IntervalVector. If n is more than the length of self, removes and returns all intervals.

Parameters:

  • n (Integer) (defaults to: nil)

    number of intervals to remove and return

Returns:



5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
# File 'ext/p1788/p1788.cc', line 5049

static VALUE p1788_vector_pop(int argc, VALUE *argv, VALUE self)
{
  IntervalVector &v = p1788_vector_rb2ref(self);
  int l = v.size();
  int rl;
  VALUE n, r;
  if (rb_scan_args(argc, argv, "01", &n)) {
    rl = NUM2INT(n);
    if (rl < 0)
      rl = 0;
    else if (rl > l)
      rl = l;
    r = p1788_vector_alloc(c_IntervalVector);
    IntervalVector &u = p1788_vector_rb2ref(r);
    u.resize(rl);
    for (int i = 0; i < rl; i++)
      u[i] = v[l+i-rl];
    v.resize(l-rl);
  }
  else {
    if (l > 0) {
      P1788_NEW_RB_INTERVAL(r, v[l-1]);
      v.resize(l-1);
    }
    else
      r = Qnil;
  }
  return r;
}

#pow(y) ⇒ IntervalVector

Power function

Returns:



6228
6229
6230
6231
6232
6233
# File 'ext/p1788/p1788.cc', line 6228

static VALUE p1788_vector_pow(VALUE self, VALUE y)
{
  if (rb_obj_is_kind_of(y, rb_cNumeric) && NUM2DBL(y) == 2.0)
    return p1788_vector_sqr(self);
  P1788_VECTOR_BINARY_OP(self, y, div);
}

#pown(n) ⇒ IntervalVector

Power with integer exponent

Parameters:

  • n (Integer)

    integer exponent

Returns:



6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
# File 'ext/p1788/p1788.cc', line 6272

static VALUE p1788_vector_pown(VALUE self, VALUE n)
{
  if (!RB_INTEGER_TYPE_P(n))
    rb_raise(rb_eTypeError, "expecting an integer as exponent, not a %" PRIsVALUE, rb_class_name(rb_class_of(n)));
  int p = NUM2INT(n);
  const IntervalVector &v = p1788_vector_rb2ref(self);
  const int l = v.size();
  IntervalVector *t = new IntervalVector(l);
  if (p == 2) {
    for (int i = 0; i < l; i++)
      (*t)[i] = Interval::sqr(v[i]);
  }
  else {
    for (int i = 0; i < l; i++)
      (*t)[i] = Interval::pown(v[i], p);
  }
  return p1788_vector_alloc_from_pointer(t);
}

#push(obj, ...) ⇒ self

Appends obj to self.

Parameters:

Returns:

  • (self)


5029
5030
5031
5032
5033
5034
# File 'ext/p1788/p1788.cc', line 5029

static VALUE p1788_vector_push(int argc, VALUE *argv, VALUE self)
{
  for (int i = 0; i < argc; i++)
    p1788_vector_pushpush(self, argv[i]);
  return self;
}

#radiiArray<Float, nil>

Returns an array conaining the radii of the elements in self. nil is returned for empty elements.

Returns:

  • (Array<Float, nil>)


5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
# File 'ext/p1788/p1788.cc', line 5420

static VALUE p1788_vector_radii(VALUE self)
{
  IntervalVector &v = p1788_vector_rb2ref(self);
  const size_t l = v.size();
  VALUE ar = rb_ary_new_capa(l);
  for (size_t i = 0; i < l; i++) {
    if (Interval::is_empty(v[i]))
      rb_ary_store(ar, i, Qnil);
    else
      rb_ary_store(ar, i, DBL2NUM(Interval::rad(v[i])));
  }
  return ar;
}

#recipIntervalVector

Reciprocal.

Returns:

See Also:



5887
5888
5889
# File 'ext/p1788/p1788.cc', line 5887

static VALUE p1788_vector_recip(VALUE self) {
  P1788_VECTOR_UNARIOP(self, recip);
}

#reject {|interval| ... } ⇒ IntervalVector #rejectEnumerator

Returns a new vector whose intervals are all those from self for which the block returns false or nil. Returns a new Enumerator if no block is given.

Overloads:

  • #reject {|interval| ... } ⇒ IntervalVector

    Returns a new vector.

    Yield Parameters:

    Yield Returns:

    • (Boolean)

      drop or not interval in the new vector ?

    Returns:

  • #rejectEnumerator

    Returns:

    • (Enumerator)

Returns:



4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
# File 'ext/p1788/p1788.cc', line 4723

static VALUE p1788_vector_reject(VALUE self)
{
  RETURN_SIZED_ENUMERATOR(self, 0, 0, p1788_vector_enum_length);
  IntervalVector &v = p1788_vector_rb2ref(self);
  VALUE r = p1788_vector_alloc(c_IntervalVector);
  IntervalVector &u = p1788_vector_rb2ref(r);
  const int l = v.size();
  for (int i = 0; i < l; i++) {
    VALUE y, b;
    P1788_NEW_RB_INTERVAL(y, v[i]);
    b = rb_yield(y);
    if (b == Qnil || b == Qfalse)
      u.push_back(v[i]);
  }
  return r;
}

#reject! {|interval| ... } ⇒ self #reject!Enumerator

Removes each interval from self for which the block returns a truthy value. Returns a new Enumerator if no block is given.

Overloads:

  • #reject! {|interval| ... } ⇒ self

    Yield Parameters:

    Yield Returns:

    • (Boolean)

      remove or not interval from self ?

    Returns:

    • (self)
  • #reject!Enumerator

    Returns:

    • (Enumerator)

Returns:

  • (self, Enumerator)


4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
# File 'ext/p1788/p1788.cc', line 4752

static VALUE p1788_vector_reject_bang(VALUE self)
{
  RETURN_SIZED_ENUMERATOR(self, 0, 0, p1788_vector_enum_length);
  IntervalVector &v = p1788_vector_rb2ref(self);
  VALUE r = p1788_vector_alloc(c_IntervalVector);
  IntervalVector &u = p1788_vector_rb2ref(r);
  const int l = v.size();
  for (int i = 0; i < l; i++) {
    VALUE y, b;
    P1788_NEW_RB_INTERVAL(y, v[i]);
    b = rb_yield(y);
    if (b == Qnil || b == Qfalse)
      u.push_back(v[i]);
  }
  v = std::move(u);
  return self;
}

#resize(new_length, default_value = Interval::ALL_REALS) ⇒ self

Resize self to new_length. If the vector is enlarged, new values will be filled with default_value.

Parameters:

  • new_length (Integer)

    new length as a positive integer

  • default_value (Interval) (defaults to: Interval::ALL_REALS)

Returns:

  • (self)


5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
# File 'ext/p1788/p1788.cc', line 5124

static VALUE p1788_vector_resize(int argc, VALUE *argv, VALUE self)
{
  VALUE newlen, dfltval;
  IntervalVector &v = p1788_vector_rb2ref(self);
  Interval dflt(-INF, INF);
  int new_size = 0;
  switch (rb_scan_args(argc, argv, "11", &newlen, &dfltval)) {
    case 2:
      dflt = p1788_rbobj2interval(dfltval);
    case 1:
      new_size = NUM2INT(newlen);
  }
  if (new_size < 0)
    new_size = 0;
  v.resize(new_size, dflt);
  return self;
}

#reverseIntervalVector

Returns a new vector with the intervals of self in reverse order.

Returns:



4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
# File 'ext/p1788/p1788.cc', line 4808

static VALUE p1788_vector_reverse(VALUE self)
{
  IntervalVector &v = p1788_vector_rb2ref(self);
  const int l = v.size();
  VALUE r = p1788_vector_alloc(c_IntervalVector);
  IntervalVector &u = p1788_vector_rb2ref(r);
  u.resize(l);
  int i, j;
  for (i = 0, j = l-1; i < l; i++, j--)
    u[j] = v[i];
  return r;
}

#reverse!self

Reverses self in place.

Returns:

  • (self)


4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
# File 'ext/p1788/p1788.cc', line 4825

static VALUE p1788_vector_reverse_bang(VALUE self)
{
  IntervalVector &v = p1788_vector_rb2ref(self);
  const int l = v.size();
  IntervalVector u = IntervalVector(l);
  int i, j;
  for (i = 0, j = l-1; i < l; i++, j--)
    u[j] = v[i];
  v = std::move(u);
  return self;
}

#round_ties_to_awayIntervalVector

Round bounds, ties halfway cases away from zero



6110
6111
6112
# File 'ext/p1788/p1788.cc', line 6110

static VALUE p1788_vector_round_ties_to_away(VALUE self) {
  P1788_VECTOR_UNARIOP(self, round_ties_to_away);
}

#round_ties_to_evenIntervalVector

Round bounds, ties halfway cases to even



6102
6103
6104
# File 'ext/p1788/p1788.cc', line 6102

static VALUE p1788_vector_round_ties_to_even(VALUE self) {
  P1788_VECTOR_UNARIOP(self, round_ties_to_even);
}

#select {|interval| ... } ⇒ IntervalVector #selectEnumerator

Calls the block, if given, with each interval of self; returns a new vector containing those intervals of self for which the block returns a truthy value. Returns a new Enumerator if no block is given.

Overloads:

  • #select {|interval| ... } ⇒ IntervalVector

    Returns a new vector.

    Yield Parameters:

    Yield Returns:

    • (Boolean)

      keep or not interval in the new vector ?

    Returns:

  • #selectEnumerator

    Returns:

    • (Enumerator)

Returns:



4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
# File 'ext/p1788/p1788.cc', line 4663

static VALUE p1788_vector_select(VALUE self)
{
  RETURN_SIZED_ENUMERATOR(self, 0, 0, p1788_vector_enum_length);
  IntervalVector &v = p1788_vector_rb2ref(self);
  VALUE r = p1788_vector_alloc(c_IntervalVector);
  IntervalVector &u = p1788_vector_rb2ref(r);
  const int l = v.size();
  for (int i = 0; i < l; i++) {
    VALUE y, b;
    P1788_NEW_RB_INTERVAL(y, v[i]);
    b = rb_yield(y);
    if (b != Qnil && b != Qfalse)
      u.push_back(v[i]);
  }
  return r;
}

#select! {|interval| ... } ⇒ self #select!Enumerator

Calls the block, if given, with each interval of self; removes from self those intervals for which the block returns false or nil. Returns a new Enumerator if no block is given.

Overloads:

  • #select! {|interval| ... } ⇒ self

    Yield Parameters:

    Yield Returns:

    • (Boolean)

      keep or not interval in self ?

    Returns:

    • (self)
  • #select!Enumerator

    Returns:

    • (Enumerator)

Returns:

  • (self, Enumerator)


4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
# File 'ext/p1788/p1788.cc', line 4693

static VALUE p1788_vector_select_bang(VALUE self)
{
  RETURN_SIZED_ENUMERATOR(self, 0, 0, p1788_vector_enum_length);
  IntervalVector &v = p1788_vector_rb2ref(self);
  VALUE r = p1788_vector_alloc(c_IntervalVector);
  IntervalVector &u = p1788_vector_rb2ref(r);
  const int l = v.size();
  for (int i = 0; i < l; i++) {
    VALUE y, b;
    P1788_NEW_RB_INTERVAL(y, v[i]);
    b = rb_yield(y);
    if (b != Qnil && b != Qfalse)
      u.push_back(v[i]);
  }
  v = std::move(u);
  return self;
}

#signIntervalVector

Sign

Returns:

See Also:



6056
6057
6058
# File 'ext/p1788/p1788.cc', line 6056

static VALUE p1788_vector_sign(VALUE self) {
  P1788_VECTOR_UNARIOP(self, sign);
}

#sinIntervalVector

Sine

Returns:

See Also:



5960
5961
5962
# File 'ext/p1788/p1788.cc', line 5960

static VALUE p1788_vector_sin(VALUE self) {
  P1788_VECTOR_UNARIOP(self, sin);
}

#sinhIntervalVector

Hyperbolic sine

Returns:

See Also:



6008
6009
6010
# File 'ext/p1788/p1788.cc', line 6008

static VALUE p1788_vector_sinh(VALUE self) {
  P1788_VECTOR_UNARIOP(self, sinh);
}

#sqrIntervalVector

Square.

Returns:

See Also:



5895
5896
5897
# File 'ext/p1788/p1788.cc', line 5895

static VALUE p1788_vector_sqr(VALUE self) {
  P1788_VECTOR_UNARIOP(self, sqr);
}

#sqrtIntervalVector

Square root.

Returns:

See Also:



5903
5904
5905
# File 'ext/p1788/p1788.cc', line 5903

static VALUE p1788_vector_sqrt(VALUE self) {
  P1788_VECTOR_UNARIOP(self, sqrt);
}

#strict_subset_of?(y) ⇒ Boolean

[𝒔𝒆𝒍𝒇] ⊂ [𝒚] ∧ [𝒔𝒆𝒍𝒇] ≠ [𝒚]

[𝒔𝒆𝒍𝒇] ≠ [𝒚] ∧ ∀ 𝑖 ∈ (0, ..., 𝑛-1), [𝒔𝒆𝒍𝒇]i ⊆ [𝒚]i

true if y is different from self and for each index i, self[i] ⊆ y[i]. y and self must have the same length ; returns true if length is zero.

Returns:

  • (Boolean)


5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
# File 'ext/p1788/p1788.cc', line 5706

static VALUE p1788_vector_strict_subset(VALUE self, VALUE y)
{
  const IntervalVector &v = p1788_vector_rb2ref(self);
  const size_t l = v.size();
  if (l == 0)
    return Qtrue;
  const IntervalVector &u = p1788_raise_if_not_vector_of_given_length(y, l);
  bool both_are_equal = true;
  for (size_t i = 0; i < l; i++) {
    if (!(Interval::subset(v[i], u[i])))
      return Qfalse;
    if (!Interval::equal(v[i], u[i]))
      both_are_equal = false;
  }
  return both_are_equal ? Qfalse : Qtrue;
}

#strict_superset_of?(y) ⇒ Boolean

[𝒔𝒆𝒍𝒇] ⊃ [𝒚] ∧ [𝒔𝒆𝒍𝒇] ≠ [𝒚]

[𝒔𝒆𝒍𝒇] ≠ [𝒚] ∧ ∀ 𝑖 ∈ (0, ..., 𝑛-1), [𝒔𝒆𝒍𝒇]i ⊇ [𝒚]i

true if y is different from self and for each index i, self[i] ⊆ y[i]. y and self must have the same length ; returns true if length is zero.

Returns:

  • (Boolean)


5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
# File 'ext/p1788/p1788.cc', line 5755

static VALUE p1788_vector_strict_superset(VALUE self, VALUE y)
{
  const IntervalVector &v = p1788_vector_rb2ref(self);
  const size_t l = v.size();
  if (l == 0)
    return Qtrue;
  const IntervalVector &u = p1788_raise_if_not_vector_of_given_length(y, l);
  bool both_are_equal = true;
  for (size_t i = 0; i < l; i++) {
    if (!(Interval::superset(v[i], u[i])))
      return Qfalse;
    if (!Interval::equal(v[i], u[i]))
      both_are_equal = false;
  }
  return both_are_equal ? Qfalse : Qtrue;
}

#subset_of?(y) ⇒ Boolean

[𝒔𝒆𝒍𝒇] ⊆ [𝒚]

∀ 𝑖 ∈ (0, ..., 𝑛-1), ∀ đ‘„ ∈ [𝒔𝒆𝒍𝒇]i, ∃ 𝑩 ∈ [𝒚]i : đ‘„ = 𝑩

true if for each index i, self[i] ⊆ y[i]. y and self must have the same length ; returns true if length is zero.

Returns:

  • (Boolean)


5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
# File 'ext/p1788/p1788.cc', line 5683

static VALUE p1788_vector_subset(VALUE self, VALUE y)
{
  const IntervalVector &v = p1788_vector_rb2ref(self);
  const size_t l = v.size();
  if (l == 0)
    return Qtrue;
  const IntervalVector &u = p1788_raise_if_not_vector_of_given_length(y, l);
  for (size_t i = 0; i < l; i++) {
    if (!(Interval::subset(v[i], u[i])))
      return Qfalse;
  }
  return Qtrue;
}

#superset_of?(y) ⇒ Boolean Also known as: contain?

[𝒔𝒆𝒍𝒇] ⊇ [𝒚]

∀ 𝑖 ∈ (0, ..., 𝑛-1), ∀ 𝑩 ∈ [𝒚]i, ∃ đ‘„ ∈ [𝒔𝒆𝒍𝒇]i : 𝑩 = đ‘„

true if for each index i, self[i] ⊇ y[i]. y and self must have the same length ; returns true if length is zero.

Returns:

  • (Boolean)


5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
# File 'ext/p1788/p1788.cc', line 5732

static VALUE p1788_vector_superset(VALUE self, VALUE y)
{
  const IntervalVector &v = p1788_vector_rb2ref(self);
  const size_t l = v.size();
  if (l == 0)
    return Qtrue;
  const IntervalVector &u = p1788_raise_if_not_vector_of_given_length(y, l);
  for (size_t i = 0; i < l; i++) {
    if (!(Interval::superset(v[i], u[i])))
      return Qfalse;
  }
  return Qtrue;
}

#tanIntervalVector

Tangent

Returns:

See Also:



5976
5977
5978
# File 'ext/p1788/p1788.cc', line 5976

static VALUE p1788_vector_tan(VALUE self) {
  P1788_VECTOR_UNARIOP(self, tan);
}

#tanhIntervalVector

Hyperbolic tangent

Returns:

See Also:



6024
6025
6026
# File 'ext/p1788/p1788.cc', line 6024

static VALUE p1788_vector_tanh(VALUE self) {
  P1788_VECTOR_UNARIOP(self, tanh);
}

#to_aArray<Interval>

Returns:



4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
# File 'ext/p1788/p1788.cc', line 4149

static VALUE p1788_vector_to_a(VALUE self)
{
  const IntervalVector &v = p1788_vector_rb2ref(self);
  int l = v.size();
  VALUE r = rb_ary_new_capa(l);
  VALUE e;
  for (int i = 0; i < l; i++) {
    P1788_NEW_RB_INTERVAL(e, v[i]);
    rb_ary_store(r, i, e);
  }
  return r;
}

#to_latex(print_dollars = true) ⇒ String

Returns a LaTex representation as a string.

Parameters:

  • print_dollars (Boolean) (defaults to: true)

    if true, will surround the string with $$ signs.

Returns:

  • (String)


4136
4137
4138
4139
4140
4141
4142
4143
4144
# File 'ext/p1788/p1788.cc', line 4136

static VALUE p1788_vector_to_latex(int argc, VALUE *argv, VALUE self)
{
  VALUE arg;
  if (rb_scan_args(argc, argv, "01", &arg) > 0) {
    if (arg == Qnil || arg == Qfalse)
      return p1788_vector_to_tex(self);
  }
  return rb_sprintf("$$ %" PRIsVALUE " $$", p1788_vector_to_tex(self));
}

#to_sString

Returns:

  • (String)


4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
# File 'ext/p1788/p1788.cc', line 4101

static VALUE p1788_vector_to_s(VALUE self)
{
  const IntervalVector &v = p1788_vector_rb2ref(self);
  std::string r("[");
  const std::string jn(", ");
  int l = v.size();
  if (l > 0)
    r += p1788_interval_to_cppstring(v[0]);
  for (int i = 1; i < l && i; i++)
    r += jn + p1788_interval_to_cppstring(v[i]);
  r += "]";
  return rb_str_new(r.c_str(), r.length());
}

#truncIntervalVector

Round bounds towards 0

Returns:

See Also:

  • P1788#trunc


6094
6095
6096
# File 'ext/p1788/p1788.cc', line 6094

static VALUE p1788_vector_trunc(VALUE self) {
  P1788_VECTOR_UNARIOP(self, trunc);
}

#unbounded?Boolean

One of the bounds of self is infinite and self is nonempty (none of its elements is empty).

Returns:

  • (Boolean)


5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
# File 'ext/p1788/p1788.cc', line 5219

static VALUE p1788_vector_is_unbounded(VALUE self)
{
  IntervalVector &v = p1788_vector_rb2ref(self);
  const int l = v.size();
  if (l < 1)
    return Qfalse;
  VALUE one_element_is_unbounded = Qfalse;
  for (int i = 0; i < l; i++) {
    if (Interval::is_empty(v[i]))
      return Qfalse;
    if (!Interval::is_common_interval(v[i]))
      one_element_is_unbounded = Qtrue;
  }
  return one_element_is_unbounded;
}

#upper_boundsArray<Float, nil>

Returns an array conaining the upper bounds of the elements in self. nil is returned for empty elements.

Returns:

  • (Array<Float, nil>)


5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
# File 'ext/p1788/p1788.cc', line 5382

static VALUE p1788_vector_upper_bounds(VALUE self)
{
  IntervalVector &v = p1788_vector_rb2ref(self);
  const size_t l = v.size();
  VALUE ar = rb_ary_new_capa(l);
  for (size_t i = 0; i < l; i++) {
    if (Interval::is_empty(v[i]))
      rb_ary_store(ar, i, Qnil);
    else
      rb_ary_store(ar, i, DBL2NUM(Interval::sup(v[i])));
  }
  return ar;
}

#volumeFloat

Returns the product of the width of all dimensions.

  • Returns +∞ if self is unbounded and not flat.
  • Returns 0 if self is flat and not unbounded
  • Returns Float::NAN if self is unbounded and flat

Returns:

  • (Float)

See Also:



5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
# File 'ext/p1788/p1788.cc', line 5280

static VALUE p1788_vector_volume(VALUE self)
{
  IntervalVector &v = p1788_vector_rb2ref(self);
  const int l = v.size();
  if (l < 1)
    return DBL2NUM(0.0);
  double res = 1.0;
  for (int i = 0; i < l; i++) {
    if (Interval::is_empty(v[i]))
      res *= 0.0;
    else
      res *= Interval::wid(v[i]);
  }
  return DBL2NUM(res);
}

#widthsArray<Float, nil>

Returns an array conaining the widths of the elements in self. nil is returned for empty elements.

Returns:

  • (Array<Float, nil>)


5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
# File 'ext/p1788/p1788.cc', line 5401

static VALUE p1788_vector_widths(VALUE self)
{
  IntervalVector &v = p1788_vector_rb2ref(self);
  const size_t l = v.size();
  VALUE ar = rb_ary_new_capa(l);
  for (size_t i = 0; i < l; i++) {
    if (Interval::is_empty(v[i]))
      rb_ary_store(ar, i, Qnil);
    else
      rb_ary_store(ar, i, DBL2NUM(Interval::wid(v[i])));
  }
  return ar;
}

#|(y) ⇒ IntervalVector

Convex hull of interval vector union.

Returns:



6188
6189
6190
6191
# File 'ext/p1788/p1788.cc', line 6188

static VALUE p1788_vector_union(VALUE self, VALUE y)
{
  P1788_VECTOR_BINARY_OP(self, y, convex_hull);
}