diff --git a/.travis.yml b/.travis.yml index 6366188..8dc1aa1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,3 +7,10 @@ jdk: - oraclejdk7 - oraclejdk8 - openjdk7 + +env: + matrix: + - SCALA_VERSION=2.10 + - SCALA_VERSION=2.11 + +script: "mvn clean install -P scala-${SCALA_VERSION}" diff --git a/README.md b/README.md index 30c1985..94cc402 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,7 @@ Scala implementation of Histogrammar See [histogrammar.org](http://histogrammar.org) for a complete introduction to Histogrammar. -This is a Scala implementation for Scala version 2.10. - -**FIXME:** add tests (and check implementation) for Scala 2.11. It should work, but still. +This is a Scala implementation for Scala versions 2.10 and 2.11. Installation ============ @@ -13,7 +11,13 @@ Installation Histogrammar has a standard Maven POM. With Maven 3+, run ```bash -mvn install +mvn install -P scala-2.10 +``` + +or + +```bash +mvn install -P scala-2.11 ``` in the base directory (to compile everything) or one of the subdirectories. All subdirectories depend on `core`, so this must be installed first. diff --git a/bokeh/pom.xml b/bokeh/pom.xml index 70e3a9b..de99d7f 100644 --- a/bokeh/pom.xml +++ b/bokeh/pom.xml @@ -20,7 +20,7 @@ 2016 org.diana-hep - histogrammar-bokeh + histogrammar-bokeh_${scala.binary.version} 1.0.0 jar @@ -32,11 +32,35 @@ + + + scala-2.10 + + !scala-2.11 + + + 2.10.6 + 2.10 + 1.7 + 1.7 + + + + + scala-2.11 + + scala-2.11 + + + 2.11.8 + 2.11 + 1.8 + 1.8 + + + + - 1.7 - 1.7 - 2.10 - 2.10.5 UTF-8 UTF-8 @@ -50,13 +74,13 @@ org.diana-hep - histogrammar + histogrammar_${scala.binary.version} 1.0.0 io.continuum.bokeh - bokeh_${scala.tools.version} + bokeh_${scala.binary.version} 0.6 provided @@ -73,7 +97,7 @@ net.alchim31.maven scala-maven-plugin - 3.2.1 + 3.2.2 diff --git a/bokeh/src/main/scala/org/dianahep/histogrammar/bokeh.scala b/bokeh/src/main/scala/org/dianahep/histogrammar/bokeh.scala index 0f8f390..23fd9f8 100644 --- a/bokeh/src/main/scala/org/dianahep/histogrammar/bokeh.scala +++ b/bokeh/src/main/scala/org/dianahep/histogrammar/bokeh.scala @@ -346,24 +346,24 @@ package object bokeh extends Tools { //////////////////////////////////////////////////////////////// methods for FractionedHistogram - implicit def anyBinnedToFractionedHistogramMethodsBokeh[U <: Container[U] with NoAggregation, O <: Container[O] with NoAggregation, N <: Container[N] with NoAggregation](hist: Fractioned[Binned[Counted, U, O, N]]): FractionedHistogramMethodsBokeh = + implicit def anyBinnedToFractionedHistogramMethodsBokeh[U <: Container[U] with NoAggregation, O <: Container[O] with NoAggregation, N <: Container[N] with NoAggregation](hist: Fractioned[Binned[Counted, U, O, N], Binned[Counted, U, O, N]]): FractionedHistogramMethodsBokeh = new FractionedHistogramMethodsBokeh(anyBinnedToFractionedHistogramMethods(hist).fractioned) implicit def anyBinningToFractionedHistogramMethodsBokeh[DATUM, U <: Container[U] with Aggregation{type Datum >: DATUM}, O <: Container[O] with Aggregation{type Datum >: DATUM}, N <: Container[N] with Aggregation{type Datum >: DATUM}](hist: Fractioning[DATUM, Binning[DATUM, Counting, U, O, N]]): FractionedHistogramMethodsBokeh = new FractionedHistogramMethodsBokeh(anyBinningToFractionedHistogramMethods(hist).fractioned) - implicit def anySelectedBinnedToFractionedHistogramMethodsBokeh[U <: Container[U] with NoAggregation, O <: Container[O] with NoAggregation, N <: Container[N] with NoAggregation](hist: Fractioned[Selected[Binned[Counted, U, O, N]]]): FractionedHistogramMethodsBokeh = + implicit def anySelectedBinnedToFractionedHistogramMethodsBokeh[U <: Container[U] with NoAggregation, O <: Container[O] with NoAggregation, N <: Container[N] with NoAggregation](hist: Fractioned[Selected[Binned[Counted, U, O, N]], Selected[Binned[Counted, U, O, N]]]): FractionedHistogramMethodsBokeh = new FractionedHistogramMethodsBokeh(anySelectedBinnedToFractionedHistogramMethods(hist).fractioned) implicit def anySelectingBinningToFractionedHistogramMethodsBokeh[DATUM, U <: Container[U] with Aggregation{type Datum >: DATUM}, O <: Container[O] with Aggregation{type Datum >: DATUM}, N <: Container[N] with Aggregation{type Datum >: DATUM}](hist: Fractioning[DATUM, Selecting[DATUM, Binning[DATUM, Counting, U, O, N]]]): FractionedHistogramMethodsBokeh = new FractionedHistogramMethodsBokeh(anySelectingBinningToFractionedHistogramMethods(hist).fractioned) - implicit def anySparselyBinnedToFractionedHistogramMethodsBokeh[N <: Container[N] with NoAggregation](hist: Fractioned[SparselyBinned[Counted, N]]): FractionedHistogramMethodsBokeh = + implicit def anySparselyBinnedToFractionedHistogramMethodsBokeh[N <: Container[N] with NoAggregation](hist: Fractioned[SparselyBinned[Counted, N], SparselyBinned[Counted, N]]): FractionedHistogramMethodsBokeh = new FractionedHistogramMethodsBokeh(anySparselyBinnedToFractionedHistogramMethods(hist).fractioned) implicit def anySparselyBinningToFractionedHistogramMethodsBokeh[DATUM, N <: Container[N] with Aggregation{type Datum >: DATUM}](hist: Fractioning[DATUM, SparselyBinning[DATUM, Counting, N]]): FractionedHistogramMethodsBokeh = new FractionedHistogramMethodsBokeh(anySparselyBinningToFractionedHistogramMethods(hist).fractioned) - implicit def anySelectedSparselyBinnedToFractionedHistogramMethodsBokeh[N <: Container[N] with NoAggregation](hist: Fractioned[Selected[SparselyBinned[Counted, N]]]): FractionedHistogramMethodsBokeh = + implicit def anySelectedSparselyBinnedToFractionedHistogramMethodsBokeh[N <: Container[N] with NoAggregation](hist: Fractioned[Selected[SparselyBinned[Counted, N]], Selected[SparselyBinned[Counted, N]]]): FractionedHistogramMethodsBokeh = new FractionedHistogramMethodsBokeh(anySelectedSparselyBinnedToFractionedHistogramMethods(hist).fractioned) implicit def anySelectingSparselyBinningToFractionedHistogramMethodsBokeh[DATUM, N <: Container[N] with Aggregation{type Datum >: DATUM}](hist: Fractioning[DATUM, Selecting[DATUM, SparselyBinning[DATUM, Counting, N]]]): FractionedHistogramMethodsBokeh = new FractionedHistogramMethodsBokeh(anySelectingSparselyBinningToFractionedHistogramMethods(hist).fractioned) - class FractionedHistogramMethodsBokeh(val fractioned: Fractioned[Selected[Binned[Counted, Counted, Counted, Counted]]]) + class FractionedHistogramMethodsBokeh(val fractioned: Fractioned[Selected[Binned[Counted, Counted, Counted, Counted]], Selected[Binned[Counted, Counted, Counted, Counted]]]) //////////////////////////////////////////////////////////////// methods for TwoDimensionallyHistogram and TwoDimensionallySparselyHistogram diff --git a/core/pom.xml b/core/pom.xml index cf77ea6..d5fd472 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -20,7 +20,7 @@ 2016 org.diana-hep - histogrammar + histogrammar_${scala.binary.version} 1.0.0 jar @@ -32,6 +32,34 @@ + + + scala-2.10 + + !scala-2.11 + + + 2.10.6 + 2.10 + 1.7 + 1.7 + + + + + scala-2.11 + + scala-2.11 + + + 2.11.8 + 2.11 + 1.8 + 1.8 + + + + @@ -43,10 +71,6 @@ - 1.7 - 1.7 - 2.10 - 2.10.5 UTF-8 UTF-8 @@ -60,8 +84,8 @@ org.scalatest - scalatest_${scala.tools.version} - 2.2.6 + scalatest_${scala.binary.version} + 2.2.5 test @@ -77,7 +101,7 @@ net.alchim31.maven scala-maven-plugin - 3.2.1 + 3.2.2 diff --git a/core/src/main/scala/org/dianahep/histogrammar/ascii.scala b/core/src/main/scala/org/dianahep/histogrammar/ascii.scala index b1e5200..e991817 100644 --- a/core/src/main/scala/org/dianahep/histogrammar/ascii.scala +++ b/core/src/main/scala/org/dianahep/histogrammar/ascii.scala @@ -362,24 +362,24 @@ package object ascii { //////////////////////////////////////////////////////////////// methods for FractionedHistogram - implicit def anyBinnedToFractionedHistogramMethodsAscii[U <: Container[U] with NoAggregation, O <: Container[O] with NoAggregation, N <: Container[N] with NoAggregation](hist: Fractioned[Binned[Counted, U, O, N]]): FractionedHistogramMethodsAscii = + implicit def anyBinnedToFractionedHistogramMethodsAscii[U <: Container[U] with NoAggregation, O <: Container[O] with NoAggregation, N <: Container[N] with NoAggregation](hist: Fractioned[Binned[Counted, U, O, N], Binned[Counted, U, O, N]]): FractionedHistogramMethodsAscii = new FractionedHistogramMethodsAscii(anyBinnedToFractionedHistogramMethods(hist).fractioned) implicit def anyBinningToFractionedHistogramMethodsAscii[DATUM, U <: Container[U] with Aggregation{type Datum >: DATUM}, O <: Container[O] with Aggregation{type Datum >: DATUM}, N <: Container[N] with Aggregation{type Datum >: DATUM}](hist: Fractioning[DATUM, Binning[DATUM, Counting, U, O, N]]): FractionedHistogramMethodsAscii = new FractionedHistogramMethodsAscii(anyBinningToFractionedHistogramMethods(hist).fractioned) - implicit def anySelectedBinnedToFractionedHistogramMethodsAscii[U <: Container[U] with NoAggregation, O <: Container[O] with NoAggregation, N <: Container[N] with NoAggregation](hist: Fractioned[Selected[Binned[Counted, U, O, N]]]): FractionedHistogramMethodsAscii = + implicit def anySelectedBinnedToFractionedHistogramMethodsAscii[U <: Container[U] with NoAggregation, O <: Container[O] with NoAggregation, N <: Container[N] with NoAggregation](hist: Fractioned[Selected[Binned[Counted, U, O, N]], Selected[Binned[Counted, U, O, N]]]): FractionedHistogramMethodsAscii = new FractionedHistogramMethodsAscii(anySelectedBinnedToFractionedHistogramMethods(hist).fractioned) implicit def anySelectingBinningToFractionedHistogramMethodsAscii[DATUM, U <: Container[U] with Aggregation{type Datum >: DATUM}, O <: Container[O] with Aggregation{type Datum >: DATUM}, N <: Container[N] with Aggregation{type Datum >: DATUM}](hist: Fractioning[DATUM, Selecting[DATUM, Binning[DATUM, Counting, U, O, N]]]): FractionedHistogramMethodsAscii = new FractionedHistogramMethodsAscii(anySelectingBinningToFractionedHistogramMethods(hist).fractioned) - implicit def anySparselyBinnedToFractionedHistogramMethodsAscii[N <: Container[N] with NoAggregation](hist: Fractioned[SparselyBinned[Counted, N]]): FractionedHistogramMethodsAscii = + implicit def anySparselyBinnedToFractionedHistogramMethodsAscii[N <: Container[N] with NoAggregation](hist: Fractioned[SparselyBinned[Counted, N], SparselyBinned[Counted, N]]): FractionedHistogramMethodsAscii = new FractionedHistogramMethodsAscii(anySparselyBinnedToFractionedHistogramMethods(hist).fractioned) implicit def anySparselyBinningToFractionedHistogramMethodsAscii[DATUM, N <: Container[N] with Aggregation{type Datum >: DATUM}](hist: Fractioning[DATUM, SparselyBinning[DATUM, Counting, N]]): FractionedHistogramMethodsAscii = new FractionedHistogramMethodsAscii(anySparselyBinningToFractionedHistogramMethods(hist).fractioned) - implicit def anySelectedSparselyBinnedToFractionedHistogramMethodsAscii[N <: Container[N] with NoAggregation](hist: Fractioned[Selected[SparselyBinned[Counted, N]]]): FractionedHistogramMethodsAscii = + implicit def anySelectedSparselyBinnedToFractionedHistogramMethodsAscii[N <: Container[N] with NoAggregation](hist: Fractioned[Selected[SparselyBinned[Counted, N]], Selected[SparselyBinned[Counted, N]]]): FractionedHistogramMethodsAscii = new FractionedHistogramMethodsAscii(anySelectedSparselyBinnedToFractionedHistogramMethods(hist).fractioned) implicit def anySelectingSparselyBinningToFractionedHistogramMethodsAscii[DATUM, N <: Container[N] with Aggregation{type Datum >: DATUM}](hist: Fractioning[DATUM, Selecting[DATUM, SparselyBinning[DATUM, Counting, N]]]): FractionedHistogramMethodsAscii = new FractionedHistogramMethodsAscii(anySelectingSparselyBinningToFractionedHistogramMethods(hist).fractioned) - class FractionedHistogramMethodsAscii(val fractioned: Fractioned[Selected[Binned[Counted, Counted, Counted, Counted]]]) { + class FractionedHistogramMethodsAscii(val fractioned: Fractioned[Selected[Binned[Counted, Counted, Counted, Counted]], Selected[Binned[Counted, Counted, Counted, Counted]]]) { /** Print an ASCII representation of a histogram for debugging on headless systems. Limited to 80 columns. */ def println { println({(n: Double, d: Double, z: Double) => n/d}, 80) diff --git a/core/src/main/scala/org/dianahep/histogrammar/defs.scala b/core/src/main/scala/org/dianahep/histogrammar/defs.scala index 65e1779..3b28b9f 100644 --- a/core/src/main/scala/org/dianahep/histogrammar/defs.scala +++ b/core/src/main/scala/org/dianahep/histogrammar/defs.scala @@ -510,7 +510,7 @@ package object histogrammar { } implicit class StringIndex(val string: String) extends CollectionIndex { - override def toString() = "\"" + scala.util.parsing.json.JSONFormat.quoteString(string) + "\"" + override def toString() = "\"" + string + "\"" } object StringIndex { def unapply(x: StringIndex) = Some(x.string) @@ -1049,32 +1049,32 @@ package object histogrammar { //////////////////////////////////////////////////////////////// methods for FractionedHistogram - implicit def anyBinnedToFractionedHistogramMethods[U <: Container[U] with NoAggregation, O <: Container[O] with NoAggregation, N <: Container[N] with NoAggregation](hist: Fractioned[Binned[Counted, U, O, N]]): FractionedHistogramMethods = + implicit def anyBinnedToFractionedHistogramMethods[U <: Container[U] with NoAggregation, O <: Container[O] with NoAggregation, N <: Container[N] with NoAggregation](hist: Fractioned[Binned[Counted, U, O, N], Binned[Counted, U, O, N]]): FractionedHistogramMethods = new FractionedHistogramMethods(new Fractioned(hist.entries, hist.quantityName, anyBinnedToHistogramMethods(hist.numerator).selected, anyBinnedToHistogramMethods(hist.denominator).selected)) implicit def anyBinningToFractionedHistogramMethods[DATUM, U <: Container[U] with Aggregation{type Datum >: DATUM}, O <: Container[O] with Aggregation{type Datum >: DATUM}, N <: Container[N] with Aggregation{type Datum >: DATUM}](hist: Fractioning[DATUM, Binning[DATUM, Counting, U, O, N]]): FractionedHistogramMethods = anyBinnedToFractionedHistogramMethods(hist.toImmutable) - implicit def anySelectedBinnedToFractionedHistogramMethods[U <: Container[U] with NoAggregation, O <: Container[O] with NoAggregation, N <: Container[N] with NoAggregation](hist: Fractioned[Selected[Binned[Counted, U, O, N]]]): FractionedHistogramMethods = + implicit def anySelectedBinnedToFractionedHistogramMethods[U <: Container[U] with NoAggregation, O <: Container[O] with NoAggregation, N <: Container[N] with NoAggregation](hist: Fractioned[Selected[Binned[Counted, U, O, N]], Selected[Binned[Counted, U, O, N]]]): FractionedHistogramMethods = new FractionedHistogramMethods(new Fractioned(hist.entries, hist.quantityName, anySelectedBinnedToHistogramMethods(hist.numerator).selected, anySelectedBinnedToHistogramMethods(hist.denominator).selected)) implicit def anySelectingBinningToFractionedHistogramMethods[DATUM, U <: Container[U] with Aggregation{type Datum >: DATUM}, O <: Container[O] with Aggregation{type Datum >: DATUM}, N <: Container[N] with Aggregation{type Datum >: DATUM}](hist: Fractioning[DATUM, Selecting[DATUM, Binning[DATUM, Counting, U, O, N]]]): FractionedHistogramMethods = anySelectedBinnedToFractionedHistogramMethods(hist.toImmutable) - implicit def anySparselyBinnedToFractionedHistogramMethods[N <: Container[N] with NoAggregation](hist: Fractioned[SparselyBinned[Counted, N]]): FractionedHistogramMethods = + implicit def anySparselyBinnedToFractionedHistogramMethods[N <: Container[N] with NoAggregation](hist: Fractioned[SparselyBinned[Counted, N], SparselyBinned[Counted, N]]): FractionedHistogramMethods = new FractionedHistogramMethods(new Fractioned(hist.entries, hist.quantityName, anySparselyBinnedToHistogramMethods(hist.numerator).selected, anySparselyBinnedToHistogramMethods(hist.denominator).selected)) implicit def anySparselyBinningToFractionedHistogramMethods[DATUM, N <: Container[N] with Aggregation{type Datum >: DATUM}](hist: Fractioning[DATUM, SparselyBinning[DATUM, Counting, N]]): FractionedHistogramMethods = anySparselyBinnedToFractionedHistogramMethods(hist.toImmutable) - implicit def anySelectedSparselyBinnedToFractionedHistogramMethods[N <: Container[N] with NoAggregation](hist: Fractioned[Selected[SparselyBinned[Counted, N]]]): FractionedHistogramMethods = + implicit def anySelectedSparselyBinnedToFractionedHistogramMethods[N <: Container[N] with NoAggregation](hist: Fractioned[Selected[SparselyBinned[Counted, N]], Selected[SparselyBinned[Counted, N]]]): FractionedHistogramMethods = new FractionedHistogramMethods(new Fractioned(hist.entries, hist.quantityName, anySelectedSparselyBinnedToHistogramMethods(hist.numerator).selected, anySelectedSparselyBinnedToHistogramMethods(hist.denominator).selected)) implicit def anySelectingSparselyBinningToFractionedHistogramMethods[DATUM, N <: Container[N] with Aggregation{type Datum >: DATUM}](hist: Fractioning[DATUM, Selecting[DATUM, SparselyBinning[DATUM, Counting, N]]]): FractionedHistogramMethods = anySelectedSparselyBinnedToFractionedHistogramMethods(hist.toImmutable) /** Methods that are implicitly added to container combinations that look like fractioned histograms. */ - class FractionedHistogramMethods(val fractioned: Fractioned[Selected[Binned[Counted, Counted, Counted, Counted]]]) { + class FractionedHistogramMethods(val fractioned: Fractioned[Selected[Binned[Counted, Counted, Counted, Counted]], Selected[Binned[Counted, Counted, Counted, Counted]]]) { def numeratorBinned = fractioned.numerator.cut def denominatorBinned = fractioned.denominator.cut diff --git a/core/src/main/scala/org/dianahep/histogrammar/primitives/average.scala b/core/src/main/scala/org/dianahep/histogrammar/primitives/average.scala index 8398793..c2db626 100644 --- a/core/src/main/scala/org/dianahep/histogrammar/primitives/average.scala +++ b/core/src/main/scala/org/dianahep/histogrammar/primitives/average.scala @@ -14,6 +14,8 @@ package org.dianahep +import scala.language.existentials + import org.dianahep.histogrammar.json._ import org.dianahep.histogrammar.util._ diff --git a/core/src/main/scala/org/dianahep/histogrammar/primitives/bag.scala b/core/src/main/scala/org/dianahep/histogrammar/primitives/bag.scala index 91c4008..62fe1fe 100644 --- a/core/src/main/scala/org/dianahep/histogrammar/primitives/bag.scala +++ b/core/src/main/scala/org/dianahep/histogrammar/primitives/bag.scala @@ -14,6 +14,8 @@ package org.dianahep +import scala.language.existentials + import scala.reflect.classTag import scala.reflect.ClassTag diff --git a/core/src/main/scala/org/dianahep/histogrammar/primitives/bin.scala b/core/src/main/scala/org/dianahep/histogrammar/primitives/bin.scala index e4571c5..ed6a6d2 100644 --- a/core/src/main/scala/org/dianahep/histogrammar/primitives/bin.scala +++ b/core/src/main/scala/org/dianahep/histogrammar/primitives/bin.scala @@ -14,6 +14,8 @@ package org.dianahep +import scala.language.existentials + import org.dianahep.histogrammar.json._ import org.dianahep.histogrammar.util._ @@ -196,7 +198,7 @@ and so on.""" } val nanflow = nanflowFactory.fromJsonFragment(get("nanflow"), None) - new Binned[Container[_], Container[_], Container[_], Container[_]](low, high, entries, (nameFromParent ++ quantityName).lastOption, values, underflow, overflow, nanflow) + new Binned(low, high, entries, (nameFromParent ++ quantityName).lastOption, values.asInstanceOf[Seq[C] forSome {type C <: Container[C] with NoAggregation}], underflow.asInstanceOf[C forSome {type C <: Container[C] with NoAggregation}], overflow.asInstanceOf[C forSome {type C <: Container[C] with NoAggregation}], nanflow.asInstanceOf[C forSome {type C <: Container[C] with NoAggregation}]) case _ => throw new JsonFormatException(json, name) } diff --git a/core/src/main/scala/org/dianahep/histogrammar/primitives/categorize.scala b/core/src/main/scala/org/dianahep/histogrammar/primitives/categorize.scala index 42f0a2f..d0fdb93 100644 --- a/core/src/main/scala/org/dianahep/histogrammar/primitives/categorize.scala +++ b/core/src/main/scala/org/dianahep/histogrammar/primitives/categorize.scala @@ -16,6 +16,7 @@ package org.dianahep import scala.collection.mutable import scala.language.postfixOps +import scala.language.existentials import org.dianahep.histogrammar.json._ import org.dianahep.histogrammar.util._ @@ -85,15 +86,17 @@ Unlike [[org.dianahep.histogrammar.SparselyBin]], this aggregator has the potent case x => throw new JsonFormatException(x, name + ".bins:name") } - get("bins") match { - case JsonObject(categoryPairs @ _*) => - new Categorized[Container[_]](entries, (nameFromParent ++ quantityName).lastOption, contentType, categoryPairs map { - case (JsonString(category), value) => - category -> factory.fromJsonFragment(value, dataName) - } toMap) - - case x => throw new JsonFormatException(x, name + ".bins") - } + val thebins = + get("bins") match { + case JsonObject(categoryPairs @ _*) => + categoryPairs map { + case (JsonString(category), value) => + category -> factory.fromJsonFragment(value, dataName) + } toMap + case x => throw new JsonFormatException(x, name + ".bins") + } + + new Categorized(entries, (nameFromParent ++ quantityName).lastOption, contentType, thebins.asInstanceOf[Map[String, C] forSome {type C <: Container[C] with NoAggregation}]) case _ => throw new JsonFormatException(json, name) } diff --git a/core/src/main/scala/org/dianahep/histogrammar/primitives/centrallybin.scala b/core/src/main/scala/org/dianahep/histogrammar/primitives/centrallybin.scala index 7030ac5..1c60eac 100644 --- a/core/src/main/scala/org/dianahep/histogrammar/primitives/centrallybin.scala +++ b/core/src/main/scala/org/dianahep/histogrammar/primitives/centrallybin.scala @@ -142,7 +142,7 @@ package histogrammar { } val nanflow = nanflowFactory.fromJsonFragment(get("nanflow"), None) - new CentrallyBinned[Container[_], Container[_]](entries, (nameFromParent ++ quantityName).lastOption, bins.asInstanceOf[Seq[(Double, Container[_])]], nanflow) + new CentrallyBinned(entries, (nameFromParent ++ quantityName).lastOption, bins.asInstanceOf[Seq[(Double, C)] forSome {type C <: Container[C] with NoAggregation}], nanflow.asInstanceOf[C forSome {type C <: Container[C] with NoAggregation}]) case _ => throw new JsonFormatException(json, name) } diff --git a/core/src/main/scala/org/dianahep/histogrammar/primitives/collection.scala b/core/src/main/scala/org/dianahep/histogrammar/primitives/collection.scala index 7a0f4a0..fc0c3a9 100644 --- a/core/src/main/scala/org/dianahep/histogrammar/primitives/collection.scala +++ b/core/src/main/scala/org/dianahep/histogrammar/primitives/collection.scala @@ -78,11 +78,14 @@ In strongly typed languages, the restriction to a single type allows nested obje case x => throw new JsonFormatException(x, name + ".sub:type") } - get("data") match { - case JsonObject(labelPairs @ _*) if (labelPairs.size >= 1) => - new Labeled[Container[_]](entries, labelPairs map {case (JsonString(label), sub) => label -> factory.fromJsonFragment(sub, None)}: _*) - case x => throw new JsonFormatException(x, name + ".data") - } + val thedata = + get("data") match { + case JsonObject(labelPairs @ _*) if (labelPairs.size >= 1) => + labelPairs map {case (JsonString(label), sub) => label -> factory.fromJsonFragment(sub, None)} + case x => throw new JsonFormatException(x, name + ".data") + } + + new Labeled(entries, thedata.asInstanceOf[Seq[(String, C)] forSome {type C <: Container[C] with NoAggregation}]: _*) case _ => throw new JsonFormatException(json, name) } @@ -286,10 +289,10 @@ To collect aggregators of the ''same type'' without naming them, use [[org.diana * * @param pairs Names (strings) associated with containers of any type except [[org.dianahep.histogrammar.Counting]]. */ - def apply[DATUM](pairs: (String, Container[_] with AggregationOnData {type Datum = DATUM})*) = new UntypedLabeling(0.0, pairs: _*) + def apply[DATUM, F <: Container[F] with Aggregation](first: (String, F), rest: (String, Container[_] with Aggregation)*) = new UntypedLabeling(0.0, first, rest: _*) /** Synonym for `apply`. */ - def ing[DATUM](pairs: (String, Container[_] with AggregationOnData {type Datum = DATUM})*) = apply(pairs: _*) + def ing[DATUM, F <: Container[F] with Aggregation](first: (String, F), rest: (String, Container[_] with Aggregation)*) = apply(first, rest: _*) import KeySetComparisons._ def fromJsonFragment(json: Json, nameFromParent: Option[String]): Container[_] with NoAggregation = json match { @@ -301,9 +304,10 @@ To collect aggregators of the ''same type'' without naming them, use [[org.diana case x => throw new JsonFormatException(x, name + ".entries") } + val thedata = get("data") match { case JsonObject(subpairs @ _*) => - new UntypedLabeled(entries, subpairs map { + subpairs map { case (JsonString(label), JsonObject(typedata @ _*)) if (typedata.keySet has Set("type", "data")) => val subget = typedata.toMap @@ -312,11 +316,12 @@ To collect aggregators of the ''same type'' without naming them, use [[org.diana case (_, x) => throw new JsonFormatException(x, name + s""".data "$label"""") } case (_, x) => throw new JsonFormatException(x, name + s".data") - }: _*) - + } case x => throw new JsonFormatException(x, name) } + new UntypedLabeled(entries, thedata.asInstanceOf[Seq[(String, C)] forSome {type C <: Container[C] with NoAggregation}]: _*) + case _ => throw new JsonFormatException(json, name) } @@ -371,7 +376,7 @@ To collect aggregators of the ''same type'' without naming them, use [[org.diana case _ => throw new IllegalArgumentException(s"""wrong type or out of bounds index for UntypedLabeled: ${indexes.mkString(", ")}""") } - def zero = new UntypedLabeled(0.0, pairs map {case (k, v) => (k, v.zero.asInstanceOf[Container[_]])}: _*) + def zero = new UntypedLabeled(0.0, (pairs map {case (k, v) => (k, v.zero)}).asInstanceOf[Seq[(String, Container[_])]]: _*) def +(that: UntypedLabeled) = if (this.keySet != that.keySet) throw new ContainerException(s"""cannot add UntypedLabeled because they have different keys:\n ${this.keys.toArray.sorted.mkString(" ")}\nvs\n ${that.keys.toArray.sorted.mkString(" ")}""") @@ -409,15 +414,17 @@ To collect aggregators of the ''same type'' without naming them, use [[org.diana * * '''Note:''' the compiler cannot predict the type of data that is drawn from this collection, so it must be cast with `as`. */ - class UntypedLabeling[DATUM] private[histogrammar](var entries: Double, val pairs: (String, Container[_] with AggregationOnData {type Datum = DATUM})*) extends Container[UntypedLabeling[DATUM]] with AggregationOnData with Collection { - type Type = UntypedLabeled + class UntypedLabeling[F <: Container[F] with Aggregation] private[histogrammar](var entries: Double, first: (String, F), rest: (String, Container[_] with Aggregation)*) extends Container[UntypedLabeling[F]] with AggregationOnData with Collection { + type Type = UntypedLabeling[F] type EdType = UntypedLabeled - type Datum = DATUM + type Datum = F#Datum def factory = UntypedLabel if (entries < 0.0) throw new ContainerException(s"entries ($entries) cannot be negative") + val pairs = first +: rest + /** Input `pairs` as a key-value map. */ val pairsMap = pairs.toMap /** Number of `pairs`. */ @@ -448,14 +455,15 @@ To collect aggregators of the ''same type'' without naming them, use [[org.diana case _ => throw new IllegalArgumentException(s"""wrong type or out of bounds index for UntypedLabeling: ${indexes.mkString(", ")}""") } - def zero = new UntypedLabeling[DATUM](0.0, pairs map {case (k, v) => (k, v.zero.asInstanceOf[Container[_] with AggregationOnData {type Datum = DATUM}])}: _*) - def +(that: UntypedLabeling[DATUM]) = + def zero = new UntypedLabeling[F](0.0, (first._1, first._2.zero), rest.map({case (k, v) => (k, v.zero.asInstanceOf[Container[_] with Aggregation])}): _*) + def +(that: UntypedLabeling[F]) = if (this.keySet != that.keySet) throw new ContainerException(s"""cannot add UntypedLabeling because they have different keys:\n ${this.keys.toArray.sorted.mkString(" ")}\nvs\n ${that.keys.toArray.sorted.mkString(" ")}""") else - new UntypedLabeling[DATUM]( + new UntypedLabeling[F]( this.entries + that.entries, - this.pairs.map({case (key, mysub) => + (this.first._1, this.first._2 + that.pairsMap(this.first._1).asInstanceOf[F]), + this.rest.map({case (key, mysub) => val yoursub = that.pairsMap(key) if (mysub.factory != yoursub.factory) throw new ContainerException(s"""cannot add UntypedLabeling because key "$key" has a different type in the two maps: ${mysub.factory.name} vs ${yoursub.factory.name}""") @@ -486,7 +494,7 @@ To collect aggregators of the ''same type'' without naming them, use [[org.diana override def toString() = s"""""" override def equals(that: Any) = that match { - case that: UntypedLabeling[DATUM] => this.entries === that.entries && this.pairsMap == that.pairsMap + case that: UntypedLabeling[F] => this.entries === that.entries && this.pairsMap == that.pairsMap case _ => false } override def hashCode() = (entries, pairsMap).hashCode @@ -545,12 +553,15 @@ To collect aggregators of the ''same type'' with string-based labels, use [[org. case x => throw new JsonFormatException(x, name + ".sub:type") } - get("data") match { - case JsonArray(values @ _*) if (values.size >= 1) => - new Indexed[Container[_]](entries, values.map(factory.fromJsonFragment(_, None)): _*) - case x => - throw new JsonFormatException(x, name + ".data") - } + val thedata = + get("data") match { + case JsonArray(values @ _*) if (values.size >= 1) => + values.map(factory.fromJsonFragment(_, None)) + case x => + throw new JsonFormatException(x, name + ".data") + } + + new Indexed(entries, thedata.asInstanceOf[Seq[C] forSome {type C <: Container[C] with NoAggregation}]: _*) case _ => throw new JsonFormatException(json, name) } @@ -804,29 +815,22 @@ To collect an unlimited number of aggregators of the ''same type'' without namin get("data") match { case JsonArray(values @ _*) if (values.size >= 1) => - var backwards: BranchedList = BranchedNil + var out: BranchedList = BranchedNil - values.zipWithIndex.toList foreach { + values.zipWithIndex.toList.reverse foreach { case (JsonObject(typedata @ _*), i) if (typedata.keySet has Set("type", "data")) => val subget = typedata.toMap (subget("type"), subget("data")) match { case (JsonString(factory), sub) => val item = Factory(factory).fromJsonFragment(sub, None).asInstanceOf[C forSome {type C <: Container[C] with NoAggregation}] - backwards = new Branched(entries, item, backwards) + out = new Branched(entries, item, out) case (_, x) => throw new JsonFormatException(x, name + s".data") } case (x, i) => throw new JsonFormatException(x, name + s".data $i") } - // we've loaded it backwards, so reverse the order before returning it - var out: BranchedList = BranchedNil - while (backwards != BranchedNil) { - val list = backwards.asInstanceOf[Branched[C forSome {type C <: Container[C] with NoAggregation}, BranchedList]] - out = new Branched(list.entries, list.head, out) - backwards = list.tail - } out.asInstanceOf[Container[_] with NoAggregation] case x => throw new JsonFormatException(x, name + ".data") diff --git a/core/src/main/scala/org/dianahep/histogrammar/primitives/count.scala b/core/src/main/scala/org/dianahep/histogrammar/primitives/count.scala index 97224b4..a0bb4d7 100644 --- a/core/src/main/scala/org/dianahep/histogrammar/primitives/count.scala +++ b/core/src/main/scala/org/dianahep/histogrammar/primitives/count.scala @@ -14,6 +14,8 @@ package org.dianahep +import scala.language.existentials + import org.dianahep.histogrammar._ import org.dianahep.histogrammar.json._ import org.dianahep.histogrammar.util._ @@ -60,7 +62,7 @@ package histogrammar { import KeySetComparisons._ def fromJsonFragment(json: Json, nameFromParent: Option[String]): Container[_] with NoAggregation = json match { - case JsonFloat(entries) => new Counted(entries) + case JsonNumber(entries) => new Counted(entries) case _ => throw new JsonFormatException(json, name) } diff --git a/core/src/main/scala/org/dianahep/histogrammar/primitives/deviate.scala b/core/src/main/scala/org/dianahep/histogrammar/primitives/deviate.scala index 271245d..0faa320 100644 --- a/core/src/main/scala/org/dianahep/histogrammar/primitives/deviate.scala +++ b/core/src/main/scala/org/dianahep/histogrammar/primitives/deviate.scala @@ -14,6 +14,8 @@ package org.dianahep +import scala.language.existentials + import org.dianahep.histogrammar.json._ import org.dianahep.histogrammar.util._ diff --git a/core/src/main/scala/org/dianahep/histogrammar/primitives/fraction.scala b/core/src/main/scala/org/dianahep/histogrammar/primitives/fraction.scala index 43c06f1..a2dbd94 100644 --- a/core/src/main/scala/org/dianahep/histogrammar/primitives/fraction.scala +++ b/core/src/main/scala/org/dianahep/histogrammar/primitives/fraction.scala @@ -14,6 +14,8 @@ package org.dianahep +import scala.language.existentials + import org.dianahep.histogrammar.json._ import org.dianahep.histogrammar.util._ @@ -59,12 +61,12 @@ As a side effect of NaN values returning false for any comparison, a NaN return * * This could be used for any bin-by-bin ratio (or even a difference or other reduction), such as a data/Monte Caro ratio. The purpose of binding the histograms together like this is to verify that they have compatible bins and to provide access to existing methods for creating ratio plots from Fractioned objects. */ - def build[N <: Container[N], D <: Container[D]](numerator: N, denominator: D): Fractioned[N] = { + def build[N <: Container[N], D <: Container[D]](numerator: N, denominator: D): Fractioned[N, D] = { // check for compatibility val d2 = denominator.asInstanceOf[N] numerator + d2 // return object - new Fractioned(d2.entries, None, numerator, d2) + new Fractioned(denominator.entries, None, numerator, denominator) } import KeySetComparisons._ @@ -97,7 +99,7 @@ As a side effect of NaN values returning false for any comparison, a NaN return val numerator = factory.fromJsonFragment(get("numerator"), subName) val denominator = factory.fromJsonFragment(get("denominator"), subName) - new Fractioned[Container[_]](entries, (nameFromParent ++ quantityName).lastOption, numerator, denominator) + new Fractioned(entries, (nameFromParent ++ quantityName).lastOption, numerator.asInstanceOf[C forSome {type C <: Container[C] with NoAggregation}], denominator.asInstanceOf[C forSome {type C <: Container[C] with NoAggregation}]) case _ => throw new JsonFormatException(json, name) } @@ -163,14 +165,14 @@ As a side effect of NaN values returning false for any comparison, a NaN return * @param numerator Container for data that passed the given selection. * @param denominator Container for all data, regardless of whether it passed the given selection. */ - class Fractioned[V <: Container[V]] private[histogrammar](val entries: Double, val quantityName: Option[String], val numerator: V, val denominator: V) extends Container[Fractioned[V]] with NoAggregation with QuantityName with Select.Methods { - // NOTE: The type bounds ought to be V <: Container[V] with NoAggregation, but this constraint has + class Fractioned[N <: Container[N], D <: Container[D]] private[histogrammar](val entries: Double, val quantityName: Option[String], val numerator: N, val denominator: D) extends Container[Fractioned[N, D]] with NoAggregation with QuantityName with Select.Methods { + // NOTE: The type bounds ought to be N <: Container[N] with NoAggregation, but this constraint has // been relaxed to allow the alternate constructor. The standard constructor applies this // constraint, so normal Fractioned objects will have the correct types. HOWEVER, this class // no longer "knows" that. I am not sure if this lack of knowledge will ever become a problem. - type Type = Fractioned[V] - type EdType = Fractioned[V] + type Type = Fractioned[N, D] + type EdType = Fractioned[N, D] def factory = Fraction if (entries < 0.0) @@ -178,8 +180,8 @@ As a side effect of NaN values returning false for any comparison, a NaN return def fractionPassing = numerator.entries / entries - def zero = new Fractioned[V](0.0, quantityName, numerator.zero, denominator.zero) - def +(that: Fractioned[V]) = + def zero = new Fractioned[N, D](0.0, quantityName, numerator.zero, denominator.zero) + def +(that: Fractioned[N, D]) = if (this.quantityName != that.quantityName) throw new ContainerException(s"cannot add ${getClass.getName} because quantityName differs (${this.quantityName} vs ${that.quantityName})") else @@ -197,7 +199,7 @@ As a side effect of NaN values returning false for any comparison, a NaN return override def toString() = s"""""" override def equals(that: Any) = that match { - case that: Fractioned[V] => this.entries === that.entries && this.quantityName == that.quantityName && this.numerator == that.numerator && this.denominator == that.denominator + case that: Fractioned[N, D] => this.entries === that.entries && this.quantityName == that.quantityName && this.numerator == that.numerator && this.denominator == that.denominator case _ => false } override def hashCode() = (entries, quantityName, numerator, denominator).hashCode @@ -214,7 +216,7 @@ As a side effect of NaN values returning false for any comparison, a NaN return */ class Fractioning[DATUM, V <: Container[V] with Aggregation{type Datum >: DATUM}] private[histogrammar](val quantity: UserFcn[DATUM, Double], var entries: Double, val numerator: V, val denominator: V) extends Container[Fractioning[DATUM, V]] with AggregationOnData with NumericalQuantity[DATUM] with Select.Methods { type Type = Fractioning[DATUM, V] - type EdType = Fractioned[numerator.EdType] + type EdType = Fractioned[numerator.EdType, numerator.EdType] type Datum = DATUM def factory = Fraction diff --git a/core/src/main/scala/org/dianahep/histogrammar/primitives/irregularlybin.scala b/core/src/main/scala/org/dianahep/histogrammar/primitives/irregularlybin.scala index 23c8f1b..841e49e 100644 --- a/core/src/main/scala/org/dianahep/histogrammar/primitives/irregularlybin.scala +++ b/core/src/main/scala/org/dianahep/histogrammar/primitives/irregularlybin.scala @@ -15,6 +15,7 @@ package org.dianahep import scala.collection.immutable.SortedSet +import scala.language.existentials import org.dianahep.histogrammar.json._ import org.dianahep.histogrammar.util._ @@ -91,24 +92,25 @@ IrregularlyBin is also similar to [[org.dianahep.histogrammar.CentrallyBin]], in } val nanflow = nanflowFactory.fromJsonFragment(get("nanflow"), None) - get("bins") match { - case JsonArray(elements @ _*) if (elements.size >= 1) => - new IrregularlyBinned[Container[_], Container[_]](entries, (nameFromParent ++ quantityName).lastOption, elements.zipWithIndex map {case (element, i) => - element match { - case JsonObject(elementPairs @ _*) if (elementPairs.keySet has Set("atleast", "data")) => - val elementGet = elementPairs.toMap - val atleast = elementGet("atleast") match { - case JsonNumber(x) => x - case x => throw new JsonFormatException(x, name + s".data element $i atleast") - } - (atleast, factory.fromJsonFragment(elementGet("data"), dataName)) - - case x => throw new JsonFormatException(x, name + s".data element $i") + val thebins = + get("bins") match { + case JsonArray(elements @ _*) if (elements.size >= 1) => + elements.zipWithIndex map {case (element, i) => + element match { + case JsonObject(elementPairs @ _*) if (elementPairs.keySet has Set("atleast", "data")) => + val elementGet = elementPairs.toMap + val atleast = elementGet("atleast") match { + case JsonNumber(x) => x + case x => throw new JsonFormatException(x, name + s".data element $i atleast") + } + (atleast, factory.fromJsonFragment(elementGet("data"), dataName)) + case x => throw new JsonFormatException(x, name + s".data element $i") + } } - }, nanflow) + case x => throw new JsonFormatException(x, name + ".data") + } - case x => throw new JsonFormatException(x, name + ".data") - } + new IrregularlyBinned(entries, (nameFromParent ++ quantityName).lastOption, thebins.asInstanceOf[Seq[(Double, C)] forSome {type C <: Container[C] with NoAggregation}], nanflow.asInstanceOf[C forSome {type C <: Container[C] with NoAggregation}]) case _ => throw new JsonFormatException(json, name) } diff --git a/core/src/main/scala/org/dianahep/histogrammar/primitives/minmax.scala b/core/src/main/scala/org/dianahep/histogrammar/primitives/minmax.scala index 236bba9..2d16432 100644 --- a/core/src/main/scala/org/dianahep/histogrammar/primitives/minmax.scala +++ b/core/src/main/scala/org/dianahep/histogrammar/primitives/minmax.scala @@ -14,6 +14,8 @@ package org.dianahep +import scala.language.existentials + import org.dianahep.histogrammar.json._ import org.dianahep.histogrammar.util._ diff --git a/core/src/main/scala/org/dianahep/histogrammar/primitives/select.scala b/core/src/main/scala/org/dianahep/histogrammar/primitives/select.scala index b26a9a8..8677860 100644 --- a/core/src/main/scala/org/dianahep/histogrammar/primitives/select.scala +++ b/core/src/main/scala/org/dianahep/histogrammar/primitives/select.scala @@ -86,7 +86,7 @@ The efficiency of a cut in a Select aggregator named `x` is simply `x.cut.entrie val cut = factory.fromJsonFragment(get("data"), None) - new Selected[Container[_]](entries, (nameFromParent ++ quantityName).lastOption, cut) + new Selected(entries, (nameFromParent ++ quantityName).lastOption, cut.asInstanceOf[C forSome {type C <: Container[C] with NoAggregation}]) case _ => throw new JsonFormatException(json, name) } diff --git a/core/src/main/scala/org/dianahep/histogrammar/primitives/sparselybin.scala b/core/src/main/scala/org/dianahep/histogrammar/primitives/sparselybin.scala index 7283fd1..4422386 100644 --- a/core/src/main/scala/org/dianahep/histogrammar/primitives/sparselybin.scala +++ b/core/src/main/scala/org/dianahep/histogrammar/primitives/sparselybin.scala @@ -171,7 +171,7 @@ Like fixed-domain binning, the bins are indexed by integers, though they are 64- case x => throw new JsonFormatException(x, name + ".origin") } - new SparselyBinned[Container[_], Container[_]](binWidth, entries, (nameFromParent ++ quantityName).lastOption, contentType, bins.asInstanceOf[SortedMap[Long, Container[_]]], nanflow, origin) + new SparselyBinned(binWidth, entries, (nameFromParent ++ quantityName).lastOption, contentType, bins.asInstanceOf[SortedMap[Long, C] forSome {type C <: Container[C] with NoAggregation}], nanflow.asInstanceOf[C forSome {type C <: Container[C] with NoAggregation}], origin) case _ => throw new JsonFormatException(json, name) } diff --git a/core/src/main/scala/org/dianahep/histogrammar/primitives/stack.scala b/core/src/main/scala/org/dianahep/histogrammar/primitives/stack.scala index 4ee7b5b..09ff834 100644 --- a/core/src/main/scala/org/dianahep/histogrammar/primitives/stack.scala +++ b/core/src/main/scala/org/dianahep/histogrammar/primitives/stack.scala @@ -15,6 +15,7 @@ package org.dianahep import scala.collection.immutable.SortedSet +import scala.language.existentials import org.dianahep.histogrammar.json._ import org.dianahep.histogrammar.util._ @@ -112,25 +113,26 @@ To make plots from different sources in Histogrammar, one must perform separate } val nanflow = nanflowFactory.fromJsonFragment(get("nanflow"), None) - get("bins") match { - case JsonArray(elements @ _*) if (elements.size >= 1) => - new Stacked[Container[_], Container[_]](entries, (nameFromParent ++ quantityName).lastOption, elements.zipWithIndex map {case (element, i) => - element match { - case JsonObject(elementPairs @ _*) if (elementPairs.keySet has Set("atleast", "data")) => - val elementGet = elementPairs.toMap - val atleast = elementGet("atleast") match { - case JsonNumber(x) => x - case x => throw new JsonFormatException(x, name + s".bins element $i atleast") - } - (atleast, factory.fromJsonFragment(elementGet("data"), dataName)) - - case x => throw new JsonFormatException(x, name + s".bins element $i") + val thebins = + get("bins") match { + case JsonArray(elements @ _*) if (elements.size >= 1) => + elements.zipWithIndex map {case (element, i) => + element match { + case JsonObject(elementPairs @ _*) if (elementPairs.keySet has Set("atleast", "data")) => + val elementGet = elementPairs.toMap + val atleast = elementGet("atleast") match { + case JsonNumber(x) => x + case x => throw new JsonFormatException(x, name + s".bins element $i atleast") + } + (atleast, factory.fromJsonFragment(elementGet("data"), dataName)) + case x => throw new JsonFormatException(x, name + s".bins element $i") + } } - }, nanflow) - case x => throw new JsonFormatException(x, name + ".bins") } + new Stacked(entries, (nameFromParent ++ quantityName).lastOption, thebins.asInstanceOf[Seq[(Double, C)] forSome {type C <: Container[C] with NoAggregation}], nanflow.asInstanceOf[C forSome {type C <: Container[C] with NoAggregation}]) + case _ => throw new JsonFormatException(json, name) } } diff --git a/core/src/main/scala/org/dianahep/histogrammar/primitives/sum.scala b/core/src/main/scala/org/dianahep/histogrammar/primitives/sum.scala index 0f0700d..3a1a37a 100644 --- a/core/src/main/scala/org/dianahep/histogrammar/primitives/sum.scala +++ b/core/src/main/scala/org/dianahep/histogrammar/primitives/sum.scala @@ -14,6 +14,8 @@ package org.dianahep +import scala.language.existentials + import org.dianahep.histogrammar.json._ import org.dianahep.histogrammar.util._ diff --git a/core/src/test/scala/basic.scala b/core/src/test/scala/basic.scala index 3e8d2f6..8ade276 100644 --- a/core/src/test/scala/basic.scala +++ b/core/src/test/scala/basic.scala @@ -878,31 +878,31 @@ class BasicSuite extends FlatSpec with Matchers { checkJson(finalHist) } - // for (i <- 0 to 10) { - // val (left, right) = simple.splitAt(i) + for (i <- 0 to 10) { + val (left, right) = simple.splitAt(i) - // val hist1 = Bin(5, -3.0, 7.0, {x: Double => x}) - // val hist2 = Bin(5, -3.0, 7.0, {x: Double => x}) - // val sum1 = Sum({x: Double => 1.0}) - // val sum2 = Sum({x: Double => 1.0}) + val hist1 = Bin(5, -3.0, 7.0, {x: Double => x}) + val hist2 = Bin(5, -3.0, 7.0, {x: Double => x}) + val sum1 = Sum({x: Double => 1.0}) + val sum2 = Sum({x: Double => 1.0}) - // val collection1 = UntypedLabel("hist" -> hist1, "sum" -> sum1) - // val collection2 = UntypedLabel("hist" -> hist2, "sum" -> sum2) + val collection1 = UntypedLabel("hist" -> hist1, "sum" -> sum1) + val collection2 = UntypedLabel("hist" -> hist2, "sum" -> sum2) - // val partialHists = Seq( - // left.foldLeft(collection1)(new Increment[Double, collection1.Type]), - // right.foldLeft(collection2)(new Increment[Double, collection1.Type])) + val partialHists = Seq( + left.foldLeft(collection1)(new Increment[Double, collection1.Type]), + right.foldLeft(collection2)(new Increment[Double, collection1.Type])) - // val finalHist = partialHists.reduce(new Combine[collection1.Type]) + val finalHist = partialHists.reduce(new Combine[collection1.Type]) - // finalHist("hist").as[hist1.Type].numericalValues should be (Seq(3.0, 2.0, 2.0, 1.0, 0.0)) - // finalHist("hist").as[hist1.Type].numericalUnderflow should be (1.0) - // finalHist("hist").as[hist1.Type].numericalOverflow should be (1.0) - // finalHist("hist").as[hist1.Type].numericalNanflow should be (0.0) - // finalHist("sum").as[sum1.Type].sum should be (10.0) + finalHist("hist").as[hist1.Type].numericalValues should be (Seq(3.0, 2.0, 2.0, 1.0, 0.0)) + finalHist("hist").as[hist1.Type].numericalUnderflow should be (1.0) + finalHist("hist").as[hist1.Type].numericalOverflow should be (1.0) + finalHist("hist").as[hist1.Type].numericalNanflow should be (0.0) + finalHist("sum").as[sum1.Type].sum should be (10.0) - // checkJson(finalHist) - // } + checkJson(finalHist) + } } //////////////////////////////////////////////////////////////// Check all specialized conversions @@ -998,13 +998,13 @@ class BasicSuite extends FlatSpec with Matchers { takesPartitionedHistogramMethods(partitionedSelectedSparselyBinnedCounted) val fractioningBinningCounting = Fraction({x: Double => x}, Bin(10, 0, 1, {x: Double => x}, Count())) - val fractionedBinnedCounted = fractioningBinningCounting.toImmutable.as[Fractioned[Binned[Counted, Counted, Counted, Counted]]] + val fractionedBinnedCounted = fractioningBinningCounting.toImmutable.as[Fractioned[Binned[Counted, Counted, Counted, Counted], Binned[Counted, Counted, Counted, Counted]]] val fractioningSelectingBinningCounting = Fraction({x: Double => x}, Select({x: Double => x}, Bin(10, 0, 1, {x: Double => x}, Count()))) - val fractionedSelectedBinnedCounted = fractioningSelectingBinningCounting.toImmutable.as[Fractioned[Selected[Binned[Counted, Counted, Counted, Counted]]]] + val fractionedSelectedBinnedCounted = fractioningSelectingBinningCounting.toImmutable.as[Fractioned[Selected[Binned[Counted, Counted, Counted, Counted]], Selected[Binned[Counted, Counted, Counted, Counted]]]] val fractioningSparselyBinningCounting = Fraction({x: Double => x}, SparselyBin(1, {x: Double => x}, Count())) - val fractionedSparselyBinnedCounted = fractioningSparselyBinningCounting.toImmutable.as[Fractioned[SparselyBinned[Counted, Counted]]] + val fractionedSparselyBinnedCounted = fractioningSparselyBinningCounting.toImmutable.as[Fractioned[SparselyBinned[Counted, Counted], SparselyBinned[Counted, Counted]]] val fractioningSelectingSparselyBinningCounting = Fraction({x: Double => x}, Select({x: Double => x}, SparselyBin(1, {x: Double => x}, Count()))) - val fractionedSelectedSparselyBinnedCounted = fractioningSelectingSparselyBinningCounting.toImmutable.as[Fractioned[Selected[SparselyBinned[Counted, Counted]]]] + val fractionedSelectedSparselyBinnedCounted = fractioningSelectingSparselyBinningCounting.toImmutable.as[Fractioned[Selected[SparselyBinned[Counted, Counted]], Selected[SparselyBinned[Counted, Counted]]]] def takesFractionedHistogramMethods(x: FractionedHistogramMethods) { } takesFractionedHistogramMethods(fractioningBinningCounting) takesFractionedHistogramMethods(fractionedBinnedCounted) diff --git a/sparksql/pom.xml b/sparksql/pom.xml index 0f78b15..4cd443a 100644 --- a/sparksql/pom.xml +++ b/sparksql/pom.xml @@ -20,7 +20,7 @@ 2016 org.diana-hep - histogrammar-sparksql + histogrammar-sparksql_${scala.binary.version} 1.0.0 jar @@ -32,11 +32,35 @@ + + + scala-2.10 + + !scala-2.11 + + + 2.10.6 + 2.10 + 1.7 + 1.7 + + + + + scala-2.11 + + scala-2.11 + + + 2.11.8 + 2.11 + 1.8 + 1.8 + + + + - 1.7 - 1.7 - 2.10 - 2.10.5 UTF-8 UTF-8 @@ -50,13 +74,13 @@ org.diana-hep - histogrammar + histogrammar_${scala.binary.version} 1.0.0 org.apache.spark - spark-sql_${scala.tools.version} + spark-sql_${scala.binary.version} 1.6.1 provided @@ -73,7 +97,7 @@ net.alchim31.maven scala-maven-plugin - 3.2.1 + 3.2.2