Class Dobjects::Dvector
In: split/Dvector/dvector.c
split/Dvector/lib/Dvector_extras.rb
Parent: Object

Dvectors are a specialized implementation of one-dimensional arrays of double precision floating point numbers. They are intended for use in applications needing efficient processing of large vectors of numeric data. Essentially any of the operations you might do with a 1D Ruby Array of numbers can also be done with a Dvector. Just like Arrays, Dvector indexing starts at 0. A negative index is assumed to be relative to the end of the vector—that is, an index of -1 indicates the last element of the vector, -2 is the next to last element in the vector, and so on. Element reference and element assignment are the same as for Arrays, allowing for (start,length) or (range) as well as for simple indexing. All of the other Array operations that make sense for a 1D array of numbers are also provided for Dvectors. For example, you can "fetch" or "fill" with Dvectors, but there is no "assoc" or "compact" for them since one looks for arrays as elements and the other looks for nil elements, neither of which are found in Dvectors.

In addition to the usual Array methods, there are a variety of others that operate on the contents of the entire vector without the use of explicit iterators. These routines are crucial for efficient processing of large vectors. For example, "vec.sqrt" will create a vector of square roots of entries in vec more efficiently than the semantically equivalent form "vec.collect { |x| sqrt(x) }".

All of the numeric methods also have ‘bang’ versions that modify the contents of the vector in place; for example, "vec.sqrt!" is more efficient than "vec = vec.sqrt". By providing implicit iterators and in-place modification, Dvectors make it possible to operate on large vectors of doubles in Ruby at speeds closely approaching a C implementation.

As a final example, for diehards only, say we have large vectors holding values of abundances of total helium (xhe), singly ionized helium (xhe1), and doubly ionized helium (xhe2). We‘re missing the values for neutral helium, but that is just what‘s left of total helium after you subtract the two ionized forms, so it is easy to compute it. Finally, we need to calculate the log of the abundance of neutral helium and store it in another vector (log_xhe0). If we don‘t care about creating work for the garbage collector, we can simply do this

         log_xhe0 = (xhe - xhe1 - xhe2).log10

This works, but it creates multiple temporary vectors for intermediate results. If, like me, you‘re compulsive about efficiency, you can do the whole thing with no garbage created at all:

         log_xhe0 = Dvector.new
         log_xhe0.replace(xhe).sub!(xhe1).sub!(xhe2).log10!

This copies xhe to log_xhe0, subtracts xhe1 and xhe2 from log_xhe0 in place, and then takes the log, also in place. It‘s not pretty, but it is efficient — use if needed.

Please report problems with the Dvector extension here. [Note: for N-dimensional arrays or arrays of complex numbers or integers as well as doubles, along with a variety of matrix operations, check out the NArray extension.]

Dvector now also prides itselfs with a _dump and a _load function, which means you can Marshal them.

Methods

%   *   **   +   -   -@   /   <<   <=>   ==   []   []   []=   _dump   _load   abs   abs!   acos   acos!   acosh   acosh!   add   add!   as_exponent_of   as_exponent_of!   asin   asin!   asinh   asinh!   at   atan   atan!   atan2   atan2!   atanh   atanh!   bounds   ceil   ceil!   clean?   clear   collect   collect!   collect2   collect2!   compute_formula   concat   convolve   cos   cos!   cosh   cosh!   create_spline_interpolant   delete   delete_at   delete_if   dirty   dirty=   dirty?   div   div!   dot   dup   each   each2   each2_with_index   each_index   each_with_index   empty?   eql?   exp   exp!   exp10   exp10!   fancy_read   fast_fancy_read   fetch   fill   first   floor   floor!   freeze   from_na   frozen?   include?   index   initialize_copy   insert   inspect   inv   inv!   is_a_dvector   join   last   length   linear_interpolate   log   log!   log10   log10!   make_bezier_control_points_for_cubic_in_x   map   map!   map2   map2!   max   max_lt   max_of_many   min   min_gt   min_of_many   minus   minus!   mod   mod!   modulo   modulo!   mul   mul!   neg   neg!   new   nitems   old_fancy_read   plus   plus!   pop   pow   pow!   prune   prune!   push   raised_to   raised_to!   read   read_columns   read_row   read_rows   reject   reject!   remainder   remainder!   replace   resize   reverse   reverse!   reverse_each   reverse_each2   reverse_each2_with_index   reverse_each_index   reverse_each_with_index   rindex   round   round!   safe_acos   safe_acos!   safe_asin   safe_asin!   safe_inv   safe_inv!   safe_log   safe_log!   safe_log10   safe_log10!   safe_sqrt   safe_sqrt!   select   set   shift   sin   sin!   sinh   sinh!   size   slice   slice!   sort   sort!   spline_interpolate   sqrt   sqrt!   sub   sub!   sum   tan   tan!   tanh   tanh!   times   times!   to_a   to_ary   to_dvector   to_na   to_s   tridag   trim   trim!   uniq   uniq!   unshift   values_at   vector_length   where_closest   where_eq   where_first_closest   where_first_eq   where_first_ge   where_first_gt   where_first_le   where_first_lt   where_first_max   where_first_min   where_first_ne   where_ge   where_gt   where_last_closest   where_last_eq   where_last_ge   where_last_gt   where_last_le   where_last_lt   where_last_max   where_last_min   where_last_ne   where_le   where_lt   where_max   where_min   where_ne   write  

Included Modules

Enumerable

Constants

FANCY_READ_DEFAULTS = { 'sep' => /\s+/, 'comments' => /^\s*\#/, 'skip_first' => 0, 'index_col' => false, 'headers' => nil, # not used for now. 'default' => 0.0/0.0, # defaults to NaN 'remove_space' => true ,# removes spaces at the beginning of the lines }   Dvector.fancy_read‘s defaults options. See that function for more details
WRITE_DEFAULTS = { 'sep' => "\t", 'write_mode' => "a", }

Public Class methods

Returns a new Dvector populated with the given objects.

  Dvector.[]( 1, 2, 3, 4 )      -> a_dvector
  Dvector[ 1, 2, 3, 4 ]         -> a_dvector

Called by the marshalling mechanism to retrieve a permanent copy of a Dvector.

This function is a rudimentary formula computing stuff. Give it a text formula and an array of Dvectors (a), and it returns a Dvector with the result. The formula should contain the following;

column[n]:represents the current element of the n th Dvector of the array

This is just a try, and should be implemented in C rather than in Ruby. But if you‘re looking for simplicity, here you go ;-) !

modules are the modules you would wish the evaluator to include. This feature enables one to make sure custom functions are included

Uses Dvectors xs and ys to create a cubic spline interpolant. The xs must be given in ascending order. There is a boundary condition choice to be made for each end concerning the slope. If clamped is true, the correspdoning slope argument value sets the slope. If clamped is false (known as a "free" or "natural" spline), the 2nd derivative is set to 0 and the slope is determined by the fit. In this case, the corresponding slope argument is ignored. The interpolant is an array of Dvectors: [Xs, Ys, As, Bs, Cs]. For x between Xs[j] and Xs[j+1], let dx = x - Xs[j], and find interpolated y for x by y = As[j]*dx^3 + Bs[j]*dx^2 + Cs[j]*dx + Ys[j]. (Spline algorithms derived from Burden & Faires, Numerical Analysis, 4th edition, pp 131 and following.)

This function is a wrapper for fast_fancy_read that reflects the look-and-feel of old_fancy_read

: Reads data from an IO stream (or anything that supports a gets method) and separate it into columns of data according to the options, a hash holding the following elements (compulsory, but you can use FANCY_READ_DEFAULTS):

  'sep': a regular expression that separate the entries
  'comments': any line matching this will be skipped
  'skip_first': skips that many lines before reading anything
  'index_col': if true, the first column returned contains the
  number of the line read
  'remove_space': whether to remove spaces at the beginning of a line. *This
  option is currently not implemented !*
  'default':  what to put when nothing was found but a number must be used

As a side note, the read time is highly non-linear, which suggests that the read is memory-allocation/copying-limited, at least for big files.

An internal memory allocation with aggressive policy should solve that, that is, not using directly Dvectors (and it would be way faster to store anyway).

thanks to Dave MacMahon for from_na and to_na Create a Dvector from an NArray.

