org.saddle

Vec

trait Vec[T] extends NumericOps[Vec[T]] with Serializable

Vec is an immutable container for 1D homogeneous data (a "vector"). It is backed by an array and indexed from 0 to length - 1.

Several element access methods are provided.

The apply() method returns a slice of the original vector:

  val v = Vec(1,2,3,4)
  v(0) == Vec(1)
  v(1, 2) == Vec(2,3)

The at method returns an instance of a Scalar, which behaves much like an Option in that it can be either an instance of org.saddle.scalar.NA or a Value case class:

  Vec[Int](1,2,3,na).at(0) == Scalar(1)
  Vec[Int](1,2,3,na).at(3) == NA

The method raw accesses the underlying value directly.

  Vec(1d,2,3).raw(0) == 1d

Vec may be used in arithemetic expressions which operate on two Vecs or on a Vec and a scalar value. A few examples:

  Vec(1,2,3,4) + Vec(2,3,4,5) == Vec(3,5,7,9)
  Vec(1,2,3,4) * 2 == Vec(2,4,6,8)

Note, Vec is implicitly convertible to an array for convenience; this could be abused to mutate the contents of the Vec. Try to avoid this!

T

Type of elements within the Vec

Linear Supertypes
Serializable, Serializable, NumericOps[Vec[T]], AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Hide All
  2. Show all
  1. Vec
  2. Serializable
  3. Serializable
  4. NumericOps
  5. AnyRef
  6. Any
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def concat[B, C](v: Vec[B])(implicit wd: Promoter[T, B, C], mc: ST[C]): Vec[C]

    Concatenate two Vec instances together, where there exists some way to join the type of elements.

    Concatenate two Vec instances together, where there exists some way to join the type of elements. For instance, Vec[Double] concat Vec[Int] will promote Int to Double as a result of the implicit existence of an instance of Promoter[Double, Int, Double]

    B

    type of other Vec elements

    C

    type of resulting Vec elements

    v

    Vec[B] to concat

    wd

    Implicit evidence of Promoter[A, B, C]

    mc

    Implicit evidence of ST[C]

  2. abstract def copy: Vec[T]

    Returns a Vec whose backing array has been copied

    Returns a Vec whose backing array has been copied

    Attributes
    protected
  3. abstract def dropNA: Vec[T]

    Drop the elements of the Vec which are NA

  4. abstract def filterFoldLeft[B](pred: (T) ⇒ Boolean)(init: B)(f: (B, T) ⇒ B)(implicit arg0: ST[B]): B

    Filtered left fold over the elements of the Vec, as in scala collections library

  5. abstract def filterScanLeft[B](pred: (T) ⇒ Boolean)(init: B)(f: (B, T) ⇒ B)(implicit arg0: ST[B]): Vec[B]

    Filtered left scan over elements of the Vec, as in scala collections library

  6. abstract def flatMap[B](f: (T) ⇒ Vec[B])(implicit arg0: ST[B]): Vec[B]

    Maps a function over elements of the Vec and flattens the result.

  7. abstract def foldLeft[B](init: B)(f: (B, T) ⇒ B)(implicit arg0: ST[B]): B

    Left fold over the elements of the Vec, as in scala collections library

  8. abstract def foldLeftWhile[B](init: B)(f: (B, T) ⇒ B)(cond: (B, T) ⇒ Boolean)(implicit arg0: ST[B]): B

    Left fold that folds only while the test condition holds true.

    Left fold that folds only while the test condition holds true. As soon as the condition function yields false, the fold returns.

    cond

    Function whose signature is the same as the fold function, except that it evaluates to Boolean

  9. abstract def hasNA: Boolean

    Return true if there is an NA value in the Vec

  10. abstract def length: Int

    The number of elements in the container F

  11. abstract def map[B](f: (T) ⇒ B)(implicit arg0: ST[B]): Vec[B]

    Map a function over the elements of the Vec, as in scala collections library

  12. abstract def rolling[B](winSz: Int, f: (Vec[T]) ⇒ B)(implicit arg0: ST[B]): Vec[B]

    Produce a Vec whose entries are the result of executing a function on a sliding window of the data.

    Produce a Vec whose entries are the result of executing a function on a sliding window of the data.

    B

    Result type of function

    winSz

    Window size

    f

    Function Vec[A] => B to operate on sliding window

  13. abstract def scalarTag: ScalarTag[T]

    A ScalarTag in the type of the elements of the Vec

  14. abstract def scanLeft[B](init: B)(f: (B, T) ⇒ B)(implicit arg0: ST[B]): Vec[B]

    Left scan over the elements of the Vec, as in scala collections library

  15. abstract def shift(n: Int): Vec[T]

    Creates a view into original Vec, but shifted so that n values at the beginning or end of the Vec are NA's.

    Creates a view into original Vec, but shifted so that n values at the beginning or end of the Vec are NA's. Data is not copied.

    n

    Number of offsets to shift

  16. abstract def slice(from: Int, until: Int, stride: Int = 1): Vec[T]

    Creates a view into original vector from an offset up to, but excluding, another offset.

    Creates a view into original vector from an offset up to, but excluding, another offset. Data is not copied.

    from

    Beginning offset

    until

    One past ending offset

    stride

    Increment within slice

  17. abstract def take(locs: Array[Int]): Vec[T]

    Equivalent to slicing operation; e.

    Equivalent to slicing operation; e.g.

      val v = Vec(1,2,3)
      v.take(0,1) == v(0,1)
    
    locs

    Location of elements to take

  18. abstract def unary_-(): Vec[T]

    Additive inverse of Vec with numeric elements

  19. abstract def without(locs: Array[Int]): Vec[T]

    The complement of the take operation; slice out elements NOT specified in list.

    The complement of the take operation; slice out elements NOT specified in list.

    locs

    Location of elements not to take

  20. abstract def zipMap[B, C](other: Vec[B])(f: (T, B) ⇒ C)(implicit arg0: ST[B], arg1: ST[C]): Vec[C]

    Zips Vec with another Vec and applies a function to the paired elements.

    Zips Vec with another Vec and applies a function to the paired elements. If either of the pair is NA, the result is forced to NA.

    B

    Parameter of other Vec

    C

    Result of function

    other

    Vec[B]

    f

    Function (A, B) => C

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. def %[B, That](other: B)(implicit op: BinOp[Mod, Vec[T], B, That]): That

    Integer modulus of division

    Integer modulus of division

    B

    type of the other operand

    That

    result type of operation

    other

    other operand instance (divisor)

    op

    implicit evidence for operation between this and other

    Definition Classes
    NumericOps
  5. def &[B, That](other: B)(implicit op: BinOp[BitAnd, Vec[T], B, That]): That

    Bit-wise AND

    Bit-wise AND

    B

    type of the other operand

    That

    result type of operation

    other

    other operand instance

    op

    implicit evidence for operation between this and other

    Definition Classes
    NumericOps
  6. def &&[B, That](other: B)(implicit op: BinOp[AndOp, Vec[T], B, That]): That

    Logical AND

    Logical AND

    B

    type of the other operand

    That

    result type of operation

    other

    other operand instance

    op

    implicit evidence for operation between this and other

    Definition Classes
    NumericOps
  7. def *[B, That](other: B)(implicit op: BinOp[Multiply, Vec[T], B, That]): That

    Multiplication

    Multiplication

    B

    type of the other operand

    That

    result type of operation

    other

    other operand instance

    op

    implicit evidence for operation between this and other

    Definition Classes
    NumericOps
  8. def **[B, That](other: B)(implicit op: BinOp[Power, Vec[T], B, That]): That

    Exponentiation

    Exponentiation

    B

    type of the other operand

    That

    result type of operation

    other

    other operand instance (exponent)

    op

    implicit evidence for operation between this and other

    Definition Classes
    NumericOps
  9. def +[B, That](other: B)(implicit op: BinOp[Add, Vec[T], B, That]): That

    Addition

    Addition

    B

    type of the other operand

    That

    result type of operation

    other

    other operand instance

    op

    implicit evidence for operation between this and other

    Definition Classes
    NumericOps
  10. def -[B, That](other: B)(implicit op: BinOp[Subtract, Vec[T], B, That]): That

    Subtraction

    Subtraction

    B

    type of the other operand

    That

    result type of operation

    other

    other operand instance

    op

    implicit evidence for operation between this and other

    Definition Classes
    NumericOps
  11. def /[B, That](other: B)(implicit op: BinOp[Divide, Vec[T], B, That]): That

    Division

    Division

    B

    type of the other operand

    That

    result type of operation

    other

    other operand instance (divisor)

    op

    implicit evidence for operation between this and other

    Definition Classes
    NumericOps
  12. def <[B, That](other: B)(implicit op: BinOp[LtOp, Vec[T], B, That]): That

    Less-than comparison operator

    Less-than comparison operator

    B

    type of the other operand

    That

    result type of operation

    other

    other operand instance

    op

    implicit evidence for operation between this and other

    Definition Classes
    NumericOps
  13. def <<[B, That](other: B)(implicit op: BinOp[BitShl, Vec[T], B, That]): That

    Bit-shift left

    Bit-shift left

    B

    type of the other operand

    That

    result type of operation

    other

    other operand instance

    op

    implicit evidence for operation between this and other

    Definition Classes
    NumericOps
  14. def <=[B, That](other: B)(implicit op: BinOp[LteOp, Vec[T], B, That]): That

    Less-than-or-equal-to comparison operator

    Less-than-or-equal-to comparison operator

    B

    type of the other operand

    That

    result type of operation

    other

    other operand instance

    op

    implicit evidence for operation between this and other

    Definition Classes
    NumericOps
  15. def <>[B, That](other: B)(implicit op: BinOp[NeqOp, Vec[T], B, That]): That

    Element-wise inequality operator

    Element-wise inequality operator

    B

    type of the other operand

    That

    result type of operation

    other

    other operand instance

    op

    implicit evidence for operation between this and other

    Definition Classes
    NumericOps
  16. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  17. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  18. def =?[B, That](other: B)(implicit op: BinOp[EqOp, Vec[T], B, That]): That

    Element-wise equality operator

    Element-wise equality operator

    B

    type of the other operand

    That

    result type of operation

    other

    other operand instance

    op

    implicit evidence for operation between this and other

    Definition Classes
    NumericOps
  19. def >[B, That](other: B)(implicit op: BinOp[GtOp, Vec[T], B, That]): That

    Greater-than comparison operator

    Greater-than comparison operator

    B

    type of the other operand

    That

    result type of operation

    other

    other operand instance

    op

    implicit evidence for operation between this and other

    Definition Classes
    NumericOps
  20. def >=[B, That](other: B)(implicit op: BinOp[GteOp, Vec[T], B, That]): That

    Greater-than-or-equal-to comparison operator

    Greater-than-or-equal-to comparison operator

    B

    type of the other operand

    That

    result type of operation

    other

    other operand instance

    op

    implicit evidence for operation between this and other

    Definition Classes
    NumericOps
  21. def >>[B, That](other: B)(implicit op: BinOp[BitShr, Vec[T], B, That]): That

    Bit-shift right (arithmetic)

    Bit-shift right (arithmetic)

    B

    type of the other operand

    That

    result type of operation

    other

    other operand instance

    op

    implicit evidence for operation between this and other

    Definition Classes
    NumericOps
  22. def >>>[B, That](other: B)(implicit op: BinOp[BitUShr, Vec[T], B, That]): That

    Bit-shift right (logical)

    Bit-shift right (logical)

    B

    type of the other operand

    That

    result type of operation

    other

    other operand instance

    op

    implicit evidence for operation between this and other

    Definition Classes
    NumericOps
  23. def ^[B, That](other: B)(implicit op: BinOp[BitXor, Vec[T], B, That]): That

    Bit-wise EXCLUSIVE OR

    Bit-wise EXCLUSIVE OR

    B

    type of the other operand

    That

    result type of operation

    other

    other operand instance

    op

    implicit evidence for operation between this and other

    Definition Classes
    NumericOps
  24. def apply(rng: Slice[Int]): Vec[T]

    Slice a Vec at a bound of locations, e.

    Slice a Vec at a bound of locations, e.g.

    val v = Vec(1,2,3,4,5) v(1->3) == Vec(2,3,4)

    rng

    evaluates to IRange

  25. def apply(locs: Array[Int]): Vec[T]

    Slice a Vec at a sequence of locations, e.

    Slice a Vec at a sequence of locations, e.g.

    val v = Vec(1,2,3,4,5) v(Array(1,3)) == Vec(2,4)

    locs

    locations at which to slice

  26. def apply(locs: Int*): Vec[T]

    Slice a Vec at a sequence of locations, e.

    Slice a Vec at a sequence of locations, e.g.

    val v = Vec(1,2,3,4,5) v(1,3) == Vec(2,4)

    locs

    locations at which to slice

  27. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  28. def at(loc: Int): Scalar[T]

    Access a boxed element of a Vec[A] at a single location

    Access a boxed element of a Vec[A] at a single location

    loc

    offset into Vec

  29. def clone(): AnyRef

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  30. def contents: Array[T]

    Return copy of backing array

  31. def dot[B, That](other: B)(implicit op: BinOp[InnerProd, Vec[T], B, That]): That

    Dot (inner) product

    Dot (inner) product

    B

    type of the other operand

    That

    result type of operation

    other

    other operand instance

    op

    implicit evidence for operation between this and other

    Definition Classes
    NumericOps
  32. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  33. def equals(o: Any): Boolean

    Default equality does an iterative, element-wise equality check of all values.

    Default equality does an iterative, element-wise equality check of all values.

    NB: to avoid boxing, is overwritten in child classes

    Definition Classes
    Vec → AnyRef → Any
  34. def exists(pred: (T) ⇒ Boolean): Boolean

    Return true if there exists some element of the Vec which satisfies the predicate function

    Return true if there exists some element of the Vec which satisfies the predicate function

    pred

    Predicate function from A => Boolean

  35. def fillNA(f: (Int) ⇒ T): Vec[T]

    Fills NA values in vector with result of a function which acts on the index of the particular NA value found

    Fills NA values in vector with result of a function which acts on the index of the particular NA value found

    f

    A function from Int => A; yields value for NA value at ith position

  36. def filter(pred: (T) ⇒ Boolean): Vec[T]

    Return Vec whose elements satisfy a predicate function

    Return Vec whose elements satisfy a predicate function

    pred

    Predicate function from A => Boolean

  37. def filterAt(pred: (Int) ⇒ Boolean): Vec[T]

    Return vec whose offets satisfy a predicate function

    Return vec whose offets satisfy a predicate function

    pred

    Predicate function from Int => Boolean

  38. def finalize(): Unit

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  39. def find(pred: (T) ⇒ Boolean): Vec[Int]

    Return Vec of integer locations (offsets) which satisfy some predicate

    Return Vec of integer locations (offsets) which satisfy some predicate

    pred

    Predicate function from A => Boolean

  40. def findOne(pred: (T) ⇒ Boolean): Int

    Return first integer location which satisfies some predicate, or -1 if there is none

    Return first integer location which satisfies some predicate, or -1 if there is none

    pred

    Predicate function from A => Boolean

  41. def first: Scalar[T]

    Access the first element of a Vec[A], or NA if length is zero

  42. def forall(pred: (T) ⇒ Boolean)(op: (T) ⇒ Unit): Unit

    Execute a (side-effecting) operation on each (non-NA) element in vec which satisfies some predicate.

    Execute a (side-effecting) operation on each (non-NA) element in vec which satisfies some predicate.

    pred

    Function A => Boolean

    op

    Side-effecting function

  43. def foreach(op: (T) ⇒ Unit): Unit

    Execute a (side-effecting) operation on each (non-NA) element in the vec

    Execute a (side-effecting) operation on each (non-NA) element in the vec

    op

    operation to execute

  44. final def getClass(): java.lang.Class[_]

    Definition Classes
    AnyRef → Any
  45. def hashCode(): Int

    Default hashcode is simple rolling prime multiplication of sums of hashcodes for all values.

    Default hashcode is simple rolling prime multiplication of sums of hashcodes for all values.

    Definition Classes
    Vec → AnyRef → Any
  46. def head(n: Int): Vec[T]

    Return first n elements

    Return first n elements

    n

    Number of elements to access

  47. def isEmpty: Boolean

    True if and only if number of elements is zero

  48. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  49. def last: Scalar[T]

    Access the last element of a Vec[A], or NA if length is zero

  50. def mask(f: (T) ⇒ Boolean): Vec[T]

    Returns Vec whose locations are NA where the result of the provided function evaluates to true

    Returns Vec whose locations are NA where the result of the provided function evaluates to true

    f

    A function taking an element and returning a Boolean

  51. def mask(m: Vec[Boolean]): Vec[T]

    Returns Vec whose locations corresponding to true entries in the boolean input mask vector are set to NA

    Returns Vec whose locations corresponding to true entries in the boolean input mask vector are set to NA

    m

    Mask vector of Vec[Boolean]

  52. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  53. def needsCopy: Boolean

    Set to true when the vec is shifted over the backing array

    Set to true when the vec is shifted over the backing array

    Attributes
    protected
  54. final def notify(): Unit

    Definition Classes
    AnyRef
  55. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  56. def outer[B, That](other: B)(implicit op: BinOp[OuterProd, Vec[T], B, That]): That

    Outer product

    Outer product

    B

    type of the other operand

    That

    result type of operation

    other

    other operand instance

    op

    implicit evidence for operation between this and other

    Definition Classes
    NumericOps
  57. def pad: Vec[T]

    Replaces all NA values for which there is a non-NA value at a lower offset with the corresponding highest-offset, non-NA value.

    Replaces all NA values for which there is a non-NA value at a lower offset with the corresponding highest-offset, non-NA value. E.g,

      Vec(1, 2, NA, 3, NA).pad == Vec(1, 2, 2, 3, 3)
      Vec(NA, 1, 2, NA).pad == Vec(NA, 1, 2, 2)
    
  58. def padAtMost(n: Int): Vec[T]

    Replaces all NA values for which there is a non-NA value at a lower offset with the corresponding highest-offset, non-NA value; but looking back only at most N positions.

    Replaces all NA values for which there is a non-NA value at a lower offset with the corresponding highest-offset, non-NA value; but looking back only at most N positions.

      Vec(1, 2, NA, 3, NA).padAtMost(1) == Vec(1, 2, 2, 3, 3)
      Vec(NA, 1, 2, NA).padAtMost(1) == Vec(NA, 1, 2, 2)
      Vec(1, NA, NA, 3, NA).padAtMost(1) == Vec(1, 1, NA, 3, 3)
    
  59. def print(len: Int = 10, stream: OutputStream = System.out): Unit

    Pretty-printer for Vec, which simply outputs the result of stringify.

    Pretty-printer for Vec, which simply outputs the result of stringify.

    len

    Number of elements to display

  60. def raw(loc: Int): T

    Access an unboxed element of a Vec[A] at a single location

    Access an unboxed element of a Vec[A] at a single location

    loc

    offset into Vec

  61. def reversed: Vec[T]

    Yield a Vec whose elements have been reversed from their original order

  62. def sliceBy(from: Int, to: Int, stride: Int = 1): Vec[T]

    Creates a view into original vector from an offset up to, and including, another offset.

    Creates a view into original vector from an offset up to, and including, another offset. Data is not copied.

    from

    Beginning offset

    to

    Ending offset

    stride

    Increment within slice

  63. def sorted(implicit ev: ORD[T], st: ST[T]): Vec[T]

    Yield a Vec whose elements have been sorted (in ascending order)

    Yield a Vec whose elements have been sorted (in ascending order)

    ev

    evidence of Ordering[A]

  64. def splitAt(i: Int): (Vec[T], Vec[T])

    Split Vec into two Vecs at position i

    Split Vec into two Vecs at position i

    i

    Position at which to split Vec

  65. def stringify(len: Int = 10): String

    Creates a string representation of Vec

    Creates a string representation of Vec

    len

    Max number of elements to include

  66. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  67. def tail(n: Int): Vec[T]

    Return last n elements

    Return last n elements

    n

    Number of elements to access

  68. def toSeq: IndexedSeq[T]

    Converts Vec to an indexed sequence (default implementation is immutable.

    Converts Vec to an indexed sequence (default implementation is immutable.Vector)

  69. def toString(): String

    Definition Classes
    Vec → AnyRef → Any
  70. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  71. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  72. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  73. def where(pred: Vec[Boolean]): Vec[T]

    Return Vec whose elements are selected via a Vec of booleans (where that Vec holds the value true)

    Return Vec whose elements are selected via a Vec of booleans (where that Vec holds the value true)

    pred

    Predicate vector: Vec[Boolean]

  74. def xor[B, That](other: B)(implicit op: BinOp[XorOp, Vec[T], B, That]): That

    Logical EXCLUSIVE OR

    Logical EXCLUSIVE OR

    B

    type of the other operand

    That

    result type of operation

    other

    other operand instance

    op

    implicit evidence for operation between this and other

    Definition Classes
    NumericOps
  75. def |[B, That](other: B)(implicit op: BinOp[BitOr, Vec[T], B, That]): That

    Bit-wise OR

    Bit-wise OR

    B

    type of the other operand

    That

    result type of operation

    other

    other operand instance

    op

    implicit evidence for operation between this and other

    Definition Classes
    NumericOps
  76. def ||[B, That](other: B)(implicit op: BinOp[OrOp, Vec[T], B, That]): That

    Logical OR

    Logical OR

    B

    type of the other operand

    That

    result type of operation

    other

    other operand instance

    op

    implicit evidence for operation between this and other

    Definition Classes
    NumericOps

Inherited from Serializable

Inherited from Serializable

Inherited from NumericOps[Vec[T]]

Inherited from AnyRef

Inherited from Any