Class VecMath


  • public class VecMath
    extends java.lang.Object

    Functional lazy math abstraction built for performing elemwise mathematical operations on scalars and buffers.

    Arithmetic and statistical operations based on the Buffer interface. These operators and functions all implement vectorized interfaces so passing in something convertible to a reader will return a reader. Arithmetic operations are done lazily. These functions generally incur a large dispatch cost so for example each call to '+' checks all the arguments to decide if it should dispatch to an iterable implementation or to a reader implementation. For tight loops or operations like map and filter, using the specific operators will result in far faster code than using the 'add' function itself.

    It is important to note that in generla these functions are typed such that if they take a vector of numbers, they return a vector of numbers. For example,

    max([2,3,4],3)
    returns
    [3,3,4]
    . Functions that are typed to return scalars are prefixed with reduce so
    reduceMax([2,3,4])
    returns 4.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object abs​(java.lang.Object lhs)  
      static java.lang.Object acos​(java.lang.Object lhs)  
      static java.lang.Object add​(java.lang.Object lhs, java.lang.Object rhs)  
      static java.lang.Object asin​(java.lang.Object lhs)  
      static java.lang.Object atan​(java.lang.Object lhs)  
      static java.lang.Object booleansToIndexes​(java.lang.Object boolVec)
      Efficiently convert a Buffer of boolean values to indexes that indicate where the true values are.
      static java.lang.Object cbrt​(java.lang.Object lhs)
      Cube root of each element.
      static java.lang.Object ceil​(java.lang.Object lhs)  
      static java.lang.Object cos​(java.lang.Object lhs)  
      static java.lang.Object cosh​(java.lang.Object lhs)  
      static java.lang.Object cummax​(java.lang.Object lhs)  
      static java.lang.Object cummin​(java.lang.Object lhs)  
      static java.lang.Object cumprod​(java.lang.Object lhs)  
      static java.lang.Object cumsum​(java.lang.Object lhs)  
      static double distance​(java.lang.Object lhs, java.lang.Object rhs)  
      static double distanceSquared​(java.lang.Object lhs, java.lang.Object rhs)  
      static java.lang.Object div​(java.lang.Object lhs, java.lang.Object rhs)  
      static double dotProduct​(java.lang.Object lhs, java.lang.Object rhs)  
      static java.lang.Object eq​(java.lang.Object lhs, java.lang.Object rhs)
      Nan-aware eq operation returning buffer of booleans
      static java.lang.Object exp​(java.lang.Object lhs)  
      static java.lang.Object expm1​(java.lang.Object lhs)  
      static java.lang.Object floor​(java.lang.Object lhs)  
      static java.lang.Object greaterThan​(java.lang.Object lhs, java.lang.Object rhs)  
      static java.lang.Object greaterThan​(java.lang.Object lhs, java.lang.Object mid, java.lang.Object rhs)  
      static java.lang.Object greaterThanOrEq​(java.lang.Object lhs, java.lang.Object rhs)  
      static java.lang.Object greaterThanOrEq​(java.lang.Object lhs, java.lang.Object mid, java.lang.Object rhs)  
      static java.lang.Object IEEERemainder​(java.lang.Object lhs)  
      static java.lang.Object indexesWhere​(java.lang.Object lhs, java.lang.Object elemwiseComp)
      Given a IFn that returns boolean values, reindex lhs where elemwiseComp returned true.
      static boolean isEqual​(java.lang.Object lhs, java.lang.Object rhs)
      Return true if the distance between lhs and rhs is less than 0.001.
      static boolean isEqual​(java.lang.Object lhs, java.lang.Object rhs, double epsilon)
      Return true if the distance between lhs and rhs is less than epsilon.
      static java.lang.Object isFinite​(java.lang.Object lhs)  
      static java.lang.Object isInfinite​(java.lang.Object lhs)  
      static java.lang.Object isMathematicalInteger​(java.lang.Object lhs)  
      static java.lang.Object isNan​(java.lang.Object lhs)  
      static java.lang.Object lessThan​(java.lang.Object lhs, java.lang.Object rhs)  
      static java.lang.Object lessThan​(java.lang.Object lhs, java.lang.Object mid, java.lang.Object rhs)  
      static java.lang.Object lessThanOrEq​(java.lang.Object lhs, java.lang.Object rhs)  
      static java.lang.Object lessThanOrEq​(java.lang.Object lhs, java.lang.Object mid, java.lang.Object rhs)  
      static java.lang.Object log​(java.lang.Object lhs)  
      static java.lang.Object log1p​(java.lang.Object lhs)  
      static java.lang.Object logistic​(java.lang.Object lhs)  
      static double magnitude​(java.lang.Object lhs)  
      static double magnitudeSquared​(java.lang.Object lhs)  
      static java.lang.Object max​(java.lang.Object lhs, java.lang.Object rhs)  
      static double mean​(java.lang.Object data)
      High quality mean - drops NaN values and uses Kahan's compensation for summation.
      static double meanFast​(java.lang.Object data)
      Fast parallel naive mean.
      static java.lang.Object min​(java.lang.Object lhs, java.lang.Object rhs)  
      static java.lang.Object mul​(java.lang.Object lhs, java.lang.Object rhs)  
      static java.lang.Object neg​(java.lang.Object lhs)  
      static java.lang.Object not​(java.lang.Object lhs)
      Return complement of vector of booleans.
      static java.lang.Object notEq​(java.lang.Object lhs, java.lang.Object rhs)  
      static java.lang.Object pow​(java.lang.Object lhs)  
      static java.lang.Object quot​(java.lang.Object lhs)
      Integer divide.
      static java.lang.Object reduceMax​(java.lang.Object lhs)  
      static java.lang.Object reduceMin​(java.lang.Object lhs)  
      static java.lang.Object rem​(java.lang.Object lhs)
      Integer remainder
      static java.lang.Object round​(java.lang.Object lhs)  
      static java.lang.Object significand​(java.lang.Object lhs)  
      static java.lang.Object sin​(java.lang.Object lhs)  
      static java.lang.Object sinh​(java.lang.Object lhs)  
      static java.lang.Object sq​(java.lang.Object lhs)
      Square each element of lhs.
      static java.lang.Object sqrt​(java.lang.Object lhs)  
      static java.lang.Object sub​(java.lang.Object lhs, java.lang.Object rhs)  
      static double sum​(java.lang.Object data)
      High quality summation - drops NaN values and uses Kahan's compensated algorithm.
      static double sumFast​(java.lang.Object data)
      Fast parallel summation.
      static java.lang.Object tan​(java.lang.Object lhs)  
      static java.lang.Object tanh​(java.lang.Object lhs)  
      static java.lang.Object toDegrees​(java.lang.Object lhs)  
      static java.lang.Object toRadians​(java.lang.Object lhs)  
      static tech.v3.datatype.Buffer where​(java.lang.Object lhs, java.lang.Object elemwiseComp)
      Given a IFn that returns boolean values, reindex lhs where elemwiseComp returned true.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • booleansToIndexes

        public static java.lang.Object booleansToIndexes​(java.lang.Object boolVec)
        Efficiently convert a Buffer of boolean values to indexes that indicate where the true values are. After which you can reindex your buffer leaving only the values where the condition was true. Numeric buffers will be interpreted as boolean where anything that is zero is false else the value is true.
      • indexesWhere

        public static java.lang.Object indexesWhere​(java.lang.Object lhs,
                                                    java.lang.Object elemwiseComp)
        Given a IFn that returns boolean values, reindex lhs where elemwiseComp returned true. If elemwiseComp is an IFn, elemwiseComp is passed each element in lhs else elemwiseComp is interpreted as a boolean buffer.
        Returns:
        indexes where condition is true.
      • where

        public static tech.v3.datatype.Buffer where​(java.lang.Object lhs,
                                                    java.lang.Object elemwiseComp)
        Given a IFn that returns boolean values, reindex lhs where elemwiseComp returned true. If elemwiseComp is an IFn, elemwiseComp is passed each element in lhs else elemwiseComp is interpreted as a boolean buffer.
        Returns:
        - a possibly much shorter lhs.
      • add

        public static java.lang.Object add​(java.lang.Object lhs,
                                           java.lang.Object rhs)
      • neg

        public static java.lang.Object neg​(java.lang.Object lhs)
      • sub

        public static java.lang.Object sub​(java.lang.Object lhs,
                                           java.lang.Object rhs)
      • mul

        public static java.lang.Object mul​(java.lang.Object lhs,
                                           java.lang.Object rhs)
      • div

        public static java.lang.Object div​(java.lang.Object lhs,
                                           java.lang.Object rhs)
      • sq

        public static java.lang.Object sq​(java.lang.Object lhs)
        Square each element of lhs.
      • sqrt

        public static java.lang.Object sqrt​(java.lang.Object lhs)
      • cbrt

        public static java.lang.Object cbrt​(java.lang.Object lhs)
        Cube root of each element.
      • abs

        public static java.lang.Object abs​(java.lang.Object lhs)
      • pow

        public static java.lang.Object pow​(java.lang.Object lhs)
      • quot

        public static java.lang.Object quot​(java.lang.Object lhs)
        Integer divide.
      • rem

        public static java.lang.Object rem​(java.lang.Object lhs)
        Integer remainder
      • cos

        public static java.lang.Object cos​(java.lang.Object lhs)
      • acos

        public static java.lang.Object acos​(java.lang.Object lhs)
      • cosh

        public static java.lang.Object cosh​(java.lang.Object lhs)
      • sin

        public static java.lang.Object sin​(java.lang.Object lhs)
      • asin

        public static java.lang.Object asin​(java.lang.Object lhs)
      • sinh

        public static java.lang.Object sinh​(java.lang.Object lhs)
      • tan

        public static java.lang.Object tan​(java.lang.Object lhs)
      • atan

        public static java.lang.Object atan​(java.lang.Object lhs)
      • tanh

        public static java.lang.Object tanh​(java.lang.Object lhs)
      • toRadians

        public static java.lang.Object toRadians​(java.lang.Object lhs)
      • toDegrees

        public static java.lang.Object toDegrees​(java.lang.Object lhs)
      • isFinite

        public static java.lang.Object isFinite​(java.lang.Object lhs)
      • isInfinite

        public static java.lang.Object isInfinite​(java.lang.Object lhs)
      • isNan

        public static java.lang.Object isNan​(java.lang.Object lhs)
      • ceil

        public static java.lang.Object ceil​(java.lang.Object lhs)
      • floor

        public static java.lang.Object floor​(java.lang.Object lhs)
      • round

        public static java.lang.Object round​(java.lang.Object lhs)
      • significand

        public static java.lang.Object significand​(java.lang.Object lhs)
      • IEEERemainder

        public static java.lang.Object IEEERemainder​(java.lang.Object lhs)
      • isMathematicalInteger

        public static java.lang.Object isMathematicalInteger​(java.lang.Object lhs)
      • lessThan

        public static java.lang.Object lessThan​(java.lang.Object lhs,
                                                java.lang.Object rhs)
      • lessThan

        public static java.lang.Object lessThan​(java.lang.Object lhs,
                                                java.lang.Object mid,
                                                java.lang.Object rhs)
      • lessThanOrEq

        public static java.lang.Object lessThanOrEq​(java.lang.Object lhs,
                                                    java.lang.Object rhs)
      • lessThanOrEq

        public static java.lang.Object lessThanOrEq​(java.lang.Object lhs,
                                                    java.lang.Object mid,
                                                    java.lang.Object rhs)
      • greaterThan

        public static java.lang.Object greaterThan​(java.lang.Object lhs,
                                                   java.lang.Object rhs)
      • greaterThan

        public static java.lang.Object greaterThan​(java.lang.Object lhs,
                                                   java.lang.Object mid,
                                                   java.lang.Object rhs)
      • greaterThanOrEq

        public static java.lang.Object greaterThanOrEq​(java.lang.Object lhs,
                                                       java.lang.Object rhs)
      • greaterThanOrEq

        public static java.lang.Object greaterThanOrEq​(java.lang.Object lhs,
                                                       java.lang.Object mid,
                                                       java.lang.Object rhs)
      • eq

        public static java.lang.Object eq​(java.lang.Object lhs,
                                          java.lang.Object rhs)
        Nan-aware eq operation returning buffer of booleans
      • notEq

        public static java.lang.Object notEq​(java.lang.Object lhs,
                                             java.lang.Object rhs)
      • not

        public static java.lang.Object not​(java.lang.Object lhs)
        Return complement of vector of booleans.
      • max

        public static java.lang.Object max​(java.lang.Object lhs,
                                           java.lang.Object rhs)
      • reduceMax

        public static java.lang.Object reduceMax​(java.lang.Object lhs)
      • min

        public static java.lang.Object min​(java.lang.Object lhs,
                                           java.lang.Object rhs)
      • reduceMin

        public static java.lang.Object reduceMin​(java.lang.Object lhs)
      • exp

        public static java.lang.Object exp​(java.lang.Object lhs)
      • expm1

        public static java.lang.Object expm1​(java.lang.Object lhs)
      • log

        public static java.lang.Object log​(java.lang.Object lhs)
      • log1p

        public static java.lang.Object log1p​(java.lang.Object lhs)
      • logistic

        public static java.lang.Object logistic​(java.lang.Object lhs)
      • sum

        public static double sum​(java.lang.Object data)
        High quality summation - drops NaN values and uses Kahan's compensated algorithm.
        See Also:
        Stats
      • sumFast

        public static double sumFast​(java.lang.Object data)
        Fast parallel summation.
      • mean

        public static double mean​(java.lang.Object data)
        High quality mean - drops NaN values and uses Kahan's compensation for summation.
        See Also:
        Stats
      • meanFast

        public static double meanFast​(java.lang.Object data)
        Fast parallel naive mean.
      • distance

        public static double distance​(java.lang.Object lhs,
                                      java.lang.Object rhs)
      • distanceSquared

        public static double distanceSquared​(java.lang.Object lhs,
                                             java.lang.Object rhs)
      • magnitude

        public static double magnitude​(java.lang.Object lhs)
      • magnitudeSquared

        public static double magnitudeSquared​(java.lang.Object lhs)
      • dotProduct

        public static double dotProduct​(java.lang.Object lhs,
                                        java.lang.Object rhs)
      • cummin

        public static java.lang.Object cummin​(java.lang.Object lhs)
      • cummax

        public static java.lang.Object cummax​(java.lang.Object lhs)
      • cumsum

        public static java.lang.Object cumsum​(java.lang.Object lhs)
      • cumprod

        public static java.lang.Object cumprod​(java.lang.Object lhs)
      • isEqual

        public static boolean isEqual​(java.lang.Object lhs,
                                      java.lang.Object rhs,
                                      double epsilon)
        Return true if the distance between lhs and rhs is less than epsilon.
      • isEqual

        public static boolean isEqual​(java.lang.Object lhs,
                                      java.lang.Object rhs)
        Return true if the distance between lhs and rhs is less than 0.001.