Checks if the given object is a Dvector. Mainly here for testing purposes, as it corresponds to the internal is_a_dvector.

Returns the y corresponding to x by linear interpolation using the Dvectors xs and ys.

Returns the maximum value held in the array of Dvectors (or nil if ary is empty). Any nil entries in ary are ignored.

Returns the minimum value held in the array of Dvectors (or nil if ary is empty). Any nil entries in ary are ignored.

Returns a new Dvector. In the first form, the new vector is empty. In the second it is created with size copies of value The third form creates a copy of the other vector passed as a parameter (this can also be an Array). In the last form, a vector of the given size is created. Each element in this vector is calculated by passing the element‘s index to the given block and storing the return value.

   Dvector.new                       -> Dvector[]
   Dvector.new(2)                    -> Dvector[ 0, 0 ]
   Dvector.new(3, -1)                -> Dvector[ -1, -1, -1 ]
   Dvector.new(3) {|i| i**2 + 1}     -> Dvector[ 1, 2, 5 ]

This function reads in stream (can an IO object or a String, in which case it represents the name of a file to be opened) the columns specified by cols and returns them. column 0 is the first column. If cols is nil, then fancy_read attempts to find all the columns in the file, while filling absent data with NaN.

opts is a hash for tuning the behavior of the reading. It can hold the following keys:

‘sep’:the record separator
‘comments’:a regular expression matching comment lines
‘skip_first’:how many lines to skip at the beginning of the file,
‘default’:the value taken for missing elements
‘index_col’:if set to true, the first column contains the indices of the elements (starting from 0 for first and so on)

The data on the file should be organized in columns of numbers, with one row per line. The start parameter determines the starting line and defaults to 1 meaning start at the first line of the file. The length parameter determines the number of lines to be read and defaults to -1 meaning read to the end of the file. Each column of data is stored in a Dvector. If the dest argument is nil, the result array holds the newly created vectors with the leftmost column in array entry 0, the second column in entry 1, and so on. If dest is not nil, it must be an array with entries either Dvectors or nil. For entries that are Dvectors, the contents of the vector are replaced by the column of data from the file. If the entry is nil, that column of the file is skipped.

The data on the file should be organized in columns of numbers, with one row per line. The start parameter determines the starting line and defaults to 1 meaning start at the first line of the file. The length parameter determines the number of lines to be read and defaults to -1 meaning read to the end of the file. Each column of data is stored in a Dvector. If the dest argument is nil, the result array holds the newly created vectors with the leftmost column in array entry 0, the second column in entry 1, and so on. If dest is not nil, it must be an array with entries either Dvectors or nil. For entries that are Dvectors, the contents of the vector are replaced by the column of data from the file. If the entry is nil, that column of the file is skipped.

This routine reads a row of numbers from the named file. The row argument determines which line of the file to read, starting at 1 for the first line. If the dvector argument is nil, a new Dvector is allocated to hold the row of numbers. Otherwise, the contents of dvector are replaced by the numbers from the line in the file.

The data on the file should be organized in rows of numbers, with one row per line. The rows need not all have the same number of entries since each row is placed in its own Dvector. The start parameter determines the starting line and defaults to 1 meaning start at the first line of the file. The dest must be an array with entries either Dvectors or nil. For entries that are Dvectors, the contents of the vector are replaced by the row of data from the file. The start row is placed in the first entry in dest, the second row in the next, and so on. If the entry in dest is nil, that row of the file is skipped.

Returns the y corresponding to x by spline interpolation using the interpolant which was previously created by calling create_spline_interpolant.

Writes an array of Dvectors into a text file

Public Instance methods

%(p1)

Alias for modulo

*(p1)

Alias for mul

**(p1)

Alias for pow

+(p1)

Alias for add

-(p1)

Alias for sub

-@()

Alias for neg

/(p1)

Alias for div

Append—Pushes the given number on to the end of this vector. This expression returns the vector itself, so several appends may be chained together.

   Dvector[ 1, 2 ] << -3.3 << 1e3    ->  Dvector[ 1, 2, 3.3, 1000.0 ]

Comparison—Returns an integer (-1, 0, or +1) if this vector is less than, equal to, or greater than other. Two vectors are ``equal’’ according to Dvector#<=> if and only if they have the same length and contain exactly the same values.

   Dvector[ 1, 1, 2 ] <=> Dvector[ 1, 2, 3 ]        -> -1
   Dvector[ 1, 1, 2 ] <=> Dvector[ 1, 0, 3 ]        -> +1
   Dvector[ 1, 1, 2 ] <=> Dvector[ 1, 1, 2, 3 ]     -> -1
   Dvector[ 1, 2, 3, 4, 5, 6 ] <=> Dvector[ 1, 2 ]  -> +1
==(p1)

Alias for eql?

Element Reference—Returns the element at index int, or returns a subvector starting at start and continuing for length elements, or returns a subvector specified by range. Negative indices count backward from the end of the vector (-1 is the last element). Returns nil if the index (or starting index) are out of range. If the start index equals the vector size and a length or range parameter is given, an empty vector is returned.

   a = Dvector[ 1, 2, 3, 4, 5 ]
   a[2] + a[0] + a[1]     -> 6
   a[6]                   -> nil
   a[1, 2]                -> Dvector[ 2, 3 ]
   a[1..3]                -> Dvector[ 2, 3, 4 ]
   a[4..7]                -> Dvector[ 5 ]
   a[6..10]               -> nil
   a[-3, 3]               -> Dvector[ 3, 4, 5 ]
   # special cases
   a[5]                   -> nil
   a[5, 1]                -> Dvector[]
   a[5..10]               -> Dvector[]

Element Assignment—Sets the element at index int, or replaces a subvector starting at start and continuing for length elements, or replaces a subvector specified by range. Returns the assigned object as value. If indices are greater than the current capacity of the vector, the vector grows automatically by adding zeros. Negative indices will count backward from the end of the vector. Inserts elements if length is zero. If nil is used in the second and third forms, deletes elements from dvector. A 1D Array of numbers can be used on the right in the second and third forms in place of a Dvector. An IndexError is raised if a negative index points past the beginning of the vector. See also Dvector#push, and Dvector#unshift.

   a = Dvector.new
   a[4] = 4;                      -> Dvector[ 0, 0, 0, 0, 4 ]
   a[0, 3] = [ 1, 2, 3 ]          -> Dvector[ 1, 2, 3, 0, 4 ]
   a[1..2] = [ 1, 2 ]             -> Dvector[ 1, 1, 2, 0, 4 ]
   a[0, 2] = -1                   -> Dvector[ -1, 2, 0, 4 ]
   a[0..2] = 1                    -> Dvector[ 1, 4 ]
   a[-1]   = 5                    -> Dvector[ 1, 5 ]
   a[1..-1] = nil                 -> Dvector[ 1 ]

Called by the marshalling mechanism to store a permanent copy of a Dvector. limit is simply ignored.

Returns of copy of dvector with all entries replaced by their absolute values.

   a = Dvector[ 1, -2, -3, 4 ]
   a.abs   -> Dvector[ 1, 2, 3, 4 ]

Replace each entry x of dvector with abs(x).

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.abs!   -> Dvector[ 1.1, 2.2, 5.3 ]
   a        -> Dvector[ 1.1, 2.2, 5.3 ]

Returns of copy of dvector with entry x replaced by acos(x).

   a = Dvector[ 0.1, -0.2, -0.3, 0.4 ]
   a.acos   -> Dvector[ acos(0.1), acos(-0.2), acos(-0.3), acos(0.4) ]

Replace each entry x of dvector with acos(x).

   a = Dvector[ 0.1, -0.2, 0.3 ]
   a.acos!   -> Dvector[ acos(0.1), acos(-0.2), acos(0.3) ]
   a         -> Dvector[ acos(0.1), acos(-0.2), acos(0.3) ]

Returns of copy of dvector with entry x replaced by acosh(x).

   a = Dvector[ 5.1, 2.2, 1.3 ]
   a.acosh   -> Dvector[ acosh(5.1), acosh(2.2), acosh(1.3) ]

Replace each entry x of dvector with acosh(x).

   a = Dvector[ 1.1, 2.2, 5.3 ]
   a.acosh!   -> Dvector[ acosh(1.1), acosh(2.2), acosh(5.3) ]
   a          -> Dvector[ acosh(1.1), acosh(2.2), acosh(5.3) ]

