-
Notifications
You must be signed in to change notification settings - Fork 21
Closed
Labels
Milestone
Description
Compiler raises a null pointer exception and runs into infinite loop of typechecker calls finally failing into stackoverflow error.
Problem raises with the new compiler(scala 2.12.8).
Scala version: 2.12.8
Sbt version: 1.2.8
Java version: 1.8.0_181
Please use the attached code and sbt compile
to reproduce the problem.
Any help would be greatly appreciated.
Trying code regeneration to build custom vector traits.
Output
[error] ## Exception when compiling 243 sources to /scalation_1.6/scalation_mathematics/target/scala-2.12/classes
[error] null
[error] scala.tools.nsc.typechecker.RefChecks$RefCheckTransformer.transform(RefChecks.scala:1702)
[error] scala.tools.nsc.typechecker.RefChecks$RefCheckTransformer.transform(RefChecks.scala:114)
[error] scala.reflect.internal.Trees.itransform(Trees.scala:1383)
[error] scala.reflect.internal.Trees.itransform$(Trees.scala:1372)
[error] scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:27)
[error] scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:27)
[error] scala.reflect.api.Trees$Transformer.transform(Trees.scala:2563)
[error] scala.tools.nsc.typechecker.RefChecks$RefCheckTransformer.transform(RefChecks.scala:1862)
[error] scala.tools.nsc.typechecker.RefChecks$RefCheckTransformer.transform(RefChecks.scala:114)
[error] scala.reflect.internal.Trees.itransform(Trees.scala:1381)
[error] scala.reflect.internal.Trees.itransform$(Trees.scala:1372)
[error] scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:27)
[error] scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:27)
[error] scala.reflect.api.Trees$Transformer.transform(Trees.scala:2563)
[error] scala.tools.nsc.typechecker.RefChecks$RefCheckTransformer.transform(RefChecks.scala:1862)
[error] scala.tools.nsc.typechecker.RefChecks$RefCheckTransformer.transform(RefChecks.scala:114)
[error] scala.reflect.internal.Trees.itransform(Trees.scala:1383)
[error] scala.reflect.internal.Trees.itransform$(Trees.scala:1372)
[error] scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:27)
[error] scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:27)
[error] scala.reflect.api.Trees$Transformer.transform(Trees.scala:2563)
[error] scala.tools.nsc.typechecker.RefChecks$RefCheckTransformer.transform(RefChecks.scala:1862)
[error] scala.tools.nsc.typechecker.RefChecks$RefCheckTransformer.transform(RefChecks.scala:114)
[error] scala.reflect.internal.Trees.itransform(Trees.scala:1381)
[error] scala.reflect.internal.Trees.itransform$(Trees.scala:1372)
[error] scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:27)
[error] scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:27)
[error] scala.reflect.api.Trees$Transformer.transform(Trees.scala:2563)
[error] scala.tools.nsc.typechecker.RefChecks$RefCheckTransformer.transform(RefChecks.scala:1862)
[error] scala.tools.nsc.typechecker.RefChecks$RefCheckTransformer.transform(RefChecks.scala:114)
[error] scala.reflect.internal.Trees.itransform(Trees.scala:1383)
[error] scala.reflect.internal.Trees.itransform$(Trees.scala:1372)
[error] scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:27)
[error] scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:27)
[error] scala.reflect.api.Trees$Transformer.transform(Trees.scala:2563)
[error] scala.tools.nsc.typechecker.RefChecks$RefCheckTransformer.transform(RefChecks.scala:1862)
[error] scala.tools.nsc.typechecker.RefChecks$RefCheckTransformer.transform(RefChecks.scala:114)
[error] scala.reflect.internal.Trees.itransform(Trees.scala:1381)
[error] scala.reflect.internal.Trees.itransform$(Trees.scala:1372)
[error] scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:27)
[error] scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:27)
[error] scala.reflect.api.Trees$Transformer.transform(Trees.scala:2563)
BldVecto.scala
import java.io.{File, PrintWriter}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** The `BldVecto` object is used to build vector traits for various base types.
* > runMain scalation.linalgebra.bld.BldVecto
*/
object BldVecto extends App with BldParams
{
println ("BldVecto: generate code for Vecto traits")
for (k <- kind) {
val VECTO = k._1
val VECTOR = k._1.replace ("o", "or")
val BASE = k._2
val BASE_LC = BASE.toLowerCase
val FORMAT = k._5
val EXPON = if (BASE == "Complex" || BASE == "Real") "Double" else BASE
val IMPORT = if (BASE == "StrNum") "scalation.math.StrO.{abs => ABS, max => MAX, _}"
else if (BASE == "TimeNum") "scalation.math.TimeO.{abs => ABS, max => MAX, _}"
else if (CUSTOM contains BASE) s"scalation.math.$BASE.{abs => ABS, max => MAX, _}"
else "scala.math.{abs => ABS, max => MAX, sqrt}"
val IMPORT2 = if (BASE == "StrNum") "scalation.math.StrO"
else if (BASE == "TimeNum") "scalation.math.TimeO"
else if (CUSTOM contains BASE) s"scalation.math.$BASE"
else s"scalation.math.${BASE_LC}_exp"
// Beginning of string holding code template -----------------------------------
val code = raw"""
package scalation.linalgebra
import scala.collection.Traversable
import scala.collection.mutable.IndexedSeq
import scala.util.Sorting.quickSort
import $IMPORT
import $IMPORT2
import scalation.util.Error
import scalation.util.SortingD.{iqsort, qsort2}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** The `$VECTO` class stores and operates on Numeric Vectors of base type `$BASE`.
* It follows the framework of `gen.VectorN [T]` and is provided for performance.
* @param dim the dimension/size of the vector
* @param v the 1D array used to store vector elements
*/
trait $VECTO
extends Traversable [$BASE] with PartiallyOrdered [$VECTO] with Vec with Error with Serializable
{
/** Vector dimension
*/
val dim: Int
/** Number of elements in the vector as a $BASE
*/
val nd = dim.toDouble
/** Range for the storage array
*/
val range = 0 until dim
/** Format String used for printing vector values (change using 'setFormat')
* Ex: "%d,\t", "%.6g,\t" or "%12.6g,\t"
*/
protected var fString = "$FORMAT,\t"
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Return the size (number of elements) of 'this' vector.
*/
override def size: Int = dim
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Produce the range of all indices (0 to one less than dim).
*/
def indices: Range = 0 until dim
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Expand the size (dim) of 'this' vector by 'more' elements.
* @param more the number of new elements to add
*/
def expand (more: Int = dim): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Create a zero vector (all elements are zero) of length 'size'.
* @param size the size of the new vector
*/
def zero (size: Int): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Create a one vector (all elements are one) of length 'size'.
* @param size the size of the new vector
*/
def one (size: Int): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Create a vector of the form (0, ... 1, ... 0) where the 1 is at position j.
* @param j the position to place the 1
* @param size the size of the vector (upper bound = size - 1)
*/
def oneAt (j: Int, size: Int = dim): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Create a vector of the form (0, ... -1, ... 0) where the -1 is at position j.
* @param j the position to place the -1
* @param size the size of the vector (upper bound = size - 1)
*/
def _oneAt (j: Int, size: Int = dim): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Convert 'this' `$VECTO` into a `VectoI`.
*/
def toInt: VectoI
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Convert 'this' `$VECTO` into a `VectoL`.
*/
def toLong: VectoL
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Convert 'this' `$VECTO` into a `VectoD`.
*/
def toDouble: VectoD
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Convert 'this' `$VECTO` into a dense version.
*/
def toDense: $VECTOR
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Get 'this' vector's element at the 'i'-th index position.
* @param i the given index
*/
def apply (i: Int): $BASE
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Get 'this' vector's elements within the given range (vector slicing).
* @param r the given range
*/
def apply (r: Range): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Get 'this' vector's entire sequence/array.
*/
def apply (): IndexedSeq [$BASE]
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Get 'this' vector's elements that are given in the index vector.
* @param iv the index vector
*/
def apply (iv: VectoI): $VECTO = ???
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Set 'this' vector's element at the 'i'-th index position.
* @param i the given index
* @param x the value to assign
*/
def update (i: Int, x: $BASE)
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Set 'this' vector's elements over the given range (vector slicing).
* @param r the given range
* @param x the value to assign
*/
def update (r: Range, x: $BASE)
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Set 'this' vector's elements over the given range (vector slicing).
* @param r the given range
* @param u the vector to assign
*/
def update (r: Range, u: $VECTO)
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Iterate over 'this' vector element by element.
* @param f the function to apply
*/
def foreach [U] (f: $BASE => U)
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Set each value in 'this' vector to 'x'.
* @param x the value to be assigned
*/
def set (x: $BASE)
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Set the values in 'this' vector to the values in sequence 'u'.
* @param u the sequence of values to be assigned
*/
def set (u: Seq [$BASE])
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Create a copy of this Vector.
*/
def copy: $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Filter the elements of 'this' vector based on the predicate 'p', returning
* a new vector.
* @param p the predicate (`Boolean` function) to apply
*/
// def filter (p: $BASE => Boolean): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Filter out the missing elements of 'this' vector based on the predicate
* that 'e != no$BASE'.
*/
def filterMissing: $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Filter the elements of 'this' vector based on the unary predicate 'p',
* returning the index positions.
* @param p the unary predicate (`Boolean` function) to apply
*/
def filterPos (p: $BASE => Boolean): IndexedSeq [Int]
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Filter the elements of 'this' vector and vector 'v2' based on the binary
* predicate 'p', returning the index positions for both vectors.
* @param v2 the other vector to compare with
* @param p the binary predicate (`Boolean` function) to apply
*/
def filterPos2 (v2: $VECTO, p: ($BASE, $BASE) => Boolean): IndexedSeq [(Int, Int)]
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Map the elements of 'this' vector by applying the mapping function 'f'.
* @param f the function to apply
*/
def map (f: $BASE => $BASE): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Slice 'this' vector 'from' to 'end'. Override in implementing classes.
* @param from the start of the slice (included)
* @param till the end of the slice (excluded)
*/
override def slice (from: Int, till: Int = dim): $VECTO = null
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Slice 'this' vector over the given range 'rg'.
* @param rg the range specifying the slice
*/
def slice (rg: Range): $VECTO = slice (rg.start, rg.end)
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Slice 'this' vector excluding the given range 'rg'.
* @param rg the excluded range of the slice
*/
def sliceEx (rg: Range): $VECTO = slice (0, rg.start) ++ slice (rg.end, dim)
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Split 'this' vector into 'k' arrays of equal sizes (perhaps except for the last one).
* @param k the number of pieces the vector is to be split into
*/
def split (k: Int): Array [$VECTO] = null
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Select a subset of elements of 'this' vector corresponding to a 'basis'.
* @param basis the set of index positions (e.g., 0, 2, 5)
*/
def select (basis: Array [Int]): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Select all elements of 'this' vector excluding ones in the 'basis'.
* @param basis the index positions to be excluded
*/
def selectEx (basis: Array [Int]): $VECTO = select ((range diff basis).toArray)
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Concatenate 'this' vector and vector' b'.
* @param b the vector to be concatenated
*/
def ++ (b: $VECTO): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Concatenate 'this' vector and scalar 's'.
* @param s the scalar to be concatenated
*/
def ++ (s: $BASE): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Add 'this' vector and vector 'b'.
* @param b the vector to add
*/
def + (b: $VECTO): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Add 'this' vector and scalar 's'.
* @param s the scalar to add
*/
def + (s: $BASE): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Add 'this' vector and scalar 's._2' only at position 's._1', e.g., 'x + (3, 5.5)'.
* @param s the (position, scalar) to add
*/
def + (s: (Int, $BASE)): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Add in-place 'this' vector and vector 'b'.
* @param b the vector to add
*/
def += (b: $VECTO): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Add in-place 'this' vector and scalar 's'.
* @param s the scalar to add
*/
def += (s: $BASE): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Return the negative of 'this' vector (unary minus).
*/
def unary_- (): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** From 'this' vector subtract vector 'b'.
* @param b the vector to subtract
*/
def - (b: $VECTO): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** From 'this' vector subtract scalar 's'.
* @param s the scalar to subtract
*/
def - (s: $BASE): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** From 'this' vector subtract scalar 's._2' only at position 's._1', e.g., 'x - (3, 5.5)'.
* @param s the (position, scalar) to subtract
*/
def - (s: (Int, $BASE)): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** From 'this' vector subtract in-place vector 'b'.
* @param b the vector to subtract
*/
def -= (b: $VECTO): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** From 'this' vector subtract in-place scalar 's'.
* @param s the scalar to substract
*/
def -= (s: $BASE): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Multiply 'this' vector by vector 'b'.
* @param b the vector to multiply by
*/
def * (b: $VECTO): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Multiply 'this' vector by scalar 's'.
* @param s the scalar to multiply by
*/
def * (s: $BASE): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Multiply 'this' vector by scalar 's._2' only at position 's._1', e.g., 'x * (3, 5.5)'.
* @param s the (position, scalar) to multiply
*/
def * (s: (Int, $BASE)): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Multiply in-place 'this' vector and vector 'b'.
* @param b the vector to multiply by
*/
def *= (b: $VECTO): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Multiply in-place 'this' vector and scalar 's'.
* @param s the scalar to multiply by
*/
def *= (s: $BASE): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Divide 'this' vector by vector 'b' (element-by-element).
* @param b the vector to divide by
*/
def / (b: $VECTO): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Divide 'this' vector by scalar 's'.
* @param s the scalar to divide by
*/
def / (s: $BASE): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Divide 'this' vector by scalar 's._2' only at position 's._1', e.g., 'x / (3, 5.5)'.
* @param s the (position, scalar) to divide
*/
def / (s: (Int, $BASE)): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Divide in-place 'this' vector and vector 'b'.
* @param b the vector to divide by
*/
def /= (b: $VECTO): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Divide in-place 'this' vector and scalar 's'.
* @param s the scalar to divide by
*/
def /= (s: $BASE): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Return the vector containing each element of 'this' vector raised to the
* s-th power.
* @param s the scalar exponent
*/
def ~^ (s: $EXPON): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Raise in-place each element of 'this' vector to the 's'-th power.
* @param s the scalar exponent
*/
def ~^= (s: $EXPON): $VECTO
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Compare 'this' vector with that vector 'b' for inequality.
* @param b that vector
*/
def ≠ (b: $VECTO) = this != b
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Compare 'this' vector with that vector 'b' for less than or equal to.
* @param b that vector
*/
def ≤ (b: $VECTO) = this <= b
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Compare 'this' vector with that vector 'b' for greater than or equal to.
* @param b that vector
*/
def ≥ (b: $VECTO) = this >= b
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Return the vector containing the square of each element of 'this' vector.
*/
def sq: $VECTO = this * this
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Return the vector containing the reciprocal of each element of 'this' vector.
*/
def recip: $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Return the vector that is the element-wise absolute value of 'this' vector.
*/
def abs: $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Sum the elements of 'this' vector.
*/
def sum: $BASE
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Sum the elements of 'this' vector skipping the 'i'-th element (Not Equal 'i').
* @param i the index of the element to skip
*/
def sumNE (i: Int): $BASE
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Sum the positive (> 0) elements of 'this' vector.
*/
def sumPos: $BASE
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Compute the mean of the elements of 'this' vector.
*/
def mean = sum / nd
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Compute the (unbiased) sample variance of the elements of 'this' vector.
*/
def variance = (normSq - sum * sum / nd) / (nd-1.0)
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Compute the population variance of the elements of 'this' vector.
* This is also the (biased) MLE estimator for sample variance.
*/
def pvariance = (normSq - sum * sum / nd) / nd
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Establish the rank order of the elements in 'self' vector, e.g.,
* (8.0, 2.0, 4.0, 6.0) is (3, 0, 1, 2).
*/
def rank: VectoI
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Cumulate the values of 'this' vector from left to right (e.g., create a
* CDF from a pmf). Example: (4, 2, 3, 1) --> (4, 6, 9, 10)
*/
def cumulate: $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Normalize 'this' vector so that it sums to one (like a probability vector).
*/
def normalize: $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Normalize 'this' vector so its length is one (unit vector).
*/
def normalizeU: $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Normalize 'this' vector to have a maximum of one.
*/
def normalize1: $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Compute the dot product (or inner product) of 'this' vector with vector 'b'.
* @param b the other vector
*/
def dot (b: $VECTO): $BASE
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Compute the dot product (or inner product) of 'this' vector with vector 'b'.
* @param b the other vector
*/
def ∙ (b: $VECTO): $BASE = this dot b
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Compute the Euclidean norm (2-norm) squared of 'this' vector.
*/
def normSq: $BASE = this dot this
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Compute the Euclidean norm (2-norm) of 'this' vector.
*/
def norm: $BASE = sqrt (normSq).to$BASE
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Compute the Manhattan norm (1-norm) of 'this' vector.
*/
def norm1: $BASE
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Find the maximum element in 'this' vector.
* @param e the ending index (exclusive) for the search
*/
def max (e: Int = dim): $BASE
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Take the maximum of 'this' vector with vector 'b' (element-by element).
* @param b the other vector
*/
def max (b: $VECTO): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Find the minimum element in 'this' vector.
* @param e the ending index (exclusive) for the search
*/
def min (e: Int = dim): $BASE
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Take the minimum of 'this' vector with vector 'b' (element-by element).
* @param b the other vector
*/
def min (b: $VECTO): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Find the element with the greatest magnitude in 'this' vector.
*/
def mag: $BASE = ABS (max ()) max ABS (min ())
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Find the argument maximum of 'this' vector (index of maximum element).
* @param e the ending index (exclusive) for the search
*/
def argmax (e: Int = dim): Int
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Find the argument maximum of 'this' vector (index of maximum element).
* @param s the starting index (inclusive) for the search
* @param e the ending index (exclusive) for the search
*/
def argmax (s: Int, e: Int): Int
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Find the argument minimum of 'this' vector (index of minimum element).
* @param e the ending index (exclusive) for the search
*/
def argmin (e: Int = dim): Int
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Find the argument minimum of 'this' vector (index of minimum element).
* @param s the starting index (inclusive) for the search
* @param e the ending index (exclusive) for the search
*/
def argmin (s: Int, e: Int): Int
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Return the argument minimum of 'this' vector (-1 if it's not negative).
* @param e the ending index (exclusive) for the search
*/
def argminNeg (e: Int = dim): Int
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Return the argument maximum of 'this' vector (-1 if it's not positive).
* @param e the ending index (exclusive) for the search
*/
def argmaxPos (e: Int = dim): Int
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Return the index of the first negative element in 'this' vector (-1 otherwise).
* @param e the ending index (exclusive) for the search
*/
def firstNeg (e: Int = dim): Int
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Return the index of the first positive element in 'this' vector (-1 otherwise).
* @param e the ending index (exclusive) for the search
*/
def firstPos (e: Int = dim): Int
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Return the index of the first occurrence of element 'x' in 'this' vector,
* or -1 if not found.
* @param x the given element
* @param e the ending index (exclusive) for the search
*/
def indexOf (x: $BASE, e: Int = dim): Int
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Find and return index of first element satisfying predicate 'p', or
* -1 if not found.
* @param p the predicate to check
*/
def indexWhere (p: ($BASE) => Boolean): Int
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Count the number of strictly negative elements in 'this' vector.
*/
def countNeg: Int
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Count the number of strictly positive elements in 'this' vector.
*/
def countPos: Int
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Count the number of zero elements in the 'this' vector.
*/
def countZero: Int
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Create a vector consisting of the distinct elements in 'this' vector.
*/
def distinct: $VECTO
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Count the number of distinct elements in 'this' vector.
*/
def countinct: Int
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Determine whether 'x' is contained in 'this' vector.
* @param x the element to be checked
*/
def contains (x: $BASE): Boolean
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Reverse the order of the elements in 'this' vector.
*/
def reverse (): $VECTO
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Determine whether 'this' vector is in sorted (ascending) order.
*/
def isSorted: Boolean
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Sort 'this' vector in-place in ascending (non-decreasing) order.
*/
def sort ()
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Sort 'this' vector in-place in descending (non-increasing) order.
*/
def sort2 ()
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Swap elements 'i' and 'j' in 'this' vector.
* @param i the first element in the swap
* @param j the second element in the swap
*/
def swap (i: Int, j: Int)
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Check whether the other vector 'b' is at least as long as 'this' vector.
* @param b the other vector
*/
def sameDimensions (b: $VECTO): Boolean = dim <= b.dim
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Check whether 'this' vector is nonnegative (has no negative elements).
*/
def isNonnegative: Boolean
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Compare 'this' vector with vector 'b'.
* @param b the other vector
*/
// private def tryCompareTo [B >: $VECTO] (b: B)
// (implicit view_1: (B) => PartiallyOrdered [B]): Option [Int]
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Override equals to determine whether 'this' vector equals vector 'b..
* @param b the vector to compare with this
*/
override def equals (b: Any): Boolean
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Must also override hashCode for 'this' vector to be compatible with equals.
*/
override def hashCode (): Int
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Set the format to the 'newFormat' (e.g., "%.6g,\t" or "%12.6g,\t").
* @param newFormat the new format String
*/
def setFormat (newFormat: String) { fString = newFormat }
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** Convert 'this' vector to a String.
*/
override def toString: String
} // $VECTO trait
"""
// Ending of string holding code template --------------------------------------
// println (code)
val writer = new PrintWriter (new File (DIR + _l + VECTO + ".scalaa"))
writer.write (code)
writer.close ()
} // for
} // BldVecto object
BldParams
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** The `BldParams` trait defines common values to be used in code generation.
* Base trait for numeric vectors is Vecto_, with classes Vector_, RleVector_ and
* SparseVector_.
* Base trait for matrices is Matri_, with classes BidMatrix_, Matrix_, RleMatrix_,
* SparseMatrix_ and SymTriMatrix_.
*/
trait BldParams
{
/** Shorthand for universal file separator ('/' or '\\').
*/
val _l = java.io.File.separator
/** Directory in which to place the generated code.
*/
val DIR = s"src${_l}main${_l}scala${_l}scalation${_l}linalgebra${_l}bld"
/** Specifications for each base type _ = (I, L, D, R, Q, C, S).
*/
// VECTO BASE VECTOR2 BASE2 FORMAT MATRI SORTING ZERO ONE REGEX
val kind = Array (("VectoI", "Int", "VectoD", "Double", "%d", "MatriI", "SortingI", "0", "1", """"[\\-\\+]?\\d+""""),
("VectoL", "Long", "VectoD", "Double", "%d", "MatriL", "SortingL", "0l", "1l", """"[\\-\\+]?\\d+""""),
("VectoD", "Double", "VectoI", "Int", "%g", "MatriD", "SortingD", "0.0", "1.0", """"[\\-\\+]?\\d*(\\.\\d+)?""""),
("VectoR", "Real", "VectoD", "Double", "%s", "MatriR", "SortingR", "_0", "_1", """"[\\-\\+]?\\d*(\\.\\d+)?""""),
("VectoQ", "Rational", "VectoD", "Double", "%s", "MatriQ", "SortingQ", "_0", "_1", """"[\\-\\+]?\\d+(/[\\-\\+]?\\d+)?""""),
("VectoC", "Complex", "VectoD", "Double", "%s", "MatriC", "SortingC", "_0", "_1", """"[\\-\\+]?\\d*(\\.\\d+)?(\\+[\\-\\+]?\\d*(\\.\\d+)?)?i""""),
("VectoS", "StrNum", "VectoI", "Int", "%s", "MatriS", "SortingS", "_0", "_1", """"\\s*""""),
("VectoT", "TimeNum", "VectoL", "Long", "%s", "MatriT", "SortingT", "_0", "_1", """"\\s*""""))
/** Set of custom base types provided by Scalation.
* @see scalation.math
*/
val CUSTOM = Set ("Complex", "Rational", "Real", "StrNum", "TimeNum")
} // BldParams trait
jxtps