When argument is a number, this operation returns a copy of dvector with each entry x replaced by x + number. When argument is a vector, this operation returns a copy of dvector with each entry x replaced by x + the corresponding entry in the other vector.

   a = Dvector[ 11, -5, 2 ]
   a.add(3)              -> Dvector[ 14, -2, 5 ]
   a + 3                 -> Dvector[ 14, -2, 5 ]
   3 + a                 -> Dvector[ 14, -2, 5 ]
   b = Dvector[ 7, 4, -10 ]
   a.add(b)              -> Dvector[ 18, -1, -8 ]
   a + b                 -> Dvector[ 18, -1, -8 ]

When argument is a number, each entry x in dvector is replaced by x + number. When argument is a vector, each entry x in dvector is replaced by x + the corresponding entry in the other vector.

   a = Dvector[ 11, -5, 2 ]
   a.add!(3)              -> Dvector[ 14, -2, 5 ]
   a                      -> Dvector[ 14, -2, 5 ]
   a = Dvector[ 11, -5, 2 ]
   b = Dvector[ 7, 4, -10 ]
   a.add!(b)              -> Dvector[ 18, -1, -8 ]
   a                      -> Dvector[ 18, -1, -8 ]

When argument is a number, this operation returns a copy of dvector with each entry x replaced by number ** x. When argument is a vector, this operation returns a copy of dvector with each entry x replaced by the corresponding entry in the other vector raised to the power x.

   a = Dvector[ 2, -5, 12 ]
   a.as_exponent_of(3.8)              -> Dvector[ 3.8 ** 2, 3.8 ** (-5), 3.8 ** 12 ]
   b = Dvector[ 7.1, 4.9, -10 ]
   a.as_exponent_of(b)                -> Dvector[ 7.1 ** 2, 4.9 ** (-5), (-10) ** 12 ]

When argument is a number, this operation replaces each entry x of dvector by number ** x. When argument is a vector, this operation replaces each entry x of dvector by the corresponding entry in the other vector raised to the power x.

   a = Dvector[ 2, -5, 12 ]
   a.as_exponent_of!(3.8)              -> Dvector[ 3.8 ** 2, 3.8 ** (-5), 3.8 ** 12 ]
   a                                   -> Dvector[ 3.8 ** 2, 3.8 ** (-5), 3.8 ** 12 ]
   b = Dvector[ 7.1, 4.9, -10 ]
   a.as_exponent_of!(b)                -> Dvector[ 7.1 ** 2, 4.9 ** (-5), (-10) ** 12 ]
   a                                   -> Dvector[ 7.1 ** 2, 4.9 ** (-5), (-10) ** 12 ]

Returns of copy of dvector with entry x replaced by asin(x).

   a = Dvector[ 0.1, -0.2, -0.3, 0.4 ]
   a.asin   -> Dvector[ asin(0.1), asin(-0.2), asin(-0.3), asin(0.4) ]

Replace each entry x of dvector with asin(x).

   a = Dvector[ 0.1, -0.2, 0.3 ]
   a.asin!   -> Dvector[ asin(0.1), asin(-0.2), asin(0.3) ]
   a         -> Dvector[ asin(0.1), asin(-0.2), asin(0.3) ]

Returns of copy of dvector with entry x replaced by asinh(x).

   a = Dvector[ 0.1, -0.2, 0.3 ]
   a.asinh   -> Dvector[ asinh(0.1), asinh(-0.2), asinh(0.3) ]

Replace each entry x of dvector with asinh(x).

   a = Dvector[ 1.1, 2.2, 5.3 ]
   a.asinh!   -> Dvector[ asinh(1.1), asinh(2.2), asinh(5.3) ]
   a          -> Dvector[ asinh(1.1), asinh(2.2), asinh(5.3) ]

Returns the element at index int. A negative index counts from the end of dvector. Returns nil if the index is out of range.

   a = Dvector[ 1, 2, 3, 4, 5 ]
   a.at(0)     -> 1
   a.at(-1)    -> 5

Returns of copy of dvector with entry x replaced by atan(x).

   a = Dvector[ 0.1, -0.2, -0.3, 0.4 ]
   a.atan   -> Dvector[ atan(0.1), atan(-0.2), atan(-0.3), atan(0.4) ]

Replace each entry x of dvector with atan(x).

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.atan!   -> Dvector[ atan(1.1), atan(-2.2), atan(5.3) ]
   a         -> Dvector[ atan(1.1), atan(-2.2), atan(5.3) ]

When argument is a number, this operation returns a copy of dvector with each entry x replaced by the angle whose tangent is x/number. When argument is a vector, this operation returns a copy of dvector with each entry x replaced by the angle whose tangent is x divided by the corresponding entry in the other vector.

   a = Dvector[ 1.1, -5.7, 12.7 ]
   a.atan2(3.8)              -> Dvector[ atan2(1.1, 3.8), atan2(-5.7,3.8), atan2(12.7,3.8) ]
   b = Dvector[ 7.1, 4.9, -10.1 ]
   a.atan2(b)                -> Dvector[ atan2(1.1,7.1), atan2(-5.7,4.9), atan2(12.7,-10.1) ]

When argument is a number, this operation replaces each entry x of dvector by the angle whose tangent is x/number. When argument is a vector, this operation replaces each entry x of dvector by the angle whose tangent is x divided by the corresponding entry in the other vector.

   a = Dvector[ 1.1, -5.7, 12.7 ]
   a.atan2!(3.8)              -> Dvector[ atan2(1.1, 3.8), atan2(-5.7,3.8), atan2(12.7,3.8) ]
   a = Dvector[ 1.1, -5.7, 12.7 ]
   b = Dvector[ 7.1, 4.9, -10.1 ]
   a.atan2!(b)                -> Dvector[ atan2(1.1,7.1), atan2(-5.7,4.9), atan2(12.7,-10.1) ]

Returns of copy of dvector with entry x replaced by atanh(x).

   a = Dvector[ 0.1, -0.2, 0.3 ]
   a.atanh   -> Dvector[ atanh(0.1), atanh(-0.2), atanh(0.3) ]

Replace each entry x of dvector with atanh(x).

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.atanh!   -> Dvector[ atanh(1.1), atanh(-2.2), atanh(5.3) ]
   a          -> Dvector[ atanh(1.1), atanh(-2.2), atanh(5.3) ]

Returns the boundaries of a Dvector, that is [min, max]. It ignores NaN and will complain if the Dvector contains only NaN.

 v = Dvector[0.0/0.0, 0.0/0.0, 1,2,4,5,9,0.0/0.0,0.1]
 v.bounds -> [0.1, 9]

Returns of copy of dvector with entry x replaced by smallest integer not less than x.

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.ceil   -> Dvector[ 2, -2, 6 ]

Replace each entry x of dvector with the smallest integer not less than x.

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.ceil!   -> Dvector[ 2, -2, 6 ]
   a         -> Dvector[ 2, -2, 6 ]

Returns true if the vector hasn‘t been modified since the last time dirty was cleared. See dirty?.

Removes all elements from dvector.

   a = Dvector[ 1, 2, 3, 4, 5 ]
   a.clear    -> Dvector[]

Invokes block once for each element of dvector. Returns a new vector holding the values returned by block. Note that for numeric operations on long vectors, it is more efficient to apply the operator directly to the vector rather than using map or collect.

   a = Dvector[ 1, 2, 3, 4 ]
   a.map {|x| x**2 + 1 }      -> Dvector[ 2, 5, 10, 17 ]
  A better way:
   a = Dvector[ 1, 2, 3, 4 ]
   a**2 + 1                   -> Dvector[ 2, 5, 10, 17 ]

Invokes block once for each element of dvector, replacing the element with the value returned by block. Note that for numeric operations on long vectors, it is more efficient to apply the operator directly to the vector rather than using these operators.

   a = Dvector[ 2, -3, 7 ]
   a.map! {|x| x**2 + 1 }      -> Dvector[ 5, 10, 50 ]
   a                           -> Dvector[ 5, 10, 50 ]

A better way:

   a.mul!(a).add!(1)           -> Dvector[ 5, 10, 50 ]

Calls block for each element of dvector along with the corresponding element in other. Creates a new vector containing the values returned by block. The vectors must be the same size.

   a = Dvector[ 1, 0, -1 ]
   b = Dvector[ 3, 4, 5 ]
   a.map2(b) {|x,y| x**2 + y**2 }  -> Dvector[ 10, 16, 26 ]

Invokes block once for each element of dvector, replacing the element with the value returned by block.

   a = Dvector[ 1, 0, -1 ]
   b = Dvector[ 3, 4, 5 ]
   a.map2!(b) {|x,y| x**2 + y**2 }  -> Dvector[ 10, 16, 26 ]
   a                                -> Dvector[ 10, 16, 26 ]

Appends the elements in other to dvector. other can either be a Dvector or a 1D Array of numbers.

a = Dvector[1, 5, -3] a.concat([6, 7]) -> Dvector[ 1, 5, -3, 6, 7 ] a -> Dvector[ 1, 5, -3, 6, 7 ]

: convolve applies a simple convolution to the vector using kernel centered at the point middle. (0 is the leftmost point of the kernel).

Returns of copy of dvector with entry x replaced by cos(x).

   a = Dvector[ 1, -2, -3, 4 ]
   a.cos   -> Dvector[ cos(1), cos(-2), cos(-3), cos(4) ]

Replace each entry x of dvector with cos(x).

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.cos!   -> Dvector[ cos(1.1), cos(-2.2), cos(5.3) ]
   a        -> Dvector[ cos(1.1), cos(-2.2), cos(5.3) ]

Returns of copy of dvector with entry x replaced by cosh(x).

   a = Dvector[ 0.1, -0.2, 0.3 ]
   a.cosh   -> Dvector[ cosh(0.1), cosh(-0.2), cosh(0.3) ]

Replace each entry x of dvector with cosh(x).

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.cosh!   -> Dvector[ cosh(1.1), cosh(-2.2), cosh(5.3) ]
   a         -> Dvector[ cosh(1.1), cosh(-2.2), cosh(5.3) ]

Deletes items from dvector that are equal to number. If number is not found, returns nil. If the optional code block is given, returns the result of block if the item is not found.

   a = Dvector.new(5) {|i| i*3 }
   a.delete(6)                     -> 6
   a                               -> Dvector[0, 3, 9, 12]
   a.delete(2)                     -> nil
   a.delete(2) { "not found" }     -> "not found"

Deletes the element at the specified index int, returning that element, or nil if the index is out of range.

   a = Dvector.new(5) {|i| i*3 }
   a.delete_at(2)                   -> 6
   a                                -> Dvector[0, 3, 9, 12]
   a.delete_at(6)                   -> nil

Deletes every element of dvector for which block evaluates to true.

   a = Dvector[ 1, 2, 3, 4 ]
   a.delete_if {|x| x.modulo(2) == 0 }   -> Dvector[1, 3]
   a                                     -> Dvector[ 1, 3 ]
dirty()

Alias for dirty?

Sets (or unsets) the dirty flag. Returns dvector.

Returns true if the vector has been modified since the last time dirty was cleared. When a Dvector is created or copied, dirty is set to false. It is set to true whenever the vector is modified. You need to reset it manually using dirty=.

When argument is a number, this operation returns a copy of dvector with each entry x replaced by x / number. When argument is a vector, this operation returns a copy of dvector with each entry x replaced by x / the corresponding entry in the other vector.

   a = Dvector[ 1.1, -5.7, 2.5 ]
   a.div(3.8)              -> Dvector[ 1.1/3.8, -5.7/3.8, 2.5/3.8 ]
   a / 3.8                 -> Dvector[ 1.1/3.8, -5.7/3.8, 2.5/3.8 ]
   3 / a                   -> Dvector[ 3.8/1.1, -3.8/5.7, 3.8/2.5 ]
   b = Dvector[ 7.1, 4.9, -10.1 ]
   a.div(b)                -> Dvector[ 1.1/7.1, -5.7/4.9, 2.5/10.1 ]
   a / b                   -> Dvector[ 1.1/7.1, -5.7/4.9, 2.5/10.1 ]

When argument is a number, each entry x in dvector is replaced by x / number. When argument is a vector, each entry x in dvector is replaced by x / the corresponding entry in the other vector.

   a = Dvector[ 1.1, -5.7, 2.5 ]
   a.div!(3.8)             -> Dvector[ 1.1/3.8, -5.7/3.8, 2.5/3.8 ]
   a                       -> Dvector[ 1.1/3.8, -5.7/3.8, 2.5/3.8 ]
   a = Dvector[ 1.1, -5.7, 2.5 ]
   b = Dvector[ 7.1, 4.9, -10.1 ]
   a.div!(b)               -> Dvector[ 1.1/7.1, -5.7/4.9, 2.5/10.1 ]
   a                       -> Dvector[ 1.1/7.1, -5.7/4.9, 2.5/10.1 ]

Returns the sum of the products of entries in dvector and other. Returns 0.0 if dvector is empty. The vectors must be the same length.

   a = Dvector[ 1, 2, 3, 4 ]
   b = Dvector[ 1, -3, 3, 0 ]
   a.dot(b)        -> 4
   Dvector[].dot(b)   -> 0

Returns a copy of dvector. For performance sensitive situations involving a series of vector operations, first make a copy using dup and then do "bang" operations to modify the result without further copying.

Calls block once for each element in dvector, passing that element as a parameter.

   a = Dvector[ 1, 0, -1 ]
   a.each {|x| print x, " -- " }

produces:

    1 -- 0 -- -1 --

Calls block once for each element in dvector, passing that element as a parameter along with the corresponding element from the other vector. The two vectors must be the same length.

   a = Dvector[ 1, 0, -1 ]
   b = Dvector[ 3, 4, 5 ]
   a.each2(b) {|x,y| print "(", x ",", y, ") " }

produces:

   (1,3) (0,4) (-1,5)

Calls block once for each element in dvector, passing the element, the corresponding element from the other vector, and the index.

   a = Dvector[ 1, 0, -1 ]
   b = Dvector[ 3, 4, 5 ]
   a.each2_with_index(b) {|x,y,i| print "(", x ",", y, ",", i, ") " }

produces:

   (1,3,0) (0,4,1) (-1,5,2)

Same as Dvector#each, but passes the index of the element instead of the element itself.

   a = Dvector[ 1, 0, -1 ]
   a.each_index {|x| print x, " -- " }

produces:

   0 -- 1 -- 2 --

Same as Dvector#each, but passes the index of the element in addition to the element itself.

Returns true if dvector vector contains no elements.

   Dvector[].empty?   -> true

Returns true if dvector and other have the same content. other can either be a Dvector or a 1D Array of numbers.

Returns of copy of dvector with each entry x replaced by exp(x).

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.exp   -> Dvector[ exp(1.1), exp(-2.2), exp(5.3) ]

Replace each entry x of dvector with exp(x).

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.exp!   -> Dvector[ exp(1.1), exp(-2.2), exp(5.3) ]
   a        -> Dvector[ exp(1.1), exp(-2.2), exp(5.3) ]

Returns of copy of dvector with each entry x replaced by 10**x.

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.exp10   -> Dvector[ 10**(1.1), 10**(-2.2), 10**(5.3) ]

Replace each entry x of dvector with 10**x.

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.exp10!   -> Dvector[ 10**(1.1), 10**(-2.2), 10**(5.3) ]
   a          -> Dvector[ 10**(1.1), 10**(-2.2), 10**(5.3) ]

Tries to return the element at index int. If the index lies outside the vector, the first form throws an IndexError exception, the second form returns default, and the third form returns the value of invoking the block, passing in the index. Negative values of the index count from the end of the vector.

   a = Dvector[ 11, 22, 33, 44 ]
   a.fetch(1)               -> 22
   a.fetch(-1)              -> 44
   a.fetch(4, 0)            -> 0
   a.fetch(4) { |i| i*i }   -> 16

The first three forms set the selected elements of dvector (which may be the entire vector) to number. A start of nil is equivalent to zero. A length of nil is equivalent to dvector.length. The last three forms fill the vector with the value of the block. The block is passed the absolute index of each element to be filled.

   a = Dvector[ 1, 2, 3, 4, 5 ]
   a.fill(-1)               -> Dvector[ -1, -1, -1, -1, -1 ]
   a.fill(7, 2, 2)          -> Dvector[ -1, -1, 7, 7, -1 ]
   a.fill(8, 0..1)          -> Dvector[ 8, 8, 7, 7, -1 ]
   a.fill {|i| i*i}         -> Dvector[ 0, 1, 4, 9, 16 ]
   a.fill(-2) {|i| i*i*i}   -> Dvector[ 0, 1, 4, 27, 64 ]
   a                        -> Dvector[ 0, 1, 4, 27, 64 ]

Returns the first element, or the first count elements, of dvector. If the vector is empty, the first form returns nil, and the second returns an empty vector.

   a = Dvector[ 1, 2, 3, 4, 5 ]
   a.first   -> 1
   a.first(1)   -> Dvector[ 1 ]
   a.first(3)   -> Dvector[ 1, 2, 3 ]

Returns of copy of dvector with each entry x replaced by largest integer not greater than x.

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.floor   -> Dvector[ 1, -3, 5 ]

Replace each entry x of dvector with the largest integer not greater than x.

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.floor!   -> Dvector[ 1, -3, 5 ]
   a          -> Dvector[ 1, -3, 5 ]

Prevents further modifications. A TypeError will be raised if modification is attempted.

Return true if this vector is frozen (or temporarily frozen while being sorted).

Returns true if number is present in dvector, false otherwise.

   a = Dvector[ 1, 2, 3 ]
   a.include?(2)   -> true
   a.include?(0)   -> false

Returns the index of the first object in dvector == to number. Returns nil if no match is found.

   a = Dvector[ 1, 2, 3, 4, 5, 4, 3, 2 ]
   a.index(3)   -> 2
   a.index(0)   -> nil

Replaces the contents of dvector with the contents of other, truncating or expanding if necessary.

   a = Dvector[ 1, 2, 3, 4, 5 ]
   a.replace(Dvector[ -1, -2, -3 ])   -> Dvector[ -1, -2, -3 ]
   a                               -> Dvector[ -1, -2, -3 ]

If the index is not negative, insert the given values before

   the element with the index _int_.  If the index is -1, appends the
   values to _dvector_.  Otherwise inserts the values after the element
  with the given index.

   a = Dvector[ 1, 2, 3 ]
   a.insert(2, 99)         -> Dvector[ 1, 2, 99, 3 ]
   a.insert(-2, 1, 2, 3)   -> Dvector[ 1, 2, 99, 1, 2, 3, 3 ]
   a.insert(-1, 0)         -> Dvector[ 1, 2, 99, 1, 2, 3, 3, 0 ]
inspect()

Alias for to_s

Returns of copy of dvector with each entry x replaced by 1/x.

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.inv   -> Dvector[ 1 / 1.1, -1 / 2.2, 1 / 5.3 ]

Replace each entry x of dvector with 1/x.

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.inv!   -> Dvector[ 1 / 1.1, -1 / 2.2, 1 / 5.3 ]
   a        -> Dvector[ 1 / 1.1, -1 / 2.2, 1 / 5.3 ]

Returns a string created by converting each element of the vector to a string, separated by sep.

   Dvector[ 1, 2, 3 ].join        -> "1 2 3"
   Dvector[ 1, 2, 3 ].join("-")   -> "1-2-3"

Returns the last element, or the last count elements, of dvector. If the vector is empty, the first form returns nil, and the second returns an empty vector.

   a = Dvector[ 1, 2, 3, 4, 5 ]
   a.last   -> 5
   a.last(1)   -> Dvector[ 5 ]
   a.last(3)   -> Dvector[ 3, 4, 5 ]

Returns the number of elements in dvector.

   Dvector[ 0, -1, 2, -3, 4 ].length   -> 5
   Dvector[].length                    -> 0

Returns of copy of dvector with each entry x replaced by log(x).

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.log   -> Dvector[ log(1.1), log(-2.2), log(5.3) ]

Replace each entry x of dvector with log(x).

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.log!   -> Dvector[ log(1.1), log(-2.2), log(5.3) ]
   a        -> Dvector[ log(1.1), log(-2.2), log(5.3) ]

Returns of copy of dvector with each entry x replaced by log10(x).

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.log10   -> Dvector[ log10(1.1), log10(-2.2), log10(5.3) ]

Replace each entry x of dvector with log10(x).

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.log10!   -> Dvector[ log10(1.1), log10(-2.2), log10(5.3) ]
   a          -> Dvector[ log10(1.1), log10(-2.2), log10(5.3) ]

Replaces contents of dvector by control points for Bezier curve. The cubic, y(x), is defined from x0 to x0+delta_x. At location x = x0 + dx, with dx between 0 and delta_x, define y = a*dx^3 + b*dx^2 + c*dx + y0. This routine replaces the contents of dest by [x1, y1, x2, y2, x3, y3], the Bezier control points to match this cubic.

map()

Alias for collect

map!()

Alias for collect!

map2(p1)

Alias for collect2

map2!(p1)

Alias for collect2!

First form returns the entry with the maximum value in dvector, nil if dvector is empty. Second form returns maximum of all the vectors (or nil if all are empty).

   a = Dvector[ 1, 2, 3, 4, 5, 4, 3, 5, 2 ]
   a.max               -> 5
   Dvector[].max          -> nil
   b = Dvector[ 8, 3, 0, 7 ]
   a.max(b)            -> 8

Returns the maximum entry in dvector which is less than val, or nil if no such entry if found.

First form returns the entry with the minimum value in dvector, nil if dvector is empty. Second form returns minimum of all the vectors (or nil if all are empty).

   a = Dvector[ 1, 2, 3, 4, 5, 4, 3, 5, 2 ]
   a.min               -> 1
   Dvector[].min          -> nil
   b = Dvector[ 8, 3, 0, 7 ]
   a.min(b)            -> 0

Returns the minimum entry in dvector which is greater than val, or nil if no such entry if found.

minus(p1)

Alias for sub

minus!(p1)

Alias for sub!

mod(p1)

Alias for modulo

mod!(p1)

Alias for modulo!

When argument is a number, this operation returns a copy of dvector with each entry x replaced by x % number. When argument is a vector, this operation returns a copy of dvector with each entry x replaced by x % the corresponding entry in the other vector.

   a = Dvector[ 1.1, -5.7, 12.7 ]
   a.mod(3.8)              -> Dvector[ 1.1, 1.9, 1.3 ]
   a % 3.8                 -> Dvector[ 1.1, 1.9, 1.3 ]
   b = Dvector[ 7.1, 4.9, -10.1 ]
   a.mod(b)                -> Dvector[ 1.1, 4.1, -7.5 ]
   a % b                   -> Dvector[ 1.1, 4.1, -7.5 ]

When argument is a number, this operation returns a copy of dvector with each entry x replaced by x % number. When argument is a vector, this operation returns a copy of dvector with each entry x replaced by x % the corresponding entry in the other vector.

   a = Dvector[ 1.1, -5.7, 12.7 ]
   a.mod!(3.8)              -> Dvector[ 1.1, 1.9, 1.3 ]
   a                        -> Dvector[ 1.1, 1.9, 1.3 ]
   b = Dvector[ 7.1, 4.9, -10.1 ]
   a.mod!(b)                -> Dvector[ 1.1, 4.1, -7.5 ]
   a                        -> Dvector[ 1.1, 4.1, -7.5 ]

When argument is a number, this operation returns a copy of dvector with each entry x replaced by x * number. When argument is a vector, this operation returns a copy of dvector with each entry x replaced by x * the corresponding entry in the other vector.

   a = Dvector[ 11, -5, 2 ]
   a.mul(3)               -> Dvector[ 33, -15, 6 ]
   a * 3                  -> Dvector[ 33, -15, 6 ]
   3 * a                  -> Dvector[ 33, -15, 6 ]
   b = Dvector[ 7, 4, -10 ]
   a.mul(b)               -> Dvector[ 77, -20, -20 ]
   a * b                  -> Dvector[ 77, -20, -20 ]

When argument is a number, each entry x in dvector is replaced by x * number. When argument is a vector, each entry x in dvector is replaced by x * the corresponding entry in the other vector.

   a = Dvector[ 11, -5, 2 ]
   a.mul!(3)               -> Dvector[ 33, -15, 6 ]
   a                       -> Dvector[ 33, -15, 6 ]
   a = Dvector[ 11, -5, 2 ]
   b = Dvector[ 7, 4, -10 ]
   a.mul!(b)               -> Dvector[ 77, -20, -20 ]
   a                       -> Dvector[ 77, -20, -20 ]

Returns of copy of dvector with each entry x replaced by -x.

   a = Dvector[ 1, 2, 3, 4 ]
   a.neg   -> Dvector[ -1, -2, -3, -4 ]

Replace each entry x of dvector with -x.

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.neg!   -> Dvector[ -1.1, 2.2, -5.3 ]
   a        -> Dvector[ -1.1, 2.2, -5.3 ]
nitems()

Alias for length

plus(p1)

Alias for add

plus!(p1)

Alias for add!

Removes the last element from dvector and returns it, or nil if the vector is empty.

   a = Dvector[ 1, 2, 3 ]
   a.pop   -> 3
   a       -> Dvector[ 1, 2 ]

When argument is a number, this operation returns a copy of dvector with each entry x replaced by x ** number. When argument is a vector, this operation returns a copy of dvector with each entry x replaced by x ** the corresponding entry in the other vector.

   a = Dvector[ 1.1, -5.7, 12.7 ]
   a.raised_to(3)              -> Dvector[ 1.1 ** 3, (-5.7) ** 3, 12.7 ** 3 ]
   a ** 3                      -> Dvector[ 1.1 ** 3, (-5.7) ** 3, 12.7 ** 3 ]
   b = Dvector[ 7, 4, -2 ]
   a.raised_to(b)                -> Dvector[ 1.1 ** 7, (-5.7) ** 4, 12.7 ** (-2) ]
   a ** b                        -> Dvector[ 1.1 ** 7, (-5.7) ** 4, 12.7 ** (-2) ]

When argument is a number, this operation returns a copy of dvector with each entry x replaced by x ** number. When argument is a vector, this operation returns a copy of dvector with each entry x replaced by x ** the corresponding entry in the other vector.

   a = Dvector[ 1.1, -5.7, 12.7 ]
   a.raised_to!(3)                -> Dvector[ 1.1 ** 3, (-5.7) ** 3, 12.7 ** 3 ]
   a                              -> Dvector[ 1.1 ** 3, (-5.7) ** 3, 12.7 ** 3 ]
   b = Dvector[ 7, 4, -2 ]
   a.raised_to!(b)                -> Dvector[ 1.1 ** 7, (-5.7) ** 4, 12.7 ** (-2) ]
   a                              -> Dvector[ 1.1 ** 7, (-5.7) ** 4, 12.7 ** (-2) ]

Creates a new dvector without the entries given by the indexes in lst.

   a = Dvector.new(5) {|i| i*3 }    -> [0, 3, 6, 9, 12]
   a.prune([0, 2])                  -> [3, 9, 12]
   a                                -> [0, 3, 6, 9, 12]

Modifies the dvector by removing the entries given by the indexes in lst.

   a = Dvector.new(5) {|i| i*3 }    -> [0, 3, 6, 9, 12]
   a.prune!([0, 2])                 -> [3, 9, 12]
   a                                -> [3, 9, 12]

Append—Pushes the given number(s) on to the end of this vector.

   a = Dvector[ 1, 2, 3 ]
   a.push(4, 5, 6)  -> Dvector[1, 2, 3, 4, 5, 6]
raised_to(p1)

Alias for pow

raised_to!(p1)

Alias for pow!

Returns a new vector containing the items in dvector, except those for which the block is true.

   a = Dvector[ 1, 2, 3, 4 ]
   a.reject {|x| x.modulo(2) == 0 }   -> Dvector[1, 3]

Equivalent to Dvector#delete_if, deleting elements from dvector for which the block evaluates to true, but returns nil if no changes were made. Also see Enumerable#reject.

When the argument is a number, this operation returns a copy of dvector with each entry x replaced by the remainder of x divided by number. When the argument is a vector, this operation returns a copy of dvector with each entry x replaced by the remainder of x divided by the corresponding entry in the other vector.

   a = Dvector[ 11, -5, 2 ]
   a.remainder(3)  -> Dvector[ 2, -2, 2 ]
   b = Dvector[ 2, 3, 5 ]
   a.remainder(b)                -> Dvector[ 1, -2, 2 ]

When the argument is a number, this operation replaces with each entry x of dvector by the remainder of x divided by number. When the argument is a vector, this operation replaces with each entry x of dvector by remainder of x divided by the corresponding entry in the other vector.

   a = Dvector[ 11, -5, 2 ]
   a.remainder!(3)                -> Dvector[ 2, -2, 2 ]
   a                              -> Dvector[ 2, -2, 2 ]
   a = Dvector[ 11, -5, 2 ]
   b = Dvector[ 2, 3, 5 ]
   a.remainder!(b)                -> Dvector[ 1, -2, 2 ]
   a                              -> Dvector[ 1, -2, 2 ]

Replaces the contents of dvector with the contents of other, truncating or expanding if necessary.

   a = Dvector[ 1, 2, 3, 4, 5 ]
   a.replace(Dvector[ -1, -2, -3 ])   -> Dvector[ -1, -2, -3 ]
   a                               -> Dvector[ -1, -2, -3 ]

Modifies dvector to have the requested size by truncating or expanding with trailing zeros.

a = Dvector[1, 5, -3] a.resize(5) -> Dvector[ 1, 5, -3, 0, 0 ] a -> Dvector[ 1, 5, -3, 0, 0 ] a.resize(2) -> Dvector[ 1, 5 ] a -> Dvector[ 1, 5 ]

Returns a new vector containing dvector‘s elements in reverse order.

   Dvector[ 1, 2, 3 ].reverse         -> Dvector[ 3, 2, 1 ]
   Dvector[ 1 ].reverse               -> Dvector[ 1 ]

Reverses dvector in place.

   a = Dvector[ 1, 2, 3 ]
   a.reverse!       -> Dvector[ 3, 2, 1 ]
   a                -> Dvector[ 3, 2, 1 ]

Same as Dvector#each, but traverses dvector in reverse order.

   a = Dvector[ 1, 0, -1 ]
   a.each {|x| print x, " " }

produces:

    -1 0 1

Same as Dvector#each2, but traverses vectors in reverse order. The vectors must have the same size.

   a = Dvector[ 1, 0, -1 ]
   b = Dvector[ 3, 4, 5 ]
   a.reverse_each2(b) {|x,y| print "(", x ",", y, ") " }

produces:

    (-1,5) (0,4) (1,3)

Same as Dvector#each2_with_index, but traverses the vectors in reverse order.

   a = Dvector[ 1, 0, -1 ]
   b = Dvector[ 3, 4, 5 ]
   a.reverse_each2_with_index(b) {|x,y,i| print "(", x ",", y, "," i, ") " }

produces:

    (-1,5,2) (0,4,1) (1,3,0)

Same as Dvector#reverse_each, but passes the index of the element instead of the element itself.

   a = Dvector[ 1, 0, -1 ]
   a.reverse_each_index {|i| print i, " -- " }

produces:

   2 -- 1 -- 0 --

Same as Dvector#each_with_index, but traverses dvector in reverse order.

   a = Dvector[ 1, 0, -1 ]
   a.reverse_each_with_index {|x,i| print "(", x, ",", i, ") " }

produces:

   (-1,2) (0,1) (1,0)

Returns the index of the last object in dvector == to number. Returns nil if no match is found.

   a = Dvector[ 1, 2, 3, 4, 5, 4, 3, 2 ]
   a.rindex(3)   -> 6
   a.rindex(0)   -> nil

Returns of copy of dvector with each entry x replaced by round(x). (Numbers midway between integers round away from zero.)

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.round   -> Dvector[ 1, -2, 5 ]

Replace each entry x of dvector with the integer closest to x. (Numbers midway between integers round away from zero.)

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.round!   -> Dvector[ 1, -2, 5 ]
   a          -> Dvector[ 1, -2, 5 ]

Returns a copy of dvector with each entry x replaced by acos(max(-1,min(1,x))).

Replaces each entry x in dvector by acos(max(-1,min(1,x))).

Returns a copy of dvector with each entry x replaced by asin(max(-1,min(1,x))).

Replaces each entry x in dvector by asin(max(-1,min(1,x))).

Returns a copy of dvector with each entry x replaced by sign(x)/cutoff if abs(x) < cutoff, 1/x otherwise.

Replaces each entry x in dvector by sign(x)/cutoff if abs(x) < cutoff, 1/x otherwise.

Returns a copy of dvector with each entry x replaced by log(max(x,cutoff)).

Replaces each entry x in dvector by log(max(x,cutoff)).

Returns a copy of dvector with each entry x replaced by log10(max(x,cutoff)).

Replaces each entry x in dvector by log10(max(x,cutoff)).

Returns a copy of dvector with each entry x replaced by sqrt(max(x,0)).

Replaces each entry x in dvector by sqrt(max(x,0)).

Invokes the block passing in successive elements from dvector, returning a vector containing those elements for which the block returns a true value (equivalent to Enumerable#select).

   a = Dvector[ 1, 2, 3, 4, 5, 6 ]
   a.select {|x| x.modulo(2) == 0 }   -> Dvector[2, 4, 6]

Modifies the entries of dvector array. If the argument is a float, then all of the entries are set to that value. If the argument is another Dvector, then it must be the same length as dvector, and its contents are copied to dvector.

Returns the first element of dvector and removes it (shifting all other elements down by one). Returns nil if the vector is empty.

   args = Dvector[ 1, 2, 3 ]
   args.shift   -> 1
   args         -> Dvector[ 2, 3 ]

Returns of copy of dvector with entry x replaced by sin(x).

   a = Dvector[ 1, -2, -3, 4 ]
   a.sin   -> Dvector[ sin(1), sin(-2), sin(-3), sin(4) ]

Replace each entry x of dvector with sin(x).

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.sin!   -> Dvector[ sin(1.1), sin(-2.2), sin(5.3) ]
   a        -> Dvector[ sin(1.1), sin(-2.2), sin(5.3) ]

Returns of copy of dvector with entry x replaced by sinh(x).

   a = Dvector[ 0.1, -0.2, 0.3 ]
   a.sinh   -> Dvector[ sinh(0.1), sinh(-0.2), sinh(0.3) ]

Replace each entry x of dvector with sinh(x).

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.sinh!   -> Dvector[ sinh(1.1), sinh(-2.2), sinh(5.3) ]
   a         -> Dvector[ sinh(1.1), sinh(-2.2), sinh(5.3) ]
size()

Alias for length

slice(...)

Alias for #[]

Deletes the element(s) given by an index (optionally with a length) or by a range. Returns the deleted object, subvector, or nil if the index is out of range.

   a = Dvector.new(5) {|i| i*3 }
   a.slice!(1)               -> 3
   a                         -> Dvector[0, 6, 9, 12]
   a.slice!(-1)              -> 12
   a                         -> Dvector[0, 6, 9]
   a.slice!(100)             -> nil
   a                         -> Dvector[0, 6, 9]
   a.slice!(1..2)            -> Dvector[6, 9]
   a                         -> Dvector[0]
   a.slice!(1..2)            -> Dvector[]
   a                         -> Dvector[0]
   a.slice!(0..2)            -> Dvector[0]
   a                         -> Dvector[]

Returns a new vector created by sorting dvector. Comparisons for the sort will be done using the <=> operator or using an optional code block. The block implements a comparison between a and b, returning -1, 0, or +1.

   a = Dvector[ 4, 1, 2, 5, 3 ]
   a.sort                    -> Dvector[ 1, 2, 3, 4, 5 ]
   a                         -> Dvector[ 4, 1, 2, 5, 3 ]
   a.sort {|x,y| y <=> x }   -> Dvector[ 5, 4, 3, 2, 1 ]

Sorts dvector in place. dvev is effectively frozen while a sort is in progress. Comparisons for the sort will be done using the <=> operator or using an optional code block. The block implements a comparison between a and b, returning -1, 0, or +1.

   a = Dvector[ 4, 1, 2, 5, 3 ]
   a.sort!                    -> Dvector[ 1, 2, 3, 4, 5 ]
   a                          -> Dvector[ 1, 2, 3, 4, 5 ]
   a.sort! {|x,y| y <=> x }   -> Dvector[ 5, 4, 3, 2, 1 ]
   a                          -> Dvector[ 5, 4, 3, 2, 1 ]

Returns of copy of dvector with each entry x replaced by sqrt(x).

   a = Dvector[ 1.1, 2.2, 5.3 ]
   a.sqrt   -> Dvector[ sqrt(1.1), sqrt(2.2), sqrt(5.3) ]

Replace each entry x of dvector with sqrt(x).

   a = Dvector[ 1.1, 2.2, 5.3 ]
   a.sqrt!   -> Dvector[ sqrt(1.1), sqrt(2.2), sqrt(5.3) ]
   a         -> Dvector[ sqrt(1.1), sqrt(2.2), sqrt(5.3) ]

When argument is a number, this operation returns a copy of dvector with each entry x replaced by x - number. When argument is a vector, this operation returns a copy of dvector with each entry x replaced by x - the corresponding entry in the other vector.

   a = Dvector[ 11, -5, 2 ]
   a.sub(3)               -> Dvector[ 8, -8, -1 ]
   a - 3                  -> Dvector[ 8, -8, -1 ]
   3 - a                  -> Dvector[ -8, 8, 1 ]
   b = Dvector[ 7, 4, -10 ]
   a.sub(b)               -> Dvector[ 4, -9, 12 ]
   a - b                  -> Dvector[ 4, -9, 12 ]

When argument is a number, each entry x in dvector is replaced by x - number. When argument is a vector, each entry x in dvector is replaced by x - the corresponding entry in the other vector.

   a = Dvector[ 11, -5, 2 ]
   a.sub!(3)               -> Dvector[ 8, -8, -1 ]
   a                       -> Dvector[ 8, -8, -1 ]
   b = Dvector[ 7, 4, -10 ]
   a = Dvector[ 11, -5, 2 ]
   a.sub!(b)               -> Dvector[ 4, -9, 12 ]
   a                       -> Dvector[ 4, -9, 12 ]

Returns the sum of the entries in dvector. Returns 0.0 if dvector is empty.

   a = Dvector[ 1, 2, 3, 4 ]
   a.sum        -> 10
   Dvector[].sum   -> 0

Returns of copy of dvector with entry x replaced by tan(x).

   a = Dvector[ 1, -2, -3, 4 ]
   a.tan   -> Dvector[ tan(1), tan(-2), tan(-3), tan(4) ]

Replace each entry x of dvector with tan(x).

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.tan!   -> Dvector[ tan(1.1), tan(-2.2), tan(5.3) ]
   a        -> Dvector[ tan(1.1), tan(-2.2), tan(5.3) ]

Returns of copy of dvector with entry x replaced by tanh(x).

   a = Dvector[ 0.1, -0.2, 0.3 ]
   a.tanh   -> Dvector[ tanh(0.1), tanh(-0.2), tanh(0.3) ]

Replace each entry x of dvector with tanh(x).

   a = Dvector[ 1.1, -2.2, 5.3 ]
   a.tanh!   -> Dvector[ tanh(1.1), tanh(-2.2), tanh(5.3) ]
   a         -> Dvector[ tanh(1.1), tanh(-2.2), tanh(5.3) ]
times(p1)

Alias for mul

times!(p1)

Alias for mul!

Returns an Array with the same contents as dvector.

to_ary()

Alias for to_a

Create an NArray with the same length and contents as self.

Returns dvector.join.

   Dvector[ 1, 2, 3 ].to_s        -> "1 2 3"

Sets contents of dvector to solution vector u of the following tri-diagonal matrix problem.

   |  b[0]  c[0]    0    ...                         |   |  u[0]  |   |  r[0]  |
   |  a[1]  b[1]  c[1]   ...                         |   |  u[1]  |   |  r[1]  |
   |                     ...                         | * |  ...   | = |  ...   |
   |                     ... a[n-2]  b[n-2]  c[n-2]  |   | u[n-2] |   | r[n-2] |
   |                     ...   0     a[n-1]  b[n-1]  |   | u[n-1] |   | r[n-1] |

This corresponds to solving difference equations of the form

             a[j] * u[j-1] + b[j] * u[j] + c[j] * u[j+1] = r[j], for 0 < j < n,

with boundary conditions

   u[0]   = (r[0] - c[0] * u[1]) / b[0], and
   u[n-1] = (r[n-1] - a[n-1] * u[n-2]) / b[n-1].

See Numerical Recipes for more details.

Returns a copy of dvector with any entry with absolute value less than cutoff replaced by 0.

   a = Dvector[ 1.1, 1e-20, -5.3 ]
   a.trim  -> Dvector[ 1.1, 0, -5.3 ]

Each entry x in dvector having absolute value less than cutoff is replaced by 0.

   a = Dvector[ 1.1, 1e-20, -5.3 ]
   a.trim!  -> Dvector[ 1.1, 0, -5.3 ]

Returns a new vector by removing duplicate elements from dvector. Remove the element if there is a later one in the vector that is equal to it.

   a = Dvector[ 1.1, 3.8, 1.7, 3.8, 5 ]
   a.uniq              ->   Dvector[1.1, 1.7, 3.8, 5]

Same as Dvector#uniq, but modifies the receiver in place. Returns nil if no changes are made (that is, no duplicates are found).

 Removes duplicate elements from dvector.
 Deletes the element if there is a later one in the vector that is equal to it.

    a = Dvector[ 1.1, 3.8, 1.7, 3.8, 5 ]
    a.uniq!              ->   Dvector[1.1, 1.7, 3.8, 5]
    b = Dvector[ 1.1, 3.8, 1.7, 5 ]
    b.uniq!              ->   nil

Prepends objects to the front of dvector, moving other elements up one.

   a = [ 2, 3, 4 ]
   a.unshift(1)      -> Dvector[ 1, 2, 3, 4 ]
   a.unshift(-1, 0)  -> Dvector[ -1, 0, 1, 2, 3, 4 ]

Returns a new vector containing the elements in dvector corresponding to the given selector(s). The selectors may be either integer indices or ranges.

   a = Dvector[ 1, 2, 3, 4, 5, 6 ]
   a.values_at(1, 3, 5)           -> Dvector[ 2, 4, 6 ]
   a.values_at(1, 3, 5, 7)        -> Dvector[ 2, 4, 6 ]
   a.values_at(-1, -3, -5, -7)    -> Dvector[ 6, 4, 2 ]
   a.values_at(1..3, 2...5)       -> Dvector[ 2, 3, 4, 3, 4, 5 ]

Returns square root of the dot product of the vector with itself.

   a = Dvector[ 3, 5 ]
   a.vector_length -> 5.0

Returns the index of the first entry in dvector with value closest to number, nil if dvector is empty.

   a = Dvector[ 1, 2, -3, 4, -5, 4, 3, -5, 2 ]
   a.where_closest(3.9)        -> 3
   Dvector[].where_closest(3.9)   -> nil
where_eq(p1)

Alias for where_first_eq

where_first_closest(p1)

Alias for where_closest

Returns the index of the first entry in dvector with value equal to number, nil if dvector has no such entry.

   a = Dvector[ 1, 2, -3, 4, -5, 4, 3, -5, 2 ]
   a.where_eq(4)        -> 3
   a.where_eq(6)        -> nil
   Dvector[].where_eq(4)   -> nil

Returns the index of the first entry in dvector with value greater than or equal number, nil if dvector has no such entry.

   a = Dvector[ 1, 2, -3, 4, -5, 4, 3, -5, 2 ]
   a.where_ge(3)        -> 3
   a.where_ge(5)        -> nil
   Dvector[].where_ge(0)   -> nil

Returns the index of the first entry in dvector with value greater than number, nil if dvector has no such entry.

   a = Dvector[ 1, 2, -3, 4, -5, 4, 3, -5, 2 ]
   a.where_gt(3)        -> 3
   a.where_gt(4)        -> nil
   Dvector[].where_gt(0)   -> nil

Returns the index of the first entry in dvector with value less than or equal number, nil if dvector has no such entry.

   a = Dvector[ 1, 2, -3, 4, -5, 4, 3, -5, 2 ]
   a.where_le(0)        -> 2
   a.where_le(-5.5)     -> nil
   Dvector[].where_le(4)   -> nil

Returns the index of the first entry in dvector with value less than number, nil if dvector has no such entry.

   a = Dvector[ 1, 2, -3, 4, -5, 4, 3, -5, 2 ]
   a.where_lt(1)        -> 2
   a.where_lt(-5)       -> nil
   Dvector[].where_lt(4)   -> nil
where_first_max()

Alias for where_max

where_first_min()

Alias for where_min

Returns the index of the first entry in dvector with value not equal to number, nil if dvector has no such entry.

   a = Dvector[ 1, 2, -3, 4, -5, 4, 3, -5, 2 ]
   a.where_ne(1)        -> 1
   Dvector[].where_ne(4)   -> nil
where_ge(p1)

Alias for where_first_ge

where_gt(p1)

Alias for where_first_gt

Returns the index of the last entry in dvector with value closest to number, nil if dvector is empty.

   a = Dvector[ 1, 2, -3, 4, -5, 4, 3, -5, 2 ]
   a.where_last_closest(3.9)         -> 5
   Dvector[].where_last_closest(3.9)    -> nil

Returns the index of the last entry in dvector with value equal number, nil if dvector has no such entry.

   a = Dvector[ 1, 2, -3, 4, -5, 4, 3, -5, 2 ]
   a.where_last_eq(2)         -> 8
   a.where_last_eq(5)         -> nil
   Dvector[].where_last_eq(0)    -> nil

Returns the index of the last entry in dvector with value greater than or equal number, nil if dvector has no such entry.

   a = Dvector[ 1, 2, -3, 4, -5, 4, 3, -5, 2 ]
   a.where_last_ge(4)        -> 5
   a.where_last_ge(5)        -> nil
   Dvector[].where_last_ge(0)   -> nil

Returns the index of the last entry in dvector with value greater than number, nil if dvector has no such entry.

   a = Dvector[ 1, 2, -3, 4, -5, 4, 3, -5, 2 ]
   a.where_last_gt(2)        -> 6
   a.where_last_gt(4)        -> nil
   Dvector[].where_last_gt(0)   -> nil

Returns the index of the last entry in dvector with value less than or equal number, nil if dvector has no such entry.

   a = Dvector[ 1, 2, -3, 4, -5, 4, 3, -5, 2 ]
   a.where_last_le(1)        -> 7
   a.where_last_le(-6)       -> nil
   Dvector[].where_last_le(0)   -> nil

Returns the index of the last entry in dvector with value less than number, nil if dvector has no such entry.

   a = Dvector[ 1, 2, -3, 4, -5, 4, 3, -5, 2 ]
   a.where_last_lt(2)        -> 7
   a.where_last_lt(-5)       -> nil
   Dvector[].where_last_lt(0)   -> nil

Returns the index of the last entry with the maximum value in dvector. Returns nil if dvector is empty.

   a = Dvector[ 1, 2, 3, 4, 5, 4, 3, 5, 2 ]
   a.where_last_max        -> 7
   Dvector[].where_last_max   -> nil

Returns the index of the last entry with the minimum value in dvector, nil if dvector is empty.

   a = Dvector[ 1, 2, -3, 4, -5, 4, 3, -5, 2 ]
   a.where_last_min         -> 7
   Dvector[].where_last_min    -> nil

Returns the index of the last entry in dvector with value not equal number, nil if dvector has no such entry.

   a = Dvector[ 1, 2, -3, 4, -5, 4, 3, -5, 2 ]
   a.where_last_ne(2)        -> 7
   Dvector[0].where_last_ne(0)  -> nil
   Dvector[].where_last_ne(0)   -> nil
where_le(p1)

Alias for where_first_le

where_lt(p1)

Alias for where_first_lt

Returns the index of the first entry with the maximum value in dvector. Returns nil if dvector is empty.

   a = Dvector[ 1, 2, 3, 4, 5, 4, 3, 5, 2 ]
   a.where_max        -> 4
   Dvector[].where_max   -> nil

Returns the index of the first entry with the minimum value in dvector, nil if dvector is empty.

   a = Dvector[ 1, 2, -3, 4, -5, 4, 3, -5, 2 ]
   a.where_min        -> 4
   Dvector[].where_min   -> nil
where_ne(p1)

Alias for where_first_ne

[Validate]