├── .classpath
├── .gitignore
├── .project
├── .settings
├── org.eclipse.jdt.core.prefs
└── org.eclipse.m2e.core.prefs
├── .travis.yml
├── Config.txt
├── Dockerfile
├── LICENSE
├── README.md
├── bin
├── benchmarks
│ ├── generated
│ │ ├── arithmetic
│ │ │ ├── Average.java
│ │ │ ├── ConditionalCount.java
│ │ │ ├── ConditionalSum.java
│ │ │ ├── Count.java
│ │ │ ├── Delta.java
│ │ │ ├── Equal.java
│ │ │ ├── EqualFrequency.java
│ │ │ ├── Max.java
│ │ │ ├── MaxAbs.java
│ │ │ ├── Min.java
│ │ │ └── Sum.java
│ │ ├── bigλ
│ │ │ ├── CyclingSpeed.java
│ │ │ ├── DatabaseSelect.java
│ │ │ ├── ShakespearSentiment.java
│ │ │ ├── TwitterCounts.java
│ │ │ ├── WikiPageCount.java
│ │ │ └── YelpKids.java
│ │ ├── fiji
│ │ │ ├── IJ_RedToMagenta
│ │ │ │ └── Benchmark0.java
│ │ │ ├── IJ_Temporal
│ │ │ │ ├── Benchmark0.java
│ │ │ │ ├── Benchmark1.java
│ │ │ │ ├── Benchmark2.java
│ │ │ │ ├── Benchmark3.java
│ │ │ │ └── Benchmark4.java
│ │ │ └── IJ_Trails
│ │ │ │ ├── Benchmark0.java
│ │ │ │ ├── Benchmark1.java
│ │ │ │ ├── Benchmark2.java
│ │ │ │ └── Benchmark3.java
│ │ ├── phoenix
│ │ │ ├── Histogram.java
│ │ │ ├── KMeansJava.java
│ │ │ ├── LinearRegression.java
│ │ │ ├── PcaJava.java
│ │ │ ├── StringMatch.java
│ │ │ └── WordCount.java
│ │ └── stats
│ │ │ ├── Calculate.java
│ │ │ ├── IOUtil.java
│ │ │ ├── PlotReader.java
│ │ │ ├── PlotUtil.java
│ │ │ ├── PlotWriter.java
│ │ │ └── StatsUtil.java
│ ├── manual
│ │ ├── arithmetic
│ │ │ ├── Average.java
│ │ │ ├── ConditionalCount.java
│ │ │ ├── ConditionalSum.java
│ │ │ ├── Count.java
│ │ │ ├── Delta.java
│ │ │ ├── Equal.java
│ │ │ ├── EqualFrequency.java
│ │ │ ├── Max.java
│ │ │ ├── MaxAbs.java
│ │ │ ├── Min.java
│ │ │ └── Sum.java
│ │ ├── bigλ
│ │ │ ├── CyclingSpeed.java
│ │ │ ├── DatabaseSelect.java
│ │ │ ├── ShakespearSentiment.java
│ │ │ ├── TwitterCounts.java
│ │ │ ├── WikiPageCount.java
│ │ │ └── YelpKids.java
│ │ ├── fiji
│ │ │ ├── IJ_RedToMagenta
│ │ │ │ └── Benchmark0.java
│ │ │ ├── IJ_Temporal
│ │ │ │ ├── Benchmark0.java
│ │ │ │ ├── Benchmark1.java
│ │ │ │ ├── Benchmark2.java
│ │ │ │ ├── Benchmark3.java
│ │ │ │ └── Benchmark4.java
│ │ │ └── IJ_Trails
│ │ │ │ ├── Benchmark0.java
│ │ │ │ ├── Benchmark1.java
│ │ │ │ ├── Benchmark2.java
│ │ │ │ └── Benchmark3.java
│ │ ├── phoenix
│ │ │ ├── Histogram.java
│ │ │ ├── KMeansJava.java
│ │ │ ├── LinearRegression.java
│ │ │ ├── PcaJava.java
│ │ │ ├── StringMatch.java
│ │ │ └── WordCount.java
│ │ └── stats
│ │ │ ├── Calculate.java
│ │ │ ├── IOUtil.java
│ │ │ ├── PlotReader.java
│ │ │ ├── PlotUtil.java
│ │ │ ├── PlotWriter.java
│ │ │ └── StatsUtil.java
│ └── original
│ │ ├── arithmetic
│ │ ├── Average.java
│ │ ├── ConditionalCount.java
│ │ ├── ConditionalSum.java
│ │ ├── Count.java
│ │ ├── Delta.java
│ │ ├── Equal.java
│ │ ├── EqualFrequency.java
│ │ ├── Max.java
│ │ ├── MaxAbs.java
│ │ ├── Min.java
│ │ └── Sum.java
│ │ ├── bigλ
│ │ ├── CyclingSpeed.java
│ │ ├── DatabaseSelect.java
│ │ ├── ShakespearSentiment.java
│ │ ├── TwitterCounts.java
│ │ ├── WikiPageCount.java
│ │ └── YelpKids.java
│ │ ├── fiji
│ │ ├── IJ_RedToMagenta
│ │ │ └── fiji
│ │ │ │ └── color
│ │ │ │ └── Convert_Red_To_Magenta.java
│ │ ├── IJ_Temporal
│ │ │ ├── README.md
│ │ │ ├── pom.xml
│ │ │ └── src
│ │ │ │ └── main
│ │ │ │ ├── java
│ │ │ │ └── TemporalMedian_.java
│ │ │ │ └── resources
│ │ │ │ └── plugins.config
│ │ └── IJ_Trails
│ │ │ ├── README.md
│ │ │ ├── pom.xml
│ │ │ └── src
│ │ │ └── main
│ │ │ ├── java
│ │ │ └── Trails_.java
│ │ │ └── resources
│ │ │ └── plugins.config
│ │ ├── phoenix
│ │ ├── Histogram.java
│ │ ├── KMeansJava.java
│ │ ├── LinearRegression.java
│ │ ├── PcaJava.java
│ │ ├── StringMatch.java
│ │ └── WordCount.java
│ │ └── stats
│ │ ├── AverageData.java
│ │ ├── Calculate.java
│ │ ├── ExtractColumn.java
│ │ ├── FormatData.java
│ │ ├── IOUtil.java
│ │ ├── LinearData.java
│ │ ├── MomentInertia.java
│ │ ├── PlotReader.java
│ │ ├── PlotUtil.java
│ │ ├── PlotWriter.java
│ │ └── StatsUtil.java
├── buildCompileAndRun.sh
├── casper
├── casperc
├── check.sh
├── compileAndRun.sh
├── debug.txt
├── debugRun.sh
├── indentationScript.js
├── output
│ ├── Average.sk
│ ├── Count.sk
│ ├── MaxAbs.sk
│ ├── Mean.sk
│ ├── Min.sk
│ ├── MulVecSca.sk
│ ├── Sum.sk
│ ├── main_double_0.dfy
│ ├── main_double_0.sk
│ ├── main_double_0.txt
│ ├── main_int_0.dfy
│ ├── main_int_0.sk
│ ├── main_int_0.txt
│ ├── outputTempDafny.txt
│ ├── utils.dfy
│ └── utils.sk
├── run.sh
└── templates
│ ├── dafny_skeleton.dfy
│ ├── dafny_skeleton2.dfy
│ ├── main_skeleton.sk
│ ├── spark_skeleton.txt
│ ├── spark_skeleton_demo.txt
│ ├── utils.dfy
│ └── utils.sk
├── build.xml
├── compiler
└── src
│ └── casper
│ ├── CasperScheduler.java
│ ├── Configuration.java
│ ├── DafnyCodeGenerator.java
│ ├── ExtensionInfo.java
│ ├── JavaLibModel.java
│ ├── Main.java
│ ├── SketchCodeGenerator.java
│ ├── SketchParser.java
│ ├── Topics.java
│ ├── Util.java
│ ├── Version.java
│ ├── ast
│ ├── JavaAbstractExtFactory_c.java
│ ├── JavaExt.java
│ ├── JavaExtFactory.java
│ ├── JavaExtFactory_c.java
│ ├── JavaLang.java
│ ├── JavaLang_c.java
│ ├── JavaNodeFactory.java
│ ├── JavaNodeFactory_c.java
│ └── package.html
│ ├── extension
│ ├── MyStmtExt.java
│ ├── MyWhileExt.java
│ └── package.html
│ ├── package.html
│ ├── parse
│ ├── Grm.java
│ ├── Lexer_c.java
│ ├── casper.flex
│ ├── casper.ppg
│ ├── casper_ppg.cup
│ ├── jl5.ppg
│ ├── jl7.ppg
│ ├── package.html
│ └── sym.java
│ ├── types
│ ├── ArrayAccessNode.java
│ ├── ArrayUpdateNode.java
│ ├── BinaryOperatorNode.java
│ ├── CallNode.java
│ ├── ConditionalNode.java
│ ├── ConstantNode.java
│ ├── CustomASTNode.java
│ ├── Expression.java
│ ├── FieldNode.java
│ ├── IdentifierNode.java
│ ├── JavaTypeSystem.java
│ ├── JavaTypeSystem_c.java
│ ├── MRStage.java
│ ├── UnaryOperatorNode.java
│ ├── Variable.java
│ └── package.html
│ └── visit
│ ├── ExtractInputVariables.java
│ ├── ExtractLoopCounters.java
│ ├── ExtractLoopTerminateConditions.java
│ ├── ExtractOperators.java
│ ├── ExtractOutputVariables.java
│ ├── ExtractUserDefinedDataTypes.java
│ ├── GenerateScaffold.java
│ ├── GenerateSparkCode.java
│ ├── GenerateVerification.java
│ ├── IdentifyDataSet.java
│ ├── SelectLoopsForTranslation.java
│ ├── SelectOptimalSolution.java
│ ├── UpdateConfigurations.java
│ └── package.html
├── lib
├── imagej-1.46.jar
├── java_cup.jar
├── jflex.jar
├── polyglot.jar
├── ppg.jar
└── pth.jar
├── pom1.xml
├── target
└── .gitignore
└── tests
├── Hello.java
├── ProjectTester.java
├── pthScript
└── test.sh
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 | *~
3 | *.mdb
4 | *.dll
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Casper
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.m2e.core.maven2Builder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.m2e.core.maven2Nature
21 | org.eclipse.jdt.core.javanature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=1.8
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
12 | org.eclipse.jdt.core.compiler.source=1.8
13 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk:
3 | - oraclejdk7
4 | before_install:
5 | - sudo apt-get update && sudo apt-get -y install curl
6 | - sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
7 | - echo "deb http://download.mono-project.com/repo/ubuntu precise main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
8 | - curl -sL https://deb.nodesource.com/setup_6.x | sudo bash -
9 | - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
10 | - sudo apt-get update && sudo apt-get install -y bash g++-4.8 flex bison make ant openjdk-7-jdk nodejs unzip mono-complete git wget
11 | - export CXX="g++-4.8" CC="gcc-4.8"
12 | - wget "http://people.csail.mit.edu/asolar/sketch-1.7.2.tar.gz"
13 | - tar -xvzf sketch-1.7.2.tar.gz
14 | - rm sketch-1.7.2.tar.gz
15 | - cd sketch-1.7.2/sketch-backend/
16 | - chmod +x ./configure
17 | - ./configure
18 | - make
19 | - cd ../../
20 | - chmod a+rwx sketch-1.7.2/*
21 | - export PATH="$PATH:/home/travis/build/uwplse/Casper/sketch-1.7.2/sketch-frontend"
22 | - export SKETCH_HOME="/home/travis/build/uwplse/Casper/sketch-1.7.2/sketch-frontend/runtime"
23 | - wget -O dafny-1.9.7.zip "https://github.com/Microsoft/dafny/releases/download/v1.9.7/Dafny.1.9.7.for.Ubuntu.zip"
24 | - unzip dafny-1.9.7.zip -d .
25 | - rm dafny-1.9.7.zip
26 | - chmod -R a+rwx dafny/*
27 | - export PATH="$PATH:/home/travis/build/uwplse/Casper/dafny/"
28 | before_script:
29 | - chmod +x ./tests/ProjectTester.java
30 | - javac -d . ./tests/ProjectTester.java
31 | - ant
32 | jobs:
33 | include:
34 | - script: travis_wait 40 java ProjectTester 1
35 | - script: travis_wait 40 java ProjectTester 2
36 | - script: travis_wait 40 java ProjectTester 3
37 | notifications:
38 | email: false
39 |
--------------------------------------------------------------------------------
/Config.txt:
--------------------------------------------------------------------------------
1 | Inbits=2,
2 | ArraySizeBound=4,
3 | IntRange=4,
4 | LoopUnrollBound=4,
5 | MaxNumMROps=5,
6 | MaxNumEmits=5,
7 | MaxTupleSize=5,
8 | MaxRecursionDepth=5
9 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | # Ubuntu 14.04 as base OS
2 | FROM ubuntu:14.04
3 | MAINTAINER Maaz Ahmad
4 |
5 | # Install dependencies
6 | RUN apt-get update && apt-get -y install curl
7 | RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
8 | RUN echo "deb http://download.mono-project.com/repo/debian wheezy main" | tee /etc/apt/sources.list.d/mono-xamarin.list
9 | RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
10 | RUN apt-get update && apt-get -y install \
11 | bash \
12 | g++ \
13 | flex \
14 | bison \
15 | make \
16 | ant \
17 | openjdk-7-jdk \
18 | nodejs \
19 | unzip \
20 | mono-complete \
21 | git \
22 | wget
23 |
24 | # Install SKETCH
25 | RUN wget "http://people.csail.mit.edu/asolar/sketch-1.7.2.tar.gz"
26 | RUN tar -xvzf sketch-1.7.2.tar.gz
27 | RUN rm sketch-1.7.2.tar.gz
28 | WORKDIR sketch-1.7.2/sketch-backend/
29 | RUN chmod +x ./configure
30 | RUN ./configure
31 | RUN make
32 | WORKDIR ../../
33 | RUN chmod a+rwx sketch-1.7.2/*
34 | ENV PATH $PATH:/sketch-1.7.2/sketch-frontend/
35 | ENV SKETCH_HOME /sketch-1.7.2/sketch-frontend/runtime
36 |
37 | # Install Dafny
38 | RUN wget -O dafny-1.9.9.zip "https://github.com/Microsoft/dafny/releases/download/v1.9.9/dafny-1.9.9.40414-x64-ubuntu-14.04.zip"
39 | RUN unzip dafny-1.9.9.zip -d .
40 | RUN rm dafny-1.9.9.zip
41 | RUN /bin/bash -c "sed $'s/\r$//' ./dafny/dafny > ./dafny/dafny.Unix"
42 | RUN mv /dafny/dafny.Unix /dafny/dafny
43 | RUN chmod -R a+rwx dafny/*
44 | ENV PATH $PATH:/dafny/
45 |
46 | # Clone CASPER
47 | RUN git clone https://github.com/uwplse/Casper.git
48 | WORKDIR Casper/
49 | RUN git reset --hard 834d980
50 | RUN ant
51 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012-2015, University of Washington
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 |
10 | * Redistributions in binary form must reproduce the above copyright notice,
11 | this list of conditions and the following disclaimer in the documentation
12 | and/or other materials provided with the distribution.
13 |
14 | * Neither the name of the University of Washington nor the names of its
15 | contributors may be used to endorse or promote products derived from
16 | this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF WASHINGTON AND CONTRIBUTORS "AS IS"
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF WASHINGTON OR CONTRIBUTORS BE LIABLE
22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/bin/benchmarks/generated/arithmetic/Average.java:
--------------------------------------------------------------------------------
1 | package generated.arithmetic;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple2;
5 |
6 | public class Average {
7 |
8 | public static double avgList(JavaRDD rdd_0_0){
9 | int sum = 0;
10 | sum = 0;
11 | int count = 0;
12 | count = 0;
13 | Tuple2 output_rdd_0_0 = rdd_0_0.map(data_i -> new Tuple2(data_i,1)).reduce((val1, val2) -> new Tuple2((val1._1+val2._1),(val1._2+val2._2)));
14 | count = output_rdd_0_0._2;
15 | sum = output_rdd_0_0._1;
16 | int flat$6 = sum / count;
17 | return flat$6;
18 | }
19 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/arithmetic/ConditionalCount.java:
--------------------------------------------------------------------------------
1 | package generated.arithmetic;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | public class ConditionalCount {
9 | public static Integer countList(JavaRDD rdd_0_0){
10 | int count = 0;
11 | count = 0;
12 | count = rdd_0_0.flatMap(data_i -> {
13 | List emits = new ArrayList();
14 | if(data_i < 100) emits.add(1);
15 | return emits.iterator();
16 | }).reduce((val1, val2) -> (val1+val2));
17 | return count;
18 | }
19 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/arithmetic/ConditionalSum.java:
--------------------------------------------------------------------------------
1 | package generated.arithmetic;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | public class ConditionalSum {
9 | public static Integer sumList(JavaRDD rdd_0_0){
10 | int sum = 0;
11 | sum = 0;
12 | sum = rdd_0_0.flatMap(data_i -> {
13 | List emits = new ArrayList();
14 | if(data_i < 100) emits.add(data_i);
15 | return emits.iterator();
16 | }).reduce((val1, val2) -> (val1+val2));
17 | return sum;
18 | }
19 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/arithmetic/Count.java:
--------------------------------------------------------------------------------
1 | package generated.arithmetic;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | public class Count {
6 | public static Integer countList(JavaRDD rdd_0_0){
7 | int count = 0;
8 | count = 0;
9 | count = rdd_0_0.map(data_i -> 1).reduce((val1, val2) -> (val1+val2));
10 | return count;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/bin/benchmarks/generated/arithmetic/Delta.java:
--------------------------------------------------------------------------------
1 | package generated.arithmetic;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple2;
5 |
6 | public class Delta {
7 | public static Integer calcDelta(JavaRDD rdd_0_0){
8 | int max = 0;
9 | max = Integer.MIN_VALUE;
10 | int min = 0;
11 | min = Integer.MAX_VALUE;
12 | Tuple2 output_rdd_0_0 = rdd_0_0.map(data_i -> new Tuple2(data_i,data_i)).reduce((val1, val2) -> new Tuple2((val1._1 < val2._1 ? val1._1 : val2._1), (val1._2 < val2._2 ? val2._2 : val1._2)));
13 | max = output_rdd_0_0._2;
14 | min = output_rdd_0_0._1;
15 | int flat$7 = max-min;
16 | return flat$7;
17 | }
18 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/arithmetic/Equal.java:
--------------------------------------------------------------------------------
1 | package generated.arithmetic;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | public class Equal {
9 | public static boolean equal(JavaRDD rdd_0_0, int val){
10 | boolean equal = false;
11 | equal = true;
12 | final int val_final = val;
13 | equal = rdd_0_0.flatMap(data_i -> {
14 | List emits = new ArrayList();
15 | if(val_final != data_i) emits.add(false);
16 | return emits.iterator();
17 | }).reduce((val1, val2) -> false);
18 | return equal;
19 | }
20 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/arithmetic/EqualFrequency.java:
--------------------------------------------------------------------------------
1 | package generated.arithmetic;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple2;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 | import java.util.Map;
9 |
10 | public class EqualFrequency {
11 | public static boolean equalFrequency(JavaRDD rdd_0_0) {
12 | int first = 0;
13 | first = 0;
14 | int second = 0;
15 | second = 0;
16 | Map> output_rdd_0_0 = rdd_0_0.flatMapToPair(data_i -> {
17 | List>> emits = new ArrayList>>();
18 | if (data_i == 110) emits.add(new Tuple2(2, new Tuple2(2, 1)));
19 | if (data_i == 100) emits.add(new Tuple2(1, new Tuple2(1, 1)));
20 | return emits.iterator();
21 | }).reduceByKey((val1, val2) -> {
22 | if (val1._1 == 1) return new Tuple2(val1._1, (val2._2 + val1._2));
23 | else if (val1._1 == 2) return new Tuple2(val1._1, (val1._2 + val2._2));
24 | else return null;
25 | }).collectAsMap();
26 | second = output_rdd_0_0.get(2)._2;
27 | first = output_rdd_0_0.get(1)._2;
28 | boolean flat$7 = first == second;
29 | return flat$7;
30 | }
31 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/arithmetic/Max.java:
--------------------------------------------------------------------------------
1 | package generated.arithmetic;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | public class Max {
6 | public static int maxList(JavaRDD rdd_0_0){
7 | int max = 0;
8 | max = Integer.MIN_VALUE;
9 | max = rdd_0_0.reduce((val1, val2) -> (val2 > val1 ? val2 : val1));
10 | return max;
11 | }
12 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/arithmetic/MaxAbs.java:
--------------------------------------------------------------------------------
1 | package generated.arithmetic;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | public class MaxAbs {
6 | public static int maxAbsList(JavaRDD rdd_0_0){
7 | int max = 0;
8 | max = Integer.MIN_VALUE;
9 | max = rdd_0_0.reduce((val1, val2) -> (Math.abs(val1) > Math.abs(val2) ? val1 : val2));
10 | return max;
11 | }
12 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/arithmetic/Min.java:
--------------------------------------------------------------------------------
1 | package generated.arithmetic;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | public class Min {
6 | public static int minList(JavaRDD rdd_0_0){
7 | int min = 0;
8 | min = Integer.MAX_VALUE;
9 | min = rdd_0_0.reduce((val1, val2) -> (val2 > val1 ? val1 : val2));
10 | return min;
11 | }
12 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/arithmetic/Sum.java:
--------------------------------------------------------------------------------
1 | package generated.arithmetic;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | public class Sum {
6 | public static int sumList(JavaRDD rdd_0_0){
7 | int sum = 0;
8 | sum = 0;
9 | sum = rdd_0_0.reduce((val1, val2) -> (val1 + val2));
10 | return sum;
11 | }
12 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/bigλ/CyclingSpeed.java:
--------------------------------------------------------------------------------
1 | package generated.bigλ;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple2;
5 |
6 | import java.util.HashMap;
7 | import java.util.Map;
8 |
9 | public class CyclingSpeed {
10 | class Record {
11 | public int fst;
12 | public int snd;
13 | public int emit;
14 | public double speed;
15 | }
16 |
17 | public Map cyclingSpeed(JavaRDD rdd_0_0){
18 | Map result = null;
19 | result = new HashMap();
20 |
21 | result = rdd_0_0.mapToPair(data_index -> new Tuple2((int)Math.ceil(data_index.speed), 1)).reduceByKey((val1, val2) -> (val2+val1)).collectAsMap();
22 |
23 | return result;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/bin/benchmarks/generated/bigλ/DatabaseSelect.java:
--------------------------------------------------------------------------------
1 | package generated.bigλ;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | public class DatabaseSelect {
9 |
10 | class Record {
11 | public List columns;
12 | }
13 |
14 | public List select(JavaRDD rdd_0_0, String key){
15 | List result = null;
16 | result = new ArrayList();
17 |
18 | final String key_final = key;
19 | result = rdd_0_0.flatMap(data_index -> {
20 | List emits = new ArrayList();
21 | if(data_index.columns.get(0).equals(key_final)) emits.add(data_index);
22 | return emits.iterator();
23 | }).collect();
24 |
25 | return result;
26 | }
27 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/bigλ/ShakespearSentiment.java:
--------------------------------------------------------------------------------
1 | package generated.bigλ;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple2;
5 |
6 | import java.util.ArrayList;
7 | import java.util.HashMap;
8 | import java.util.List;
9 | import java.util.Map;
10 |
11 | public class ShakespearSentiment {
12 | public Map sentiment(JavaRDD rdd_0_0){
13 | Map result = null;
14 | result = new HashMap();
15 |
16 | result.put("love", 0);
17 | result.put("hate", 0);
18 |
19 | result = rdd_0_0.flatMapToPair(words_index -> {
20 | List> emits = new ArrayList>();
21 | if("hate".equals(words_index.trim().toLowerCase())) emits.add(new Tuple2(words_index, 1));
22 | if(words_index.trim().toLowerCase().equals("love")) emits.add(new Tuple2(words_index, 1));
23 | return emits.iterator();
24 | }).reduceByKey((val1, val2) -> (val2+val1)).collectAsMap();
25 |
26 | return result;
27 | }
28 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/bigλ/TwitterCounts.java:
--------------------------------------------------------------------------------
1 | package generated.bigλ;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple2;
5 |
6 | import java.util.*;
7 |
8 | public class TwitterCounts {
9 | public Map pairs(JavaRDD rdd_0_0) {
10 | Map result = null;
11 | result = new HashMap();
12 |
13 | result = rdd_0_0.flatMap(tweets_index -> {
14 | List emits = new ArrayList();
15 | emits = Arrays.asList(tweets_index.split("\\s+"));
16 | return emits.iterator();
17 | }).flatMapToPair(val -> {
18 | List> emits = new ArrayList>();
19 | if('#' == val.charAt(0)) emits.add(new Tuple2(val, 1));
20 | return emits.iterator();
21 | }).reduceByKey((val1, val2) -> val1+val2).collectAsMap();
22 |
23 | return result;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/bin/benchmarks/generated/bigλ/WikiPageCount.java:
--------------------------------------------------------------------------------
1 | package generated.bigλ;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple2;
5 |
6 | import java.util.HashMap;
7 | import java.util.Map;
8 |
9 | public class WikiPageCount {
10 | class Record {
11 | public String name;
12 | public int views;
13 | public int something;
14 | }
15 |
16 | public Map pageCount(JavaRDD rdd_0_0){
17 | Map result = null;
18 | result = new HashMap();
19 |
20 | result = rdd_0_0.mapToPair(data_index -> new Tuple2(data_index.name,data_index.views)).reduceByKey((val1, val2) -> (val2+val1)).collectAsMap();
21 |
22 | return result;
23 | }
24 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/bigλ/YelpKids.java:
--------------------------------------------------------------------------------
1 | package generated.bigλ;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple2;
5 |
6 | import java.util.ArrayList;
7 | import java.util.HashMap;
8 | import java.util.List;
9 | import java.util.Map;
10 |
11 | public class YelpKids {
12 | class Record {
13 | public String state;
14 | public String city;
15 | public String comment;
16 | public int score;
17 | public boolean goodForKids;
18 | }
19 |
20 | public Map reviewCount(JavaRDD rdd_0_0){
21 | Map result = null;
22 | result = new HashMap();
23 |
24 | result = rdd_0_0.flatMapToPair(data_index -> {
25 | List> emits = new ArrayList>();
26 | if(data_index.goodForKids) emits.add(new Tuple2(data_index.city, 1));
27 | return emits.iterator();
28 | }
29 | ).reduceByKey((val1, val2) -> (val2+val1)).collectAsMap();
30 |
31 | return result;
32 | }
33 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/fiji/IJ_RedToMagenta/Benchmark0.java:
--------------------------------------------------------------------------------
1 | package generated.fiji.IJ_RedToMagenta;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple3;
5 |
6 | /**
7 | * Convert_Red_To_Magenta.java: line 37
8 | */
9 | public class Benchmark0 {
10 | public JavaRDD> benchmark(JavaRDD> rdd_0_0, int w, int h) {
11 | return rdd_0_0.map(pixels_i -> new Tuple3(pixels_i._1(), pixels_i._2(), (((pixels_i._3() >> 16) & 0xff) << 16) | (((pixels_i._3() >> 8) & 0xff) << 8) | ((pixels_i._3() >> 16) & 0xff)));
12 | }
13 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/fiji/IJ_Temporal/Benchmark0.java:
--------------------------------------------------------------------------------
1 | package generated.fiji.IJ_Temporal;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple3;
5 |
6 | /**
7 | * TemporalMedian_.java: line 142
8 | */
9 | public class Benchmark0 {
10 | public JavaRDD> benchmark(JavaRDD> rdd_0_0, int w, int h) {
11 | return rdd_0_0.map(pix_i -> new Tuple3(pix_i._1(),pix_i._2(),Math.sqrt(pix_i._3() + 3 / 8) * 2));
12 | }
13 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/fiji/IJ_Temporal/Benchmark1.java:
--------------------------------------------------------------------------------
1 | package generated.fiji.IJ_Temporal;
2 |
3 | import org.apache.spark.api.java.JavaPairRDD;
4 | import org.apache.spark.api.java.JavaRDD;
5 | import scala.Tuple2;
6 | import scala.Tuple3;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | /**
12 | * TemporalMedian_.java: line 169
13 | */
14 | public class Benchmark1 {
15 | public JavaPairRDD benchmark(JavaRDD> rdd_0_0, int v, int wmin, int wmax) {
16 | return rdd_0_0.flatMapToPair(tWinPix_i -> {
17 | List> emits = new ArrayList<>();
18 | if (v == tWinPix_i._2()) new Tuple2(tWinPix_i._1(), tWinPix_i._3());
19 | return emits.iterator();
20 | });
21 | }
22 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/fiji/IJ_Temporal/Benchmark2.java:
--------------------------------------------------------------------------------
1 | package generated.fiji.IJ_Temporal;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple3;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | /**
10 | * TemporalMedian_.java: line 189
11 | */
12 | public class Benchmark2 {
13 | public JavaRDD> benchmark(JavaRDD> rdd_0_0, int wmax) {
14 | return rdd_0_0.flatMap(tWinPix_i -> {
15 | List> emits = new ArrayList<>();
16 | if (tWinPix_i._1() != 0) emits.add(new Tuple3(tWinPix_i._1()-1,tWinPix_i._2(),tWinPix_i._3()));
17 | return emits.iterator();
18 | });
19 | }
20 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/fiji/IJ_Temporal/Benchmark3.java:
--------------------------------------------------------------------------------
1 | package generated.fiji.IJ_Temporal;
2 |
3 | import org.apache.spark.api.java.JavaPairRDD;
4 |
5 | /**
6 | * TemporalMedian_.java: line 217
7 | */
8 | public class Benchmark3 {
9 | public float benchmark(JavaPairRDD rdd_0_0) {
10 | return rdd_0_0.map(vec_i -> vec_i._2).reduce((v1,v2) -> v2 + v1);
11 | }
12 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/fiji/IJ_Temporal/Benchmark4.java:
--------------------------------------------------------------------------------
1 | package generated.fiji.IJ_Temporal;
2 |
3 | import org.apache.spark.api.java.JavaPairRDD;
4 |
5 | /**
6 | * TemporalMedian_.java: line 221
7 | */
8 | public class Benchmark4 {
9 | public float benchmark(JavaPairRDD rdd_0_0, float mean) {
10 | return rdd_0_0.map(vec_i -> (vec_i._2 - mean) * (vec_i._2 - mean)).reduce((v1,v2) -> v1 + v2);
11 | }
12 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/fiji/IJ_Trails/Benchmark0.java:
--------------------------------------------------------------------------------
1 | package generated.fiji.IJ_Trails;
2 |
3 | import org.apache.spark.api.java.JavaPairRDD;
4 | import org.apache.spark.api.java.JavaRDD;
5 | import scala.Tuple2;
6 | import scala.Tuple3;
7 |
8 | public class Benchmark0 {
9 | public JavaPairRDD benchmark(JavaRDD> rdd_0_0, int wcurr, int wmin, int wmax) {
10 | return rdd_0_0.mapToPair(tWinPix_i -> new Tuple2>(tWinPix_i._2(), new Tuple2<>(1, tWinPix_i._3()))).reduceByKey((v1,v2) -> new Tuple2(v1._1+v2._1,v1._2+v2._2)).mapValues(v -> v._2/v._1);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/bin/benchmarks/generated/fiji/IJ_Trails/Benchmark1.java:
--------------------------------------------------------------------------------
1 | package generated.fiji.IJ_Trails;
2 |
3 | import org.apache.spark.api.java.JavaPairRDD;
4 | import org.apache.spark.api.java.JavaRDD;
5 | import scala.Tuple2;
6 | import scala.Tuple3;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | /**
12 | * Trails_.java: line 151
13 | */
14 | public class Benchmark1 {
15 | public JavaPairRDD benchmark(JavaRDD> rdd_0_0, int v, int wmin, int wmax) {
16 | return rdd_0_0.flatMapToPair(tWinPix_i -> {
17 | List> emits = new ArrayList<>();
18 | if (v == tWinPix_i._2()) new Tuple2(tWinPix_i._1(), tWinPix_i._3());
19 | return emits.iterator();
20 | });
21 | }
22 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/fiji/IJ_Trails/Benchmark2.java:
--------------------------------------------------------------------------------
1 | package generated.fiji.IJ_Trails;
2 |
3 | import org.apache.spark.api.java.JavaPairRDD;
4 |
5 | /**
6 | * Trails_.java: line 160
7 | */
8 | public class Benchmark2 {
9 | public float benchmark(JavaPairRDD rdd_0_0) {
10 | return rdd_0_0.map(tvec_i -> tvec_i._2).reduce((v1,v2) -> v2 + v1);
11 | }
12 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/fiji/IJ_Trails/Benchmark3.java:
--------------------------------------------------------------------------------
1 | package generated.fiji.IJ_Trails;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple3;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | /**
10 | * Trails_.java: line 169
11 | */
12 | public class Benchmark3 {
13 | public JavaRDD> benchmark(JavaRDD> rdd_0_0, int wmax) {
14 | return rdd_0_0.flatMap(tWinPix_i -> {
15 | List> emits = new ArrayList<>();
16 | if (tWinPix_i._1() != 0) emits.add(new Tuple3(tWinPix_i._1()-1,tWinPix_i._2(),tWinPix_i._3()));
17 | return emits.iterator();
18 | });
19 | }
20 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/phoenix/Histogram.java:
--------------------------------------------------------------------------------
1 | package generated.phoenix;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple2;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 | import java.util.Map;
9 |
10 | class Histogram {
11 | public static class Pixel {
12 | public int r;
13 | public int g;
14 | public int b;
15 |
16 | public Pixel(int r, int g, int b) {
17 | super();
18 | this.r = r;
19 | this.g = g;
20 | this.b = b;
21 | }
22 | }
23 |
24 | public static int[][] histogram(JavaRDD rdd_0_0, int[] hR, int[] hG, int[] hB) {
25 | int i = 0;
26 | Map,Integer> rdd_0_0_output = rdd_0_0.flatMapToPair(image_i -> {
27 | List,Integer>> emits = new ArrayList,Integer>>();
28 | emits.add(new Tuple2(new Tuple2(0, image_i.g),1));
29 | emits.add(new Tuple2(new Tuple2(1, image_i.b),1));
30 | emits.add(new Tuple2(new Tuple2(2, image_i.r),1));
31 | return emits.iterator();
32 | }).reduceByKey((v1,v2) -> v1 + v2).collectAsMap();
33 | for (Tuple2 rdd_0_0_output_k : rdd_0_0_output.keySet()) {
34 | if (rdd_0_0_output_k._1 == 0) {
35 | hG[rdd_0_0_output_k._2] = rdd_0_0_output.get(rdd_0_0_output_k);
36 | }
37 | if (rdd_0_0_output_k._1 == 1) {
38 | hB[rdd_0_0_output_k._2] = rdd_0_0_output.get(rdd_0_0_output_k);
39 | }
40 | if (rdd_0_0_output_k._1 == 2) {
41 | hR[rdd_0_0_output_k._2] = rdd_0_0_output.get(rdd_0_0_output_k);
42 | }
43 | }
44 | int[][] result = (int[][]) (new int[3][]);
45 | ((int[][]) result)[0] = (int[]) hR;
46 | ((int[][]) result)[1] = (int[]) hG;
47 | ((int[][]) result)[2] = (int[]) hB;
48 | return (int[][]) result;
49 | }
50 |
51 | public Histogram() { super(); }
52 | }
53 |
--------------------------------------------------------------------------------
/bin/benchmarks/generated/phoenix/LinearRegression.java:
--------------------------------------------------------------------------------
1 | package generated.phoenix;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple5;
5 |
6 | public class LinearRegression {
7 | public static class Point {
8 | public int x;
9 | public int y;
10 |
11 | public Point(int x, int y) {
12 | super();
13 | this.x = x;
14 | this.y = y;
15 | }
16 | }
17 |
18 | public static int[] regress(JavaRDD rdd_0_0) {
19 | int SX_ll = 0;
20 | int SY_ll = 0;
21 | int SXX_ll = 0;
22 | int SYY_ll = 0;
23 | int SXY_ll = 0;
24 | int i = 0;
25 | Tuple5 rdd_0_0_output = rdd_0_0.map(points_i -> new Tuple5(points_i.x*points_i.y,points_i.x*points_i.x,points_i.y,points_i.y*points_i.y,points_i.x)).reduce((v1,v2) -> new Tuple5(v1._1()+v2._1(),v1._2()+v2._2(),v1._3()+v2._3(),v1._4()+v2._4(),v1._5()+v2._5()));
26 | SXY_ll = rdd_0_0_output._1();
27 | SXX_ll = rdd_0_0_output._2();
28 | SY_ll = rdd_0_0_output._3();
29 | SYY_ll = rdd_0_0_output._4();
30 | SX_ll = rdd_0_0_output._5();
31 | int[] result = (int[]) (new int[5]);
32 | ((int[]) result)[0] = SX_ll;
33 | ((int[]) result)[1] = SXX_ll;
34 | ((int[]) result)[2] = SY_ll;
35 | ((int[]) result)[3] = SYY_ll;
36 | ((int[]) result)[4] = SXY_ll;
37 | return (int[]) result;
38 | }
39 |
40 | public LinearRegression() { super(); }
41 | }
42 |
--------------------------------------------------------------------------------
/bin/benchmarks/generated/phoenix/StringMatch.java:
--------------------------------------------------------------------------------
1 | package generated.phoenix;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple2;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 | import java.util.Map;
9 |
10 | public class StringMatch {
11 | public static boolean[] matchWords(JavaRDD rdd_0_0) {
12 | String key1 = "key1";
13 | String key2 = "key2";
14 | String key3 = "key3";
15 | boolean foundKey1 = false;
16 | boolean foundKey2 = false;
17 | boolean foundKey3 = false;
18 | int i = 0;
19 | Map rdd_0_0_output = rdd_0_0.flatMapToPair(words_i -> {
20 | List> emits = new ArrayList>();
21 | if (words_i.equals(key3)) emits.add(new Tuple2(2,true));
22 | if (key1.equals(words_i)) emits.add(new Tuple2(3,true));
23 | if (key2.equals(words_i)) emits.add(new Tuple2(1,true));
24 | return emits.iterator();
25 | }).reduceByKey((v1,v2) -> v2 || v1).collectAsMap();
26 | if (rdd_0_0_output.containsKey(2)) foundKey3 = rdd_0_0_output.get(2);
27 | if (rdd_0_0_output.containsKey(3)) foundKey1 = rdd_0_0_output.get(3);
28 | if (rdd_0_0_output.containsKey(1)) foundKey2 = rdd_0_0_output.get(1);
29 | boolean[] res = { foundKey1, foundKey2, foundKey3 };
30 | return (boolean[]) res;
31 | }
32 |
33 | public StringMatch() { super(); }
34 | }
35 |
--------------------------------------------------------------------------------
/bin/benchmarks/generated/phoenix/WordCount.java:
--------------------------------------------------------------------------------
1 | package generated.phoenix;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple2;
5 |
6 | import java.util.HashMap;
7 | import java.util.Map;
8 |
9 | public class WordCount {
10 | private static Map countWords(JavaRDD rdd_0_0) {
11 | Map counts = new HashMap();
12 | int j = 0;
13 | counts = rdd_0_0.mapToPair(words_i -> new Tuple2(words_i, 1)).reduceByKey((v1,v2) -> v2 + v1).collectAsMap();
14 | return (Map) counts;
15 | }
16 |
17 | public WordCount() { super(); }
18 | }
19 |
--------------------------------------------------------------------------------
/bin/benchmarks/generated/stats/IOUtil.java:
--------------------------------------------------------------------------------
1 | package generated.stats;
2 |
3 | import java.util.Scanner;
4 | import java.io.*;
5 |
6 | public class IOUtil {
7 | public static double skipToDouble(Scanner scanner) {
8 | while (((Scanner) scanner).hasNext() &&
9 | !((Scanner) scanner).hasNextDouble()) {
10 | ((Scanner) scanner).next();
11 | }
12 | return ((Scanner) scanner).hasNextDouble()
13 | ? ((Scanner) scanner).nextDouble()
14 | : Double.NaN;
15 | }
16 |
17 | public static FileReader file(String fileName)
18 | throws FileNotFoundException {
19 | return new FileReader((String) fileName);
20 | }
21 |
22 | public static String typedInput() throws IOException {
23 | BufferedReader keyIn =
24 | new BufferedReader(new InputStreamReader(System.in));
25 | return ((BufferedReader) keyIn).readLine();
26 | }
27 |
28 | /**
29 |
30 | * does not accept anything but integers
31 |
32 | * @ return the first integer value
33 |
34 | */
35 | public static int skipToInt(Scanner scanner) {
36 | while (((Scanner) scanner).hasNext() &&
37 | !((Scanner) scanner).hasNextInt()) {
38 | ((Scanner) scanner).next();
39 | }
40 | return ((Scanner) scanner).hasNextInt()
41 | ? ((Scanner) scanner).nextInt()
42 | : (int) Double.NaN;
43 | }
44 |
45 | /**
46 |
47 | * Call this every time wrong thing is typed.
48 |
49 | */
50 | public static void abuse() {
51 | System.out.println("Invalid entry.");
52 | System.out.println("Abusive statement.");
53 | System.exit(0);
54 | }
55 |
56 | public static String fileName() throws IOException {
57 | System.out.printf("Type file name or hit \'!\' \n",
58 | (Object[]) (new Object[] { }));
59 | String typed = typedInput();
60 | System.out.printf("Found %s \n", (Object[]) (new Object[] { typed }));
61 | return (String) typed;
62 | }
63 |
64 | public static String getFileName() throws IOException {
65 | System.out.printf("Type file name or hit \'!\' \n",
66 | (Object[]) (new Object[] { }));
67 | String typed = typedInput();
68 | System.out.printf("Found %s \n", (Object[]) (new Object[] { typed }));
69 | return (String) typed;
70 | }
71 |
72 | public static String enterValue(String kindOf) {
73 | return (String) ("Enter " + kindOf + "value:");
74 | }
75 |
76 | public IOUtil() { super(); }
77 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/stats/PlotReader.java:
--------------------------------------------------------------------------------
1 | package generated.stats;
2 |
3 | import java.util.Scanner;
4 |
5 | public class PlotReader {
6 | public static double[] data1Column(Scanner scan, int length) {
7 | double[] data = (double[]) (new double[length]);
8 | int i = 0;
9 | while (i < ((double[]) data).length) {
10 | ((double[]) data)[i] = IOUtil.skipToDouble((Scanner) scan);
11 | i++;
12 | }
13 | return (double[]) data;
14 | }
15 |
16 | public static double[][] data2Column(Scanner scan, int length) {
17 | double[][] data = (double[][]) (new double[length][2]);
18 | int i = 0;
19 | while (i < ((double[][]) data).length) {
20 | int j = 0;
21 | while (j < ((double[]) ((double[][]) data)[0]).length) {
22 | ((double[]) ((double[][]) data)[i])[j] =
23 | (float) IOUtil.skipToDouble((Scanner) scan);
24 | j++;
25 | }
26 | i++;
27 | }
28 | return (double[][]) data;
29 | }
30 |
31 | public static double[][] data3Column(Scanner scan, int length) {
32 | double[][] data = (double[][]) (new double[length][3]);
33 | int i = 0;
34 | while (i < ((double[][]) data).length) {
35 | int j = 0;
36 | while (j < ((double[]) ((double[][]) data)[0]).length) {
37 | ((double[]) ((double[][]) data)[i])[j] =
38 | (float) IOUtil.skipToDouble((Scanner) scan);
39 | j++;
40 | }
41 | i++;
42 | }
43 | return (double[][]) data;
44 | }
45 |
46 | public static double[][] data4Column(Scanner scan, int length) {
47 | double[][] data = (double[][]) (new double[length][4]);
48 | int i = 0;
49 | while (i < ((double[][]) data).length) {
50 | int j = 0;
51 | while (j < ((double[]) ((double[][]) data)[0]).length) {
52 | ((double[]) ((double[][]) data)[i])[j] =
53 | (float) IOUtil.skipToDouble((Scanner) scan);
54 | j++;
55 | }
56 | i++;
57 | }
58 | return (double[][]) data;
59 | }
60 |
61 | public PlotReader() { super(); }
62 | }
--------------------------------------------------------------------------------
/bin/benchmarks/generated/stats/PlotUtil.java:
--------------------------------------------------------------------------------
1 | package generated.stats;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | import java.io.PrintWriter;
6 |
7 | /**
8 |
9 | * PlotUtil.java
10 |
11 | * =============
12 |
13 | *
14 |
15 | * Copyright (C) 2013-2014 Magdalen Berns
16 |
17 | *
18 |
19 | * This program is free software: you can redistribute it and/or modify
20 |
21 | * it under the terms of the GNU General Public License as published by
22 |
23 | * the Free Software Foundation, either version 3 of the License, or
24 |
25 | * (at your option) any later version.
26 |
27 | *
28 |
29 | * This program is distributed in the hope that it will be useful,
30 |
31 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 |
33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 |
35 | * GNU General Public License for more details.
36 |
37 |
38 |
39 | * You should have received a copy of the GNU General Public License
40 |
41 | * along with this program. If not, see .
42 |
43 | */
44 | public class PlotUtil extends IOUtil {
45 | private double[] x;
46 | private double[] y;
47 | private JavaRDD data;
48 |
49 | public PlotUtil(JavaRDD rdd_0_0) {
50 | super();
51 | this.data = (JavaRDD) data;
52 | x = (double[]) (new double[(int)rdd_0_0.count()]);
53 | y = (double[]) (new double[(int)rdd_0_0.count()]);
54 | }
55 |
56 | /**
57 |
58 | * x
59 |
60 | * Pull out the x column data
61 |
62 | * @return:
63 |
64 | * The x component of a 1d array of doubles
65 |
66 | */
67 | public JavaRDD x(){
68 | return data.map(data_i -> data_i[0]);
69 | }
70 |
71 | /**
72 |
73 | * x
74 |
75 | * Pull out the y column data
76 |
77 | * @return
78 |
79 | * The y component of a 1d array of doubles
80 |
81 | */
82 | public JavaRDD y(){
83 | return data.map(data_i -> data_i[1]);
84 | }
85 |
86 | /**
87 |
88 | * removeOffset
89 |
90 | * Convenience function to remove the y intecept offset value
91 |
92 | * @return
93 |
94 | * The 2D data array of doubles with offset removed.
95 |
96 | */
97 | public static JavaRDD removeOffset(JavaRDD rdd_1_0, double offset){
98 | return rdd_1_0.map(data_i -> {
99 | data_i[0] = data_i[0] - offset;
100 | return data_i;
101 | });
102 | }
103 |
104 | public static void writeToFile(double[][] data, PrintWriter fileOut) {
105 | int i = 0;
106 | while (i < ((double[][]) data).length) {
107 | ((PrintWriter) fileOut).
108 | printf("%2.5f %2.5f",
109 | (Object[])
110 | (new Object[] { Double.valueOf(((double[])
111 | ((double[][])
112 | data)[i])[0]),
113 | Double.valueOf(((double[])
114 | ((double[][]) data)[i])[1]) }));
115 | ((PrintWriter) fileOut).println();
116 | i++;
117 | }
118 | }
119 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/arithmetic/Average.java:
--------------------------------------------------------------------------------
1 | package manual.arithmetic;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple2;
5 |
6 | public class Average {
7 |
8 | public static double avgList(JavaRDD data){
9 | Tuple2 sumcount = data.aggregate(
10 | new Tuple2(0,0),
11 | (res, val) -> new Tuple2(res._1 + val, res._2 + 1),
12 | (res1, res2) -> new Tuple2(res1._1 + res2._1, res1._2 + res2._2));
13 | return sumcount._1 / sumcount._2;
14 | }
15 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/arithmetic/ConditionalCount.java:
--------------------------------------------------------------------------------
1 | package manual.arithmetic;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | public class ConditionalCount {
6 | public static Integer countList(JavaRDD data){
7 | return data.aggregate(
8 | 0,
9 | (count, a) -> (a < 100 ? count + 1 : count),
10 | (c1, c2) -> c1 + c2
11 | );
12 | }
13 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/arithmetic/ConditionalSum.java:
--------------------------------------------------------------------------------
1 | package manual.arithmetic;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | public class ConditionalSum {
6 | public static Integer sumList(JavaRDD data){
7 | return data.aggregate(
8 | 0,
9 | (sum, a) -> (a < 100 ? sum + a : sum),
10 | (s1, s2) -> s1 + s2
11 | );
12 | }
13 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/arithmetic/Count.java:
--------------------------------------------------------------------------------
1 | package manual.arithmetic;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | public class Count {
6 | public static int countList(JavaRDD data){
7 | return (int) data.count();
8 | }
9 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/arithmetic/Delta.java:
--------------------------------------------------------------------------------
1 | package manual.arithmetic;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple2;
5 |
6 | public class Delta {
7 | public static int deltaList(JavaRDD data){
8 | Tuple2 minmax = data.aggregate(
9 | new Tuple2(Integer.MIN_VALUE,Integer.MAX_VALUE),
10 | (res, val) -> new Tuple2(Math.max(res._1,val), Math.min(res._2,val)),
11 | (res1, res2) -> new Tuple2(Math.max(res1._1,res2._1), Math.min(res1._2, res2._2)));
12 | return minmax._1 - minmax._2;
13 | }
14 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/arithmetic/Equal.java:
--------------------------------------------------------------------------------
1 | package manual.arithmetic;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | public class Equal {
6 | public static boolean equal(JavaRDD data, int val){
7 | return (boolean) data.filter(a -> a != val).isEmpty();
8 | }
9 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/arithmetic/EqualFrequency.java:
--------------------------------------------------------------------------------
1 | package manual.arithmetic;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple2;
5 |
6 | public class EqualFrequency {
7 | public static boolean equalFrequency(JavaRDD data){
8 | Tuple2 freq = data.aggregate(
9 | new Tuple2(0, 0),
10 | (res, val) -> new Tuple2((val == 100? res._1 + 1 : res._1), (val == 110? res._2 + 1 : res._2)),
11 | (res1, res2) -> new Tuple2(res1._1 + res2._1, res1._2 + res2._2));
12 | return freq._1 == freq._2;
13 | }
14 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/arithmetic/Max.java:
--------------------------------------------------------------------------------
1 | package manual.arithmetic;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | public class Max {
6 | public static int maxList(JavaRDD data){
7 | return data.reduce((a, b) -> Math.max(a, b));
8 | }
9 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/arithmetic/MaxAbs.java:
--------------------------------------------------------------------------------
1 | package manual.arithmetic;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | public class MaxAbs {
6 | public static int maxAbsList(JavaRDD data){
7 | return data.reduce((a, b) -> Math.max(Math.abs(a), Math.abs(b)));
8 | }
9 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/arithmetic/Min.java:
--------------------------------------------------------------------------------
1 | package manual.arithmetic;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | public class Min {
6 | public static int minList(JavaRDD data){
7 | return data.reduce((a, b) -> Math.min(a, b));
8 | }
9 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/arithmetic/Sum.java:
--------------------------------------------------------------------------------
1 | package manual.arithmetic;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | public class Sum {
6 | public static int sumList(JavaRDD data){
7 | return data.reduce((a, b) -> a+b);
8 | }
9 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/bigλ/CyclingSpeed.java:
--------------------------------------------------------------------------------
1 | package manual.bigλ;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple2;
5 |
6 | import java.util.Map;
7 |
8 | public class CyclingSpeed {
9 | class Record {
10 | public int fst;
11 | public int snd;
12 | public int emit;
13 | public double speed;
14 | }
15 |
16 | public Map cyclingSpeed(JavaRDD data){
17 | return data.mapToPair(r -> new Tuple2((int)Math.ceil(r.speed),1)).reduceByKey((a, b) -> a+b).collectAsMap();
18 | }
19 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/bigλ/DatabaseSelect.java:
--------------------------------------------------------------------------------
1 | package manual.bigλ;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | import java.util.List;
6 |
7 | public class DatabaseSelect {
8 |
9 | class Record {
10 | public List columns;
11 | }
12 |
13 | public List select(JavaRDD table, String key){
14 | return table.filter(r -> r.columns.get(0).equals(key)).collect();
15 | }
16 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/bigλ/ShakespearSentiment.java:
--------------------------------------------------------------------------------
1 | package manual.bigλ;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | import java.util.HashMap;
6 | import java.util.Map;
7 |
8 | public class ShakespearSentiment {
9 | public Map sentiment(JavaRDD words){
10 | Map result = new HashMap();
11 | result.put("love", 0);
12 | result.put("hate", 0);
13 |
14 | result = words.aggregate(
15 | result,
16 | (res, word) -> {
17 | if (word.trim().toLowerCase().equals("love")) {
18 | res.put("love", res.get("love")+1);
19 | }
20 | if (word.trim().toLowerCase().equals("hate")) {
21 | res.put("hate", res.get("hate")+1);
22 | }
23 | return res;
24 | },
25 | (res1, res2) -> {
26 | res1.put("love", res1.get("love") + res2.get("love"));
27 | res1.put("hate", res1.get("hate") + res2.get("hate"));
28 | return res1;
29 | }
30 | );
31 |
32 | return result;
33 | }
34 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/bigλ/TwitterCounts.java:
--------------------------------------------------------------------------------
1 | package manual.bigλ;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple2;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 | import java.util.Map;
9 |
10 | public class TwitterCounts {
11 | public Map pairs(JavaRDD tweets) {
12 | return tweets.flatMapToPair(tweet -> {
13 | List> freq = new ArrayList>();
14 | for (String word : tweet.split("\\s+")) {
15 | if (word.charAt(0) == '#') {
16 | freq.add(new Tuple2(word, 1));
17 | }
18 | }
19 | return freq.iterator();
20 | }).reduceByKey((a, b) -> a+b).collectAsMap();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/bin/benchmarks/manual/bigλ/WikiPageCount.java:
--------------------------------------------------------------------------------
1 | package manual.bigλ;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple2;
5 |
6 | import java.util.Map;
7 |
8 | public class WikiPageCount {
9 | class Record {
10 | public String name;
11 | public int views;
12 | public int something;
13 | }
14 |
15 | public Map pageCount(JavaRDD data){
16 | return data.mapToPair(r -> new Tuple2(r.name,r.views)).reduceByKey((a, b) -> a+b).collectAsMap();
17 | }
18 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/bigλ/YelpKids.java:
--------------------------------------------------------------------------------
1 | package manual.bigλ;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple2;
5 |
6 | import java.util.Map;
7 |
8 | public class YelpKids {
9 | class Record {
10 | public String state;
11 | public String city;
12 | public String comment;
13 | public int score;
14 | public boolean goodForKids;
15 | }
16 |
17 | public Map reviewCount(JavaRDD data){
18 | return data.mapToPair(r -> new Tuple2(r.city,1)).reduceByKey((a, b) -> a+b).collectAsMap();
19 | }
20 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/fiji/IJ_RedToMagenta/Benchmark0.java:
--------------------------------------------------------------------------------
1 | package manual.fiji.IJ_RedToMagenta;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | /**
6 | * Convert_Red_To_Magenta.java: line 37
7 | */
8 | public class Benchmark0 {
9 | class Pixel {
10 | int row;
11 | int col;
12 | int val;
13 | public Pixel(int r, int c, int v) {
14 | row = r;
15 | col = c;
16 | val = v;
17 | }
18 | }
19 |
20 | public JavaRDD benchmark(JavaRDD pixels, int w, int h) {
21 | return pixels.map(pixel -> {
22 | int value = pixel.val;
23 | int red = (value >> 16) & 0xff;
24 | int green = (value >> 8) & 0xff;
25 | int blue = value & 0xff;
26 | if (false && blue > 16)
27 | return pixel;
28 | else
29 | return new Pixel(pixel.row, pixel.col, (red << 16) | (green << 8) | red);
30 | });
31 | }
32 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/fiji/IJ_Temporal/Benchmark0.java:
--------------------------------------------------------------------------------
1 | package manual.fiji.IJ_Temporal;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | /**
6 | * TemporalMedian_.java: line 142
7 | */
8 | public class Benchmark0 {
9 | class Pixel {
10 | int frame;
11 | int pos;
12 | float val;
13 | public Pixel(int f, int p, float v) {
14 | frame = f;
15 | pos = p;
16 | val = v;
17 | }
18 | }
19 |
20 | public JavaRDD benchmark(JavaRDD pixels, int w, int h) {
21 | return pixels.map(pixel -> {
22 | double transf = 2 * Math.sqrt(pixel.val + 3 / 8);
23 | return new Pixel(pixel.frame, pixel.pos, (float)transf);
24 | });
25 | }
26 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/fiji/IJ_Temporal/Benchmark1.java:
--------------------------------------------------------------------------------
1 | package manual.fiji.IJ_Temporal;
2 |
3 | import org.apache.spark.api.java.JavaPairRDD;
4 | import org.apache.spark.api.java.JavaRDD;
5 | import scala.Tuple2;
6 |
7 | /**
8 | * TemporalMedian_.java: line 169
9 | */
10 | public class Benchmark1 {
11 | class Pixel {
12 | int frame;
13 | int pos;
14 | float val;
15 | public Pixel(int f, int p, float v) {
16 | frame = f;
17 | pos = p;
18 | val = v;
19 | }
20 | }
21 |
22 | public JavaPairRDD benchmark(JavaRDD tWinPix, int v, int wmin, int wmax) {
23 | return tWinPix.filter(pixel -> pixel.pos==v).mapToPair(pixel -> new Tuple2(pixel.frame, pixel.val));
24 | }
25 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/fiji/IJ_Temporal/Benchmark2.java:
--------------------------------------------------------------------------------
1 | package manual.fiji.IJ_Temporal;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | /**
6 | * TemporalMedian_.java: line 189
7 | */
8 | public class Benchmark2 {
9 | class Pixel {
10 | int frame;
11 | int pos;
12 | float val;
13 | public Pixel(int f, int p, float v) {
14 | frame = f;
15 | pos = p;
16 | val = v;
17 | }
18 | }
19 |
20 | public JavaRDD benchmark(JavaRDD tWinPix, int wmax) {
21 | return tWinPix.filter(pixel -> pixel.frame!=0).map(pixel -> new Pixel(pixel.frame-1,pixel.pos,pixel.val));
22 | }
23 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/fiji/IJ_Temporal/Benchmark3.java:
--------------------------------------------------------------------------------
1 | package manual.fiji.IJ_Temporal;
2 |
3 | import org.apache.spark.api.java.JavaPairRDD;
4 |
5 | /**
6 | * TemporalMedian_.java: line 217
7 | */
8 | public class Benchmark3 {
9 | public float benchmark(JavaPairRDD vec) {
10 | return vec.values().reduce((a, b) -> a + b);
11 | }
12 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/fiji/IJ_Temporal/Benchmark4.java:
--------------------------------------------------------------------------------
1 | package manual.fiji.IJ_Temporal;
2 |
3 | import org.apache.spark.api.java.JavaPairRDD;
4 |
5 | /**
6 | * TemporalMedian_.java: line 221
7 | */
8 | public class Benchmark4 {
9 | public float benchmark(JavaPairRDD vec, float mean) {
10 | return vec.values().map(v -> (mean - v) * (mean - v)).reduce((a, b) -> a + b);
11 | }
12 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/fiji/IJ_Trails/Benchmark0.java:
--------------------------------------------------------------------------------
1 | package manual.fiji.IJ_Trails;
2 |
3 | import org.apache.spark.api.java.JavaPairRDD;
4 | import org.apache.spark.api.java.JavaRDD;
5 | import scala.Tuple2;
6 |
7 | public class Benchmark0 {
8 | class Pixel {
9 | int frame;
10 | int pos;
11 | float val;
12 | public Pixel(int f, int p, float v) {
13 | frame = f;
14 | pos = p;
15 | val = v;
16 | }
17 | }
18 |
19 | public JavaPairRDD benchmark(JavaRDD tWinPix, int wcurr, int wmin, int wmax) {
20 | return tWinPix.mapToPair(pixel -> new Tuple2(pixel.pos, pixel.val))
21 | .aggregateByKey(
22 | new Tuple2((float)0, 0),
23 | (res, val) -> new Tuple2(res._1+val, res._2+1),
24 | (res1, res2) -> new Tuple2(res1._1+res2._1, res1._2+res2._2)
25 | ).mapValues(pixel -> pixel._1/pixel._2);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/bin/benchmarks/manual/fiji/IJ_Trails/Benchmark1.java:
--------------------------------------------------------------------------------
1 | package manual.fiji.IJ_Trails;
2 |
3 | import org.apache.spark.api.java.JavaPairRDD;
4 | import org.apache.spark.api.java.JavaRDD;
5 | import scala.Tuple2;
6 |
7 | /**
8 | * Trails_.java: line 151
9 | */
10 | public class Benchmark1 {
11 | class Pixel {
12 | int frame;
13 | int pos;
14 | float val;
15 | public Pixel(int f, int p, float v) {
16 | frame = f;
17 | pos = p;
18 | val = v;
19 | }
20 | }
21 |
22 | public JavaPairRDD benchmark(JavaRDD tWinPix, int v, int wmin, int wmax) {
23 | return tWinPix.filter(pixel -> pixel.pos==v).mapToPair(pixel -> new Tuple2(pixel.frame, pixel.val));
24 | }
25 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/fiji/IJ_Trails/Benchmark2.java:
--------------------------------------------------------------------------------
1 | package manual.fiji.IJ_Trails;
2 |
3 | import org.apache.spark.api.java.JavaPairRDD;
4 |
5 | /**
6 | * Trails_.java: line 160
7 | */
8 | public class Benchmark2 {
9 | public float benchmark(JavaPairRDD vec) {
10 | return vec.values().reduce((a, b) -> a + b);
11 | }
12 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/fiji/IJ_Trails/Benchmark3.java:
--------------------------------------------------------------------------------
1 | package manual.fiji.IJ_Trails;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | /**
6 | * Trails_.java: line 169
7 | */
8 | public class Benchmark3 {
9 | class Pixel {
10 | int frame;
11 | int pos;
12 | float val;
13 | public Pixel(int f, int p, float v) {
14 | frame = f;
15 | pos = p;
16 | val = v;
17 | }
18 | }
19 |
20 | public JavaRDD benchmark(JavaRDD tWinPix, int wmax) {
21 | return tWinPix.filter(pixel -> pixel.frame!=0).map(pixel -> new Pixel(pixel.frame-1,pixel.pos,pixel.val));
22 | }
23 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/phoenix/Histogram.java:
--------------------------------------------------------------------------------
1 | package manual.phoenix;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | class Histogram {
6 |
7 | public static class Pixel {
8 | public int r, g, b;
9 |
10 | public Pixel(int r, int g, int b) {
11 | this.r = r;
12 | this.g = g;
13 | this.b = b;
14 | }
15 | }
16 |
17 | public static int[][] histogram(JavaRDD image, int[] hR, int[] hG, int[] hB) {
18 | return image.aggregate(new int[3][256],
19 | (res, pixel) -> {
20 | res[0][pixel.r]++;
21 | res[1][pixel.g]++;
22 | res[2][pixel.b]++;
23 | return res;
24 | },
25 | (res1, res2) -> {
26 | for (int i=0; i<256; i++) {
27 | res1[0][i] = res1[0][i] + res2[0][i];
28 | res1[1][i] = res1[1][i] + res2[1][i];
29 | res1[2][i] = res1[2][i] + res2[2][i];
30 | }
31 | return res1;
32 | }
33 | );
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/bin/benchmarks/manual/phoenix/KMeansJava.java:
--------------------------------------------------------------------------------
1 | package manual.phoenix;
2 |
3 | import org.apache.spark.api.java.JavaDoubleRDD;
4 | import org.apache.spark.api.java.JavaPairRDD;
5 |
6 | /**
7 | *
8 | * Translation of Phoenix k-means implementation
9 | *
10 | */
11 |
12 | public class KMeansJava {
13 |
14 | private static class Result{
15 | public Double[][] means;
16 | public int[] clusters;
17 | boolean modified;
18 |
19 | Result(Double[][] m, int[] c, boolean mod){
20 | this.means = m;
21 | this.clusters = c;
22 | this.modified = mod;
23 | }
24 | }
25 |
26 | final int GRID_SIZE = 1000;
27 |
28 | public static void main(String[] args) {
29 |
30 | int numPoints = 1000, numMeans = 10, dim = 3;
31 |
32 | Double[][] points = generatePoints(numPoints, dim);
33 | Double[][] means = generatePoints(numMeans, dim);
34 | int[] clusters = new int[numPoints];
35 |
36 | boolean modified = false;
37 |
38 | while (!modified) {
39 | modified = findClustersAndCalcMeans(points,means,
40 | clusters).modified;
41 | }
42 |
43 | System.out.println("\n\nFinal Means:\n");
44 | dumpMatrix(means);
45 | }
46 |
47 | private static void dumpMatrix(Double[][] a) {
48 | for (int i = 0; i < a.length; i++) {
49 | for (int j = 0; j < a[i].length; j++)
50 | System.out.print(" " + a[i][j]);
51 | System.out.println();
52 | }
53 | }
54 |
55 | private static Result findClustersAndCalcMeans(Double[][] points,
56 | Double[][] means, int[] clusters) {
57 | int i, j;
58 | Double minDist, curDist;
59 | int minIdx;
60 | int dim = points[0].length;
61 | boolean modified = false;
62 | for (i = 0; i < points.length; i++) {
63 | minDist = getSqDist(points[i], means[0]);
64 | minIdx = 0;
65 | for (j = 1; j < means.length; j++) {
66 | curDist = getSqDist(points[i], means[j]);
67 | if (curDist < minDist) {
68 | minDist = curDist;
69 | minIdx = j;
70 | }
71 | }
72 |
73 | if (clusters[i] != minIdx) {
74 | clusters[i] = minIdx;
75 | modified = true;
76 | }
77 | }
78 |
79 | for (int ii = 0; ii < means.length; ii++) {
80 | Double[] sum = new Double[dim];
81 | int groupSize = 0;
82 | for (int jj = 0; jj < points.length; jj++) {
83 | if (clusters[jj] == ii) {
84 | sum = add(sum, points[jj]);
85 | groupSize++;
86 | }
87 | }
88 | dim = points[0].length;
89 | Double[] meansi = means[ii];
90 | for (int kk = 0; kk < dim; kk++) {
91 | if (groupSize != 0) {
92 | meansi[kk] = sum[kk] / groupSize;
93 | }
94 | }
95 | means[ii] = meansi;
96 | }
97 | return new Result(means, clusters, modified);
98 | }
99 |
100 | private static JavaDoubleRDD add(JavaDoubleRDD v1, JavaDoubleRDD v2) {
101 | JavaPairRDD t = v1.zip(v2);
102 | return t.mapToDouble(val -> val._1 + val._2);
103 | }
104 |
105 | private static Double getSqDist(JavaDoubleRDD v1, JavaDoubleRDD v2) {
106 | JavaPairRDD t = v1.zip(v2);
107 | return t.aggregate(0.0,
108 | (dist, val) -> dist + (val._1 - val._2) * (val._1 - val._2),
109 | (dist1, dist2) -> dist1 + dist2
110 | );
111 | }
112 |
113 | private static Double[][] generatePoints(int numPoints, int dim) {
114 | Double[][] p = new Double[numPoints][dim];
115 | for (int i = 0; i < numPoints; i++) {
116 | p[i] = new Double[dim];
117 | for (int j = 0; j < dim; j++)
118 | p[i][j] = Math.random();
119 | }
120 | return p;
121 | }
122 |
123 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/phoenix/LinearRegression.java:
--------------------------------------------------------------------------------
1 | package manual.phoenix;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | public class LinearRegression {
6 |
7 | public static class Point {
8 | public int x, y;
9 |
10 | public Point(int x, int y) {
11 | this.x = x;
12 | this.y = y;
13 | }
14 | }
15 |
16 | public static int[] regress(JavaRDD points) {
17 | return points.aggregate(new int[5],
18 | (res, point) -> {
19 | res[0] += point.x;
20 | res[1] += point.x * point.x;
21 | res[2] += point.y;
22 | res[3] += point.y * point.y;
23 | res[4] += point.x * point.y;
24 | return res;
25 | },
26 | (res1, res2) -> {
27 | res1[0] += res2[0];
28 | res1[1] += res2[1];
29 | res1[2] += res2[2];
30 | res1[3] += res2[3];
31 | res1[4] += res2[4];
32 | return res1;
33 | });
34 | }
35 |
36 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/phoenix/StringMatch.java:
--------------------------------------------------------------------------------
1 | package manual.phoenix;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 |
5 | public class StringMatch {
6 | public static boolean[] matchWords(JavaRDD words) {
7 | return words.aggregate(new boolean[3],
8 | (res, word) -> {
9 | res[0] = res[0] || (word == "key1");
10 | res[1] = res[1] || (word == "key2");
11 | res[2] = res[2] || (word == "key3");
12 | return res;
13 | },
14 | (res1, res2) -> {
15 | res1[0] = res1[0] || res2[0];
16 | res1[1] = res1[1] || res2[1];
17 | res1[2] = res1[2] || res2[2];
18 | return res1;
19 | }
20 | );
21 | }
22 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/phoenix/WordCount.java:
--------------------------------------------------------------------------------
1 | package manual.phoenix;
2 |
3 | import org.apache.spark.api.java.JavaRDD;
4 | import scala.Tuple2;
5 |
6 | import java.util.Map;
7 |
8 | public class WordCount {
9 | private static Map countWords(JavaRDD words) {
10 | return words.mapToPair(word -> new Tuple2(word,1)).reduceByKey((c1, c2) -> c1+c2).collectAsMap();
11 | }
12 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/stats/Calculate.java:
--------------------------------------------------------------------------------
1 | package manual.stats;
2 |
3 | import org.apache.spark.api.java.JavaDoubleRDD;
4 | import org.apache.spark.api.java.JavaPairRDD;
5 |
6 | /**
7 | * Calculate.java
8 | * =============
9 | *
10 | * Copyright (C) 2013-2014 Magdalen Berns
11 | *
12 | * This program is free software: you can redistribute it and/or modify
13 | * it under the terms of the GNU General Public License as published by
14 | * the Free Software Foundation, either version 3 of the License, or
15 | * (at your option) any later version.
16 | *
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU General Public License
23 | * along with this program. If not, see .
24 | */
25 |
26 | public class Calculate{
27 |
28 | private double num1, num;
29 |
30 | //Initialise instance variables to be used by instance methods.
31 | public Calculate(){
32 | num1=0.0;
33 | num=0.0;
34 | }
35 |
36 | /**
37 | * subtract
38 | * Method to subtract one double from another
39 | * @param a
40 | * double value to subtract b from
41 | * @param b
42 | * double value to be subtracted from a
43 | * @return
44 | * Double result of subtracting b from a
45 | */
46 | public static double subtract(double a, double b){
47 | return a - b;
48 | }
49 |
50 | /**
51 | * add
52 | * Method to add one double to another
53 | * @param a
54 | * double value to be added to b
55 | * @param b
56 | * double value to be added to a
57 | * @return
58 | * Double result of adding a to b
59 | */
60 | public static double add(double a,double b){
61 | return a+b;
62 | }
63 |
64 | /**
65 | * divide
66 | * Method to divide one double over another
67 | * @param a
68 | * double value to be divided by b
69 | * @param b
70 | * double value to divide a by
71 | * @return
72 | * Double result of dividing a from b
73 | */
74 | public static double divide(double a, double b){
75 | return a/b;
76 | }
77 |
78 | /**
79 | * multiply
80 | * Method to multiply one method to another
81 | * @param a
82 | * Double value to be multiplied by b
83 | * @param b
84 | * Double value to multiplied by a
85 | * @return
86 | * Double result of a * b
87 | */
88 | public static double multiply(double a, double b){
89 | return a*b;
90 | }
91 |
92 | /**
93 | * subtract
94 | * Instance method to subtract one double from another
95 | * @param num2
96 | * double value to be subtracted from num1
97 | * @return
98 | * Double result of subtracting num1 to num2
99 | */
100 | public double subtract(double num2){
101 | return num1-num2;
102 | }
103 |
104 | /**
105 | * add
106 | * Instance method to add one double to another
107 | * @param num2
108 | * double value to be added to num1
109 | * @return
110 | * Double result of adding num1 to num2
111 | */
112 | public double add(double num2){
113 | return num1+num2;
114 | }
115 |
116 | public double divide(double num2){
117 | return num1/num2;
118 | }
119 |
120 | public double multiply(double num2){
121 | return num1*num2;
122 | }
123 |
124 | public static JavaDoubleRDD multiply(JavaDoubleRDD a, double b){
125 | return a.mapToDouble(x -> x * b);
126 | }
127 |
128 | public static JavaDoubleRDD multiply(JavaDoubleRDD a, JavaDoubleRDD b){
129 | JavaPairRDD t = a.zip(b);
130 | return t.mapToDouble(x -> x._1 * x._2);
131 | }
132 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/stats/IOUtil.java:
--------------------------------------------------------------------------------
1 | package manual.stats;
2 |
3 | /**
4 | * IOUtil.java
5 | * ============
6 | * Copyright (C) 2013 Magdalen Berns
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * This file provides a library of static methods for handling common
19 | * IO requirements.
20 | */
21 |
22 | import java.util.Scanner;
23 | import java.io.*;
24 |
25 | public class IOUtil{
26 |
27 | /*
28 | * does not accept anything but doubles
29 | * @ return the first double
30 | */
31 | public static double skipToDouble(Scanner scanner){
32 |
33 | while (scanner.hasNext() && !scanner.hasNextDouble()){
34 | scanner.next();
35 | }
36 | return scanner.hasNextDouble() ? scanner.nextDouble() : Double.NaN;
37 | }
38 |
39 | public static FileReader file(String fileName) throws FileNotFoundException {
40 | return new FileReader(fileName);
41 | }
42 | //read the user input
43 | public static String typedInput() throws IOException {
44 | BufferedReader keyIn = new BufferedReader(new InputStreamReader(System.in));
45 | return keyIn.readLine();
46 | }
47 |
48 | /**
49 | * does not accept anything but integers
50 | * @ return the first integer value
51 | */
52 | public static int skipToInt(Scanner scanner) {
53 |
54 | while (scanner.hasNext() && !scanner.hasNextInt()) {
55 | scanner.next();
56 | }
57 | return scanner.hasNextInt() ? scanner.nextInt() : (int) Double.NaN;//workaround
58 | }
59 |
60 | /**
61 | * Call this every time wrong thing is typed.
62 | */
63 | public static void abuse() {
64 | System.out.println("Invalid entry.");
65 | System.out.println("Abusive statement.");
66 | System.exit(0);
67 | }
68 |
69 | public static String fileName() throws IOException {
70 | System.out.printf("Type file name or hit '!' \n");
71 | String typed= typedInput();
72 | System.out.printf("Found %s \n", typed);
73 | return typed;
74 | }
75 |
76 | public static String getFileName() throws IOException {
77 | System.out.printf("Type file name or hit '!' \n");
78 | String typed= typedInput();
79 | System.out.printf("Found %s \n", typed);
80 | return typed;
81 | }
82 |
83 | public static String enterValue(String kindOf) {
84 | return "Enter " + kindOf + "value:";
85 | }
86 | }
--------------------------------------------------------------------------------
/bin/benchmarks/manual/stats/PlotReader.java:
--------------------------------------------------------------------------------
1 | package manual.stats;
2 |
3 | /**
4 | * PlotUtil.java
5 | * ==============
6 | *
7 | * Copyright (C) 2013-2014 Magdalen Berns
8 | *
9 | * This program is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation, either version 3 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * This program is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with this program. If not, see .
21 | */
22 |
23 | import java.util.Scanner;
24 |
25 |
26 | public class PlotReader{
27 |
28 | public static double[] data1Column(Scanner scan, int length){
29 | double[] data=new double[length];
30 | for (int i=0;i
13 | *
14 | * This program is free software: you can redistribute it and/or modify
15 | * it under the terms of the GNU General Public License as published by
16 | * the Free Software Foundation, either version 3 of the License, or
17 | * (at your option) any later version.
18 | *
19 | * This program is distributed in the hope that it will be useful,
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 | * GNU General Public License for more details.
23 |
24 | * You should have received a copy of the GNU General Public License
25 | * along with this program. If not, see .
26 | */
27 | public class PlotUtil extends IOUtil{
28 |
29 | private JavaRDD data;
30 |
31 | private static class Element {
32 | double x;
33 | double y;
34 | public Element (double a, double b) { x = a; y = b; }
35 | }
36 |
37 | public PlotUtil(JavaRDD data){
38 | this.data=data;
39 | }
40 |
41 | /**
42 | * x
43 | * Pull out the x column data
44 | * @return:
45 | * The x component of a 1d array of doubles
46 | */
47 | public JavaDoubleRDD x(){
48 | return data.mapToDouble(e -> e.x);
49 | }
50 |
51 | /**
52 | * x
53 | * Pull out the y column data
54 | * @return
55 | * The y component of a 1d array of doubles
56 | */
57 | public JavaDoubleRDD y(){
58 | return data.mapToDouble(e -> e.y);
59 | }
60 |
61 | /**
62 | * removeOffset
63 | * Convenience function to remove the y intecept offset value
64 | * @return
65 | * The 2D data array of doubles with offset removed.
66 | */
67 | public static JavaRDD removeOffset(JavaRDD data, double offset){
68 | return data.map(e -> new Element(e.x + -offset, e.y));
69 | }
70 |
71 | public static void writeToFile(double[][] data, PrintWriter fileOut){
72 | for(int i=0; i.
25 | */
26 |
27 | import java.io.PrintWriter;
28 |
29 | public class PlotWriter{
30 |
31 |
32 | public static void write(double[] x, double[] y, PrintWriter fileOut){
33 | for(int i=0; idata[0][1]){
82 |
83 | //if so check that it's significant
84 | if(data[i][1]>largeUp && data[i][1] > minValue){
85 |
86 | largeUp = data[i][1];
87 | System.out.printf("%2.2f ",data[i][0]);
88 | upFile.printf("%2.2f %2.2f ",data[i][0], largeUp);
89 | upFile.println();
90 | }
91 | }
92 | }
93 | System.out.println();
94 | }
95 | }
--------------------------------------------------------------------------------
/bin/benchmarks/original/arithmetic/Average.java:
--------------------------------------------------------------------------------
1 | package original.arithmetic;
2 |
3 | import java.util.List;
4 |
5 | public class Average {
6 | public static int avgList(List data) {
7 | int sum = 0;
8 | int count = 0;
9 | for(int i=0; i data) {
7 | int count = 0;
8 | for(int i=0; i data) {
7 | int sum = 0;
8 | for(int i=0; i data) {
7 | int count = 0;
8 | for(int i=0; i data) {
7 | int min = Integer.MAX_VALUE;
8 | int max = Integer.MIN_VALUE;
9 | for(int i=0; i val)
14 | min = val;
15 | }
16 | return max-min;
17 | }
18 | }
--------------------------------------------------------------------------------
/bin/benchmarks/original/arithmetic/Equal.java:
--------------------------------------------------------------------------------
1 | package original.arithmetic;
2 |
3 | import java.util.List;
4 |
5 | public class Equal {
6 | public static boolean equal(List data, int val) {
7 | boolean equal = true;
8 | for(int i=0; i data) {
7 | int first = 0;
8 | int second = 0;
9 | for(int i=0; i data) {
7 | int max = Integer.MIN_VALUE;
8 | for(int i=0; i data) {
7 | int max = Integer.MIN_VALUE;
8 | for(int i=0; i data) {
7 | int min = Integer.MAX_VALUE;
8 | for(int i=0; i val)
11 | min = val;
12 | }
13 | return min;
14 | }
15 | }
--------------------------------------------------------------------------------
/bin/benchmarks/original/arithmetic/Sum.java:
--------------------------------------------------------------------------------
1 | package original.arithmetic;
2 |
3 | import java.util.List;
4 |
5 | public class Sum {
6 | public static int sumList(List data) {
7 | int sum = 0;
8 | for(int i=0; i cyclingSpeed(List data) {
16 | Map result = new HashMap();
17 |
18 | for(Record record : data) {
19 | int speed = ((int)Math.ceil(record.speed));
20 | if(!result.containsKey(speed)) {
21 | result.put(speed,0);
22 | }
23 | result.put(speed, result.get(speed)+1);
24 | }
25 |
26 | return result;
27 | }
28 | }
--------------------------------------------------------------------------------
/bin/benchmarks/original/bigλ/DatabaseSelect.java:
--------------------------------------------------------------------------------
1 | package original.bigλ;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class DatabaseSelect {
7 |
8 | class Record {
9 | public List columns;
10 | }
11 |
12 | public List select(List table, String key) {
13 | List result = new ArrayList();
14 |
15 | for (Record record : table) {
16 | if (record.columns.get(0).equals(key)) {
17 | result.add(record);
18 | }
19 | }
20 |
21 | return result;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/bin/benchmarks/original/bigλ/ShakespearSentiment.java:
--------------------------------------------------------------------------------
1 | package original.bigλ;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | public class ShakespearSentiment {
8 | public Map sentiment(List words) {
9 | Map result = new HashMap();
10 |
11 | result.put("love", 0);
12 | result.put("hate", 0);
13 |
14 | for (String word : words) {
15 | if (word.trim().toLowerCase().equals("love")) {
16 | result.put("love", result.get("love")+1);
17 | }
18 | else if (word.trim().toLowerCase().equals("hate")) {
19 | result.put("hate", result.get("hate")+1);
20 | }
21 | }
22 |
23 | return result;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/bin/benchmarks/original/bigλ/TwitterCounts.java:
--------------------------------------------------------------------------------
1 | package original.bigλ;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | public class TwitterCounts {
8 | public Map pairs(List tweets) {
9 | Map result = new HashMap();
10 |
11 | for (String tweet : tweets) {
12 | for (String word : tweet.split("\\s+")) {
13 | if (word.charAt(0) == '#') {
14 | if (!result.containsKey(word)) {
15 | result.put(word, 0);
16 | }
17 | result.put(word, result.get(word) + 1);
18 | }
19 | }
20 | }
21 |
22 | return result;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/bin/benchmarks/original/bigλ/WikiPageCount.java:
--------------------------------------------------------------------------------
1 | package original.bigλ;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | public class WikiPageCount {
8 | class Record {
9 | public String name;
10 | public int views;
11 | public int something;
12 | }
13 |
14 | public Map pageCount(List data) {
15 | Map result = new HashMap();
16 |
17 | for (Record record : data) {
18 | if (!result.containsKey(record.name)) {
19 | result.put(record.name, 0);
20 | }
21 | result.put(record.name, result.get(record.name) + record.views);
22 | }
23 |
24 | return result;
25 | }
26 | }
--------------------------------------------------------------------------------
/bin/benchmarks/original/bigλ/YelpKids.java:
--------------------------------------------------------------------------------
1 | package original.bigλ;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | public class YelpKids {
8 | class Record {
9 | public String state;
10 | public String city;
11 | public String comment;
12 | public int score;
13 | public boolean goodForKids;
14 | }
15 |
16 | public Map reviewCount(List data) {
17 | Map result = new HashMap();
18 |
19 | for (Record record : data) {
20 | if (!result.containsKey(record.city)) {
21 | result.put(record.city, 0);
22 | }
23 | if (record.goodForKids) {
24 | result.put(record.city, result.get(record.city)+1);
25 | }
26 | }
27 |
28 | return result;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/bin/benchmarks/original/fiji/IJ_RedToMagenta/fiji/color/Convert_Red_To_Magenta.java:
--------------------------------------------------------------------------------
1 | package original.fiji.IJ_RedToMagenta.fiji.color;
2 |
3 | import ij.ImagePlus;
4 | import ij.plugin.filter.PlugInFilter;
5 | import ij.process.ColorProcessor;
6 | import ij.process.ImageProcessor;
7 |
8 | /**
9 | * Convert all reds to magentas (to help red-green blind viewers)
10 | */
11 | public class Convert_Red_To_Magenta implements PlugInFilter {
12 | protected ImagePlus image;
13 |
14 | /**
15 | * This method gets called by ImageJ / Fiji to determine
16 | * whether the current image is of an appropriate type.
17 | *
18 | * @param arg can be specified in plugins.config
19 | * @param image is the currently opened image
20 | */
21 | public int setup(String arg, ImagePlus image) {
22 | this.image = image;
23 | return DOES_RGB;
24 | }
25 |
26 | /**
27 | * This method is run when the current image was accepted.
28 | *
29 | * @param ip is the current slice (typically, plugins use
30 | * the ImagePlus set above instead).
31 | */
32 | public void run(ImageProcessor ip) {
33 | process((ColorProcessor)ip);
34 | image.updateAndDraw();
35 | }
36 |
37 | public static void process(ColorProcessor ip) {
38 | int w = ip.getWidth(), h = ip.getHeight();
39 | int[] pixels = (int[])ip.getPixels();
40 | for (int j = 0; j < h; j++)
41 | for (int i = 0; i < w; i++) {
42 | int value = pixels[i + j * w];
43 | int red = (value >> 16) & 0xff;
44 | int green = (value >> 8) & 0xff;
45 | int blue = value & 0xff;
46 | if (false && blue > 16)
47 | continue;
48 | pixels[i + j * w] = (red << 16) | (green << 8) | red;
49 | }
50 | }
51 | }
--------------------------------------------------------------------------------
/bin/benchmarks/original/fiji/IJ_Temporal/README.md:
--------------------------------------------------------------------------------
1 | Temporal Plugins
2 | ================
3 |
4 | This Maven project implements ImageJ 1.x plugins for time sequences:
5 |
6 | * Temporal median: finds moving foreground features, see
7 | Parton et al. (2011), JCB 194 (1): 121.
8 | * Trails: does simple averaging over a time window, making tracks visible.
9 |
10 | The plugins ought to work for hyperstacks.
11 |
12 | Free software, released under the GNU General Public License,
13 | http://www.gnu.org/licenses/gpl.html
14 |
15 | Copyright Graeme Ball (2013), graemeball@googlemail.com,
16 | written while working at Micron Oxford: www.micron.ox.ac.uk
17 |
18 | **Latest .jar files for DOWNLOAD on the [Micron Oxford Website](http://www.micron.ox.ac.uk/microngroup/software/Temporal_plugins.jar)**
19 |
20 | The maven project structure is derived from:
21 | https://github.com/imagej/minimal-ij1-plugin
22 |
23 | Temporal Median filter
24 | ----------------------
25 |
26 | This plugin can be used to find moving foreground features, which can be
27 | be a powerful way to suppress false background detections in subsequent
28 | tracking steps.
29 |
30 | * set time window, and standard deviations above background for foreground
31 | * time window should be more than 2x larger than time taken for a feature
32 | to traverse a pixel (NB. total window is 2x half-width +1)
33 | * moving foreground identified by intensity increase relative to background
34 | average (i.e. median) for a pixel over a given time window
35 | * "soft" segmenation, yielding foreground probability related to excess
36 | intensity (in standard deviations) over background level
37 | * crude Anscombe transform applied to data to stabilize the variance
38 |
39 | Trails
40 | ------
41 |
42 | Averaging a short time window can be useful for enhancing signal-to-noise,
43 | and longer time windows can be used to create trajectory snapshots.
44 |
45 | * set a time window over which to average slices
46 |
--------------------------------------------------------------------------------
/bin/benchmarks/original/fiji/IJ_Temporal/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 | 4.0.0
7 |
8 |
9 | org.scijava
10 | pom-scijava
11 | 1.27
12 |
13 |
14 | uk.ac.ox.micron
15 | Temporal_plugins
16 | 1.0.0
17 |
18 |
19 | /Applications/Fiji.app
20 |
21 |
22 | plugins/Temporal_plugins.jar
23 | Temporal plugins for ImageJ 1.x - temporal median filter, trails
24 |
25 |
26 |
27 | net.imagej
28 | ij
29 | ${imagej1.version}
30 |
31 |
32 |
33 |
34 |
35 |
36 | imagej.releases
37 | http://maven.imagej.net/content/repositories/releases
38 |
39 |
40 | imagej.snapshots
41 | http://maven.imagej.net/content/repositories/snapshots
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/bin/benchmarks/original/fiji/IJ_Temporal/src/main/resources/plugins.config:
--------------------------------------------------------------------------------
1 | # Name: Temporal plugins
2 | # Author: Graeme Ball
3 | # Version: 1.0.0
4 |
5 | Plugins>Temporal, "Temporal Median", TemporalMedian_
6 | Plugins>Temporal, "Trails", Trails_
7 |
--------------------------------------------------------------------------------
/bin/benchmarks/original/fiji/IJ_Trails/README.md:
--------------------------------------------------------------------------------
1 | Temporal Plugins
2 | ================
3 |
4 | This Maven project implements ImageJ 1.x plugins for time sequences:
5 |
6 | * Temporal median: finds moving foreground features, see
7 | Parton et al. (2011), JCB 194 (1): 121.
8 | * Trails: does simple averaging over a time window, making tracks visible.
9 |
10 | The plugins ought to work for hyperstacks.
11 |
12 | Free software, released under the GNU General Public License,
13 | http://www.gnu.org/licenses/gpl.html
14 |
15 | Copyright Graeme Ball (2013), graemeball@googlemail.com,
16 | written while working at Micron Oxford: www.micron.ox.ac.uk
17 |
18 | **Latest .jar files for DOWNLOAD on the [Micron Oxford Website](http://www.micron.ox.ac.uk/microngroup/software/Temporal_plugins.jar)**
19 |
20 | The maven project structure is derived from:
21 | https://github.com/imagej/minimal-ij1-plugin
22 |
23 | Temporal Median filter
24 | ----------------------
25 |
26 | This plugin can be used to find moving foreground features, which can be
27 | be a powerful way to suppress false background detections in subsequent
28 | tracking steps.
29 |
30 | * set time window, and standard deviations above background for foreground
31 | * time window should be more than 2x larger than time taken for a feature
32 | to traverse a pixel (NB. total window is 2x half-width +1)
33 | * moving foreground identified by intensity increase relative to background
34 | average (i.e. median) for a pixel over a given time window
35 | * "soft" segmenation, yielding foreground probability related to excess
36 | intensity (in standard deviations) over background level
37 | * crude Anscombe transform applied to data to stabilize the variance
38 |
39 | Trails
40 | ------
41 |
42 | Averaging a short time window can be useful for enhancing signal-to-noise,
43 | and longer time windows can be used to create trajectory snapshots.
44 |
45 | * set a time window over which to average slices
46 |
--------------------------------------------------------------------------------
/bin/benchmarks/original/fiji/IJ_Trails/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 | 4.0.0
7 |
8 |
9 | org.scijava
10 | pom-scijava
11 | 1.27
12 |
13 |
14 | uk.ac.ox.micron
15 | Temporal_plugins
16 | 1.0.0
17 |
18 |
19 | /Applications/Fiji.app
20 |
21 |
22 | plugins/Temporal_plugins.jar
23 | Temporal plugins for ImageJ 1.x - temporal median filter, trails
24 |
25 |
26 |
27 | net.imagej
28 | ij
29 | ${imagej1.version}
30 |
31 |
32 |
33 |
34 |
35 |
36 | imagej.releases
37 | http://maven.imagej.net/content/repositories/releases
38 |
39 |
40 | imagej.snapshots
41 | http://maven.imagej.net/content/repositories/snapshots
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/bin/benchmarks/original/fiji/IJ_Trails/src/main/resources/plugins.config:
--------------------------------------------------------------------------------
1 | # Name: Temporal plugins
2 | # Author: Graeme Ball
3 | # Version: 1.0.0
4 |
5 | Plugins>Temporal, "Temporal Median", TemporalMedian_
6 | Plugins>Temporal, "Trails", Trails_
7 |
--------------------------------------------------------------------------------
/bin/benchmarks/original/phoenix/Histogram.java:
--------------------------------------------------------------------------------
1 | package original.phoenix;
2 |
3 | import java.util.List;
4 |
5 | class Histogram {
6 |
7 | public static class Pixel {
8 | public int r, g, b;
9 |
10 | public Pixel(int r, int g, int b) {
11 | this.r = r;
12 | this.g = g;
13 | this.b = b;
14 | }
15 | }
16 |
17 | public static int[][] histogram(List image, int[] hR, int[] hG, int[] hB) {
18 | for (int i = 0; i < image.size(); i += 1) {
19 | int r = image.get(i).r;
20 | int g = image.get(i).g;
21 | int b = image.get(i).b;
22 | hR[r]++;
23 | hG[g]++;
24 | hB[b]++;
25 | }
26 |
27 | int[][] result = new int[3][];
28 | result[0] = hR;
29 | result[1] = hG;
30 | result[2] = hB;
31 |
32 | return result;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/bin/benchmarks/original/phoenix/KMeansJava.java:
--------------------------------------------------------------------------------
1 | package original.phoenix;
2 |
3 | /**
4 | *
5 | * Translation of Phoenix k-means implementation
6 | *
7 | */
8 |
9 | public class KMeansJava {
10 |
11 | private static class Result{
12 | public Double[][] means;
13 | public int[] clusters;
14 | boolean modified;
15 |
16 | Result(Double[][] m, int[] c, boolean mod){
17 | this.means = m;
18 | this.clusters = c;
19 | this.modified = mod;
20 | }
21 | }
22 |
23 | final int GRID_SIZE = 1000;
24 |
25 | public static void main(String[] args) {
26 |
27 | int numPoints = 1000, numMeans = 10, dim = 3;
28 |
29 | Double[][] points = generatePoints(numPoints, dim);
30 | Double[][] means = generatePoints(numMeans, dim);
31 | int[] clusters = new int[numPoints];
32 |
33 | boolean modified = false;
34 |
35 | while (!modified) {
36 | modified = findClustersAndCalcMeans(points,means,
37 | clusters).modified;
38 | }
39 |
40 | System.out.println("\n\nFinal Means:\n");
41 | dumpMatrix(means);
42 | }
43 |
44 | private static void dumpMatrix(Double[][] a) {
45 | for (int i = 0; i < a.length; i++) {
46 | for (int j = 0; j < a[i].length; j++)
47 | System.out.print(" " + a[i][j]);
48 | System.out.println();
49 | }
50 | }
51 |
52 | private static Result findClustersAndCalcMeans(Double[][] points,
53 | Double[][] means, int[] clusters) {
54 | int i, j;
55 | Double minDist, curDist;
56 | int minIdx;
57 | int dim = points[0].length;
58 | boolean modified = false;
59 | for (i = 0; i < points.length; i++) {
60 | minDist = getSqDist(points[i], means[0]);
61 | minIdx = 0;
62 | for (j = 1; j < means.length; j++) {
63 | curDist = getSqDist(points[i], means[j]);
64 | if (curDist < minDist) {
65 | minDist = curDist;
66 | minIdx = j;
67 | }
68 | }
69 |
70 | if (clusters[i] != minIdx) {
71 | clusters[i] = minIdx;
72 | modified = true;
73 | }
74 | }
75 |
76 | for (int ii = 0; ii < means.length; ii++) {
77 | Double[] sum = new Double[dim];
78 | int groupSize = 0;
79 | for (int jj = 0; jj < points.length; jj++) {
80 | if (clusters[jj] == ii) {
81 | sum = add(sum, points[jj]);
82 | groupSize++;
83 | }
84 | }
85 | dim = points[0].length;
86 | Double[] meansi = means[ii];
87 | for (int kk = 0; kk < dim; kk++) {
88 | if (groupSize != 0) {
89 | meansi[kk] = sum[kk] / groupSize;
90 | }
91 | }
92 | means[ii] = meansi;
93 | }
94 | return new Result(means, clusters, modified);
95 | }
96 |
97 | private static Double[] add(Double[] v1, Double[] v2) {
98 | Double[] sum = new Double[v1.length];
99 | for (int i = 0; i < sum.length; i++)
100 | sum[i] = v1[i] + v2[i];
101 | return sum;
102 | }
103 |
104 | private static Double getSqDist(Double[] v1, Double[] v2) {
105 | Double dist = 0.0;
106 | for (int i = 0; i < v1.length; i++)
107 | dist += ((v1[i] - v2[i]) * (v1[i] - v2[i]));
108 | return dist;
109 | }
110 |
111 | private static Double[][] generatePoints(int numPoints, int dim) {
112 | Double[][] p = new Double[numPoints][dim];
113 | for (int i = 0; i < numPoints; i++) {
114 | p[i] = new Double[dim];
115 | for (int j = 0; j < dim; j++)
116 | p[i][j] = Math.random();
117 | }
118 | return p;
119 | }
120 |
121 | }
--------------------------------------------------------------------------------
/bin/benchmarks/original/phoenix/LinearRegression.java:
--------------------------------------------------------------------------------
1 | package original.phoenix;
2 |
3 | import java.util.List;
4 |
5 | public class LinearRegression {
6 |
7 | public static class Point {
8 | public int x, y;
9 |
10 | public Point(int x, int y) {
11 | this.x = x;
12 | this.y = y;
13 | }
14 | }
15 |
16 | public static int[] regress(List points) {
17 | int SX_ll = 0, SY_ll = 0, SXX_ll = 0, SYY_ll = 0, SXY_ll = 0;
18 |
19 | // ADD UP RESULTS
20 | for (int i = 0; i < points.size(); i++) {
21 | // Compute SX, SY, SYY, SXX, SXY
22 | SX_ll += points.get(i).x;
23 | SXX_ll += points.get(i).x * points.get(i).x;
24 | SY_ll += points.get(i).y;
25 | SYY_ll += points.get(i).y * points.get(i).y;
26 | SXY_ll += points.get(i).x * points.get(i).y;
27 | }
28 | int[] result = new int[5];
29 | result[0] = SX_ll;
30 | result[1] = SXX_ll;
31 | result[2] = SY_ll;
32 | result[3] = SYY_ll;
33 | result[4] = SXY_ll;
34 | return result;
35 | }
36 |
37 | }
--------------------------------------------------------------------------------
/bin/benchmarks/original/phoenix/StringMatch.java:
--------------------------------------------------------------------------------
1 | package original.phoenix;
2 |
3 | import java.util.List;
4 |
5 | public class StringMatch {
6 | public static boolean[] matchWords(List words) {
7 | String key1 = "key1";
8 | String key2 = "key2";
9 | String key3 = "key3";
10 |
11 | boolean foundKey1 = false;
12 | boolean foundKey2 = false;
13 | boolean foundKey3 = false;
14 |
15 | for(int i=0; i countWords(List words) {
9 | Map counts = new HashMap();
10 | for (int j = 0; j < words.size(); j++) {
11 | String word = words.get(j);
12 | Integer prev = counts.get(word);
13 | if (prev == null)
14 | prev = 0;
15 | counts.put(word, prev + 1);
16 | }
17 | return counts;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/bin/benchmarks/original/stats/AverageData.java:
--------------------------------------------------------------------------------
1 | package original.stats;
2 |
3 | /**
4 | * AverageData.java
5 | * =============
6 | *
7 | * This is a program to help with data analysis.
8 | * You can open a one column array and average all the data points.
9 | * File must be in the format where the first line gives its length
10 | * e.g.
11 | * length = 30
12 | * x_1
13 | * x_2
14 | * *
15 | * *
16 | * *
17 | * *
18 | * x + n
19 | *
20 | * Copyright (C) 2013-2014 Magdalen Berns
21 | *
22 | * This program is free software: you can redistribute it and/or modify
23 | * it under the terms of the GNU General Public License as published by
24 | * the Free Software Foundation, either version 3 of the License, or
25 | * (at your option) any later version.
26 | *
27 | * This program is distributed in the hope that it will be useful,
28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 | * GNU General Public License for more details.
31 |
32 | * You should have received a copy of the GNU General Public License
33 | * along with this program. If not, see .
34 | */
35 |
36 | import java.io.BufferedReader;
37 | import java.io.FileReader;
38 | import java.io.IOException;
39 | import java.io.PrintWriter;
40 | import java.util.Scanner;
41 |
42 | public class AverageData {
43 |
44 | public static void main(String[] args) throws IOException{
45 | System.out.printf("Please type the name of the data file you wish to average. \n");
46 | String choice= IOUtil.getFileName();
47 |
48 | if ( !choice.equals(null) ) {
49 | Scanner scan = new Scanner(new BufferedReader(new FileReader("files/"+choice)));
50 | int length = IOUtil.skipToInt(scan);
51 | double[] data = PlotReader.data1Column(scan,length);
52 | double mean = StatsUtil.mean(data);
53 | System.out.printf("Mean value %g \n", mean);
54 | System.out.printf("std Dev value %g \n", Math.sqrt(StatsUtil.variance(data,mean)));
55 | System.exit(0);
56 | }
57 | }
58 | }
--------------------------------------------------------------------------------
/bin/benchmarks/original/stats/Calculate.java:
--------------------------------------------------------------------------------
1 | package original.stats;
2 |
3 | /**
4 | * Calculate.java
5 | * =============
6 | *
7 | * Copyright (C) 2013-2014 Magdalen Berns
8 | *
9 | * This program is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation, either version 3 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * This program is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with this program. If not, see .
21 | */
22 |
23 | public class Calculate{
24 |
25 | private double num1, num;
26 |
27 | //Initialise instance variables to be used by instance methods.
28 | public Calculate(){
29 | num1=0.0;
30 | num=0.0;
31 | }
32 |
33 | /**
34 | * subtract
35 | * Method to subtract one double from another
36 | * @param a
37 | * double value to subtract b from
38 | * @param b
39 | * double value to be subtracted from a
40 | * @return
41 | * Double result of subtracting b from a
42 | */
43 | public static double subtract(double a, double b){
44 | return a - b;
45 | }
46 |
47 | /**
48 | * add
49 | * Method to add one double to another
50 | * @param a
51 | * double value to be added to b
52 | * @param b
53 | * double value to be added to a
54 | * @return
55 | * Double result of adding a to b
56 | */
57 | public static double add(double a,double b){
58 | return a+b;
59 | }
60 |
61 | /**
62 | * divide
63 | * Method to divide one double over another
64 | * @param a
65 | * double value to be divided by b
66 | * @param b
67 | * double value to divide a by
68 | * @return
69 | * Double result of dividing a from b
70 | */
71 | public static double divide(double a, double b){
72 | return a/b;
73 | }
74 |
75 | /**
76 | * multiply
77 | * Method to multiply one method to another
78 | * @param a
79 | * Double value to be multiplied by b
80 | * @param b
81 | * Double value to multiplied by a
82 | * @return
83 | * Double result of a * b
84 | */
85 | public static double multiply(double a, double b){
86 | return a*b;
87 | }
88 |
89 | /**
90 | * subtract
91 | * Instance method to subtract one double from another
92 | * @param num2
93 | * double value to be subtracted from num1
94 | * @return
95 | * Double result of subtracting num1 to num2
96 | */
97 | public double subtract(double num2){
98 | return num1-num2;
99 | }
100 |
101 | /**
102 | * add
103 | * Instance method to add one double to another
104 | * @param num2
105 | * double value to be added to num1
106 | * @return
107 | * Double result of adding num1 to num2
108 | */
109 | public double add(double num2){
110 | return num1+num2;
111 | }
112 |
113 | public double divide(double num2){
114 | return num1/num2;
115 | }
116 |
117 | public double multiply(double num2){
118 | return num1*num2;
119 | }
120 |
121 | public static double[] multiply(double[] a, double b){
122 | double[] temp= new double[a.length];
123 | for(int i=0; i.
22 | */
23 |
24 | import java.io.BufferedReader;
25 | import java.io.FileReader;
26 | import java.io.IOException;
27 | import java.io.PrintWriter;
28 | import java.util.Scanner;
29 |
30 | public class ExtractColumn {
31 |
32 | public static void main(String[] args) throws IOException {
33 |
34 | System.out.printf("Which file would you like to pull a column out of? \n");
35 | String inFileName = IOUtil.getFileName();
36 | if(inFileName.equals("!")){
37 | System.out.println("No file selected.");
38 | }
39 | else{
40 |
41 | Scanner scan = new Scanner(new BufferedReader(new FileReader("files/"+inFileName)));
42 | PrintWriter outFile = new PrintWriter("column.txt");
43 | int length = IOUtil.skipToInt(scan);
44 | double xError=IOUtil.skipToDouble(scan);
45 | double yError= IOUtil.skipToDouble(scan);
46 | double[][] data = PlotReader.data2Column(scan,length);
47 | PlotUtil p = new PlotUtil(data);
48 |
49 | PlotWriter.aColumn(p.y(),outFile);
50 | outFile.close();
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/bin/benchmarks/original/stats/FormatData.java:
--------------------------------------------------------------------------------
1 | package original.stats;
2 |
3 | /**
4 | * Format Data.java
5 | * =============
6 | * This file is a part of a program which serves as a utility for data analysis
7 | * of experimental data
8 | *
9 | * Copyright (C) 2013-2014 Magdalen Berns
10 | *
11 | * This program is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | * This program is distributed in the hope that it will be useful,
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | * GNU General Public License for more details.
19 | * You should have received a copy of the GNU General Public License
20 | * along with this program. If not, see .
21 | */
22 |
23 | import java.io.BufferedReader;
24 | import java.io.FileReader;
25 | import java.io.IOException;
26 | import java.io.PrintWriter;
27 | import java.util.Scanner;
28 |
29 | public class FormatData {
30 |
31 | public static void main(String[] args) throws IOException {
32 | String fileName = IOUtil.getFileName();
33 |
34 | Scanner scan = new Scanner(new BufferedReader(new FileReader("files/"+fileName)));
35 | PrintWriter fitFout = new PrintWriter("files/data_"+fileName);
36 |
37 | int length = IOUtil.skipToInt(scan);
38 |
39 | double xError=IOUtil.skipToDouble(scan);
40 | double yError= IOUtil.skipToDouble(scan);
41 | double[][] data = PlotReader.data2Column(scan,length);
42 | PlotUtil p = new PlotUtil(data);
43 |
44 | PlotWriter.errors(p.x(), p.y(),xError,Calculate.multiply(p.y(),yError), fitFout);
45 | fitFout.close();
46 | }
47 | }
--------------------------------------------------------------------------------
/bin/benchmarks/original/stats/IOUtil.java:
--------------------------------------------------------------------------------
1 | package original.stats;
2 |
3 | /**
4 | * IOUtil.java
5 | * ============
6 | * Copyright (C) 2013 Magdalen Berns
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * This file provides a library of static methods for handling common
19 | * IO requirements.
20 | */
21 |
22 | import java.util.Scanner;
23 | import java.io.*;
24 |
25 | public class IOUtil{
26 |
27 | /*
28 | * does not accept anything but doubles
29 | * @ return the first double
30 | */
31 | public static double skipToDouble(Scanner scanner){
32 |
33 | while (scanner.hasNext() && !scanner.hasNextDouble()){
34 | scanner.next();
35 | }
36 | return scanner.hasNextDouble() ? scanner.nextDouble() : Double.NaN;
37 | }
38 |
39 | public static FileReader file(String fileName) throws FileNotFoundException {
40 | return new FileReader(fileName);
41 | }
42 | //read the user input
43 | public static String typedInput() throws IOException {
44 | BufferedReader keyIn = new BufferedReader(new InputStreamReader(System.in));
45 | return keyIn.readLine();
46 | }
47 |
48 | /**
49 | * does not accept anything but integers
50 | * @ return the first integer value
51 | */
52 | public static int skipToInt(Scanner scanner) {
53 |
54 | while (scanner.hasNext() && !scanner.hasNextInt()) {
55 | scanner.next();
56 | }
57 | return scanner.hasNextInt() ? scanner.nextInt() : (int) Double.NaN;//workaround
58 | }
59 |
60 | /**
61 | * Call this every time wrong thing is typed.
62 | */
63 | public static void abuse() {
64 | System.out.println("Invalid entry.");
65 | System.out.println("Abusive statement.");
66 | System.exit(0);
67 | }
68 |
69 | public static String fileName() throws IOException {
70 | System.out.printf("Type file name or hit '!' \n");
71 | String typed= typedInput();
72 | System.out.printf("Found %s \n", typed);
73 | return typed;
74 | }
75 |
76 | public static String getFileName() throws IOException {
77 | System.out.printf("Type file name or hit '!' \n");
78 | String typed= typedInput();
79 | System.out.printf("Found %s \n", typed);
80 | return typed;
81 | }
82 |
83 | public static String enterValue(String kindOf) {
84 | return "Enter " + kindOf + "value:";
85 | }
86 | }
--------------------------------------------------------------------------------
/bin/benchmarks/original/stats/MomentInertia.java:
--------------------------------------------------------------------------------
1 | package original.stats;
2 |
3 | /*
4 | MomentInertia.java
5 | ==================
6 |
7 | A class to calculate the moment of intertia for various situations.
8 | Copyright (C) 2013 Magdalen Berns
9 |
10 |
11 |
12 | This program is free software: you can redistribute it and/or modify
13 | it under the terms of the GNU General Public License as published by
14 | the Free Software Foundation, either version 3 of the License, or
15 | (at your option) any later version.
16 |
17 | This program is distributed in the hope that it will be useful,
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | GNU General Public License for more details.
21 |
22 | You should have received a copy of the GNU General Public License
23 | along with this program. If not, see .
24 | */
25 |
26 |
27 | class MomentInertia{
28 |
29 | public static double centerUniformRod(double length, double mass){
30 | return (mass * length * length )/12;
31 | }
32 | public static double sphere(double length, double mass){
33 | return (mass * length * length )/12;
34 | }
35 |
36 |
37 | }
--------------------------------------------------------------------------------
/bin/benchmarks/original/stats/PlotReader.java:
--------------------------------------------------------------------------------
1 | package original.stats;
2 |
3 | /**
4 | * PlotUtil.java
5 | * ==============
6 | *
7 | * Copyright (C) 2013-2014 Magdalen Berns
8 | *
9 | * This program is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation, either version 3 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * This program is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with this program. If not, see .
21 | */
22 |
23 | import java.util.Scanner;
24 |
25 |
26 | public class PlotReader{
27 |
28 | public static double[] data1Column(Scanner scan, int length){
29 | double[] data=new double[length];
30 | for (int i=0;i
9 | *
10 | * This program is free software: you can redistribute it and/or modify
11 | * it under the terms of the GNU General Public License as published by
12 | * the Free Software Foundation, either version 3 of the License, or
13 | * (at your option) any later version.
14 | *
15 | * This program is distributed in the hope that it will be useful,
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | * GNU General Public License for more details.
19 |
20 | * You should have received a copy of the GNU General Public License
21 | * along with this program. If not, see .
22 | */
23 | public class PlotUtil extends IOUtil{
24 |
25 | private double[] x, y;
26 | private double [][] data;
27 |
28 | public PlotUtil(double[][] data){
29 | this.data=data;
30 | x = new double[data.length];
31 | y = new double[data.length];
32 | }
33 |
34 | /**
35 | * x
36 | * Pull out the x column data
37 | * @return:
38 | * The x component of a 1d array of doubles
39 | */
40 | public double[] x(){
41 | for (int i=0;i=0; i--) data[i][0] +=-offset;
64 | return data;
65 | }
66 |
67 | public static void writeToFile(double[][] data, PrintWriter fileOut){
68 | for(int i=0; i.
25 | */
26 |
27 | import java.io.PrintWriter;
28 |
29 | public class PlotWriter{
30 |
31 |
32 | public static void write(double[] x, double[] y, PrintWriter fileOut){
33 | for(int i=0; idata[0][1]){
82 |
83 | //if so check that it's significant
84 | if(data[i][1]>largeUp && data[i][1] > minValue){
85 |
86 | largeUp = data[i][1];
87 | System.out.printf("%2.2f ",data[i][0]);
88 | upFile.printf("%2.2f %2.2f ",data[i][0], largeUp);
89 | upFile.println();
90 | }
91 | }
92 | }
93 | System.out.println();
94 | }
95 | }
--------------------------------------------------------------------------------
/bin/buildCompileAndRun.sh:
--------------------------------------------------------------------------------
1 | BASEDIR=$(dirname "$0")
2 | INPUTDIR=$(readlink -f "$1")
3 | OUTPUTDIR=$(readlink -f "$2")
4 | cd $BASEDIR
5 | cd ..
6 | ant clean
7 | ant
8 | cd bin
9 | ./casperc -nooutput -stdout -w 10000 $INPUTDIR > $OUTPUTDIR
10 | nodejs indentationScript.js $OUTPUTDIR
11 |
--------------------------------------------------------------------------------
/bin/casper:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | prg=`basename "$0"`
4 | dir=`dirname "$0"`/..
5 |
6 | usage() {
7 | polyglot -h
8 | cat < pass options to the Java VM
10 | -J use a different Java VM (default java in path)
11 | -V echo the java command
12 | EOF
13 | }
14 |
15 | fixclasspath() {
16 | windows=0
17 |
18 | if [ `uname | grep -c CYGWIN` -ne 0 ]; then
19 | windows=1
20 | fi
21 |
22 | cp="$1"
23 | if [ "$windows" = 1 ]; then
24 | cygpath -pw "$cp"
25 | else
26 | echo "$cp"
27 | fi
28 | }
29 |
30 | extra_cp=
31 | args=
32 | vmargs=
33 | classpath=
34 | java=java
35 | ext=casper
36 |
37 | polyglot() {
38 | eval "$java" "$vmargs" -classpath "'$classpath'" "$@"
39 | }
40 |
41 | while true; do
42 | case "$1" in
43 | "")
44 | break
45 | ;;
46 | -V)
47 | verbose=1
48 | shift
49 | ;;
50 | -classpath)
51 | shift
52 | extra_cp="$extra_cp:$1"
53 | shift
54 | ;;
55 | -j)
56 | shift
57 | vmargs="$vmargs '$1'"
58 | shift
59 | ;;
60 | -J)
61 | shift
62 | java="'$1'"
63 | shift
64 | ;;
65 | -h)
66 | usage=1
67 | break
68 | ;;
69 | *)
70 | args="$args '$1'"
71 | shift
72 | ;;
73 | esac
74 | done
75 |
76 | if [ -n "$ext" ]; then
77 | args="-ext '$ext' $args"
78 | fi
79 |
80 |
81 | classpath="$dir/compiler/classes:$dir/runtime/classes:$dir/lib/polyglot.jar:$dir/lib/java_cup.jar"
82 | if [ -n "$ext" ]; then
83 | classpath="$classpath:$dir/lib/$ext.jar"
84 | fi
85 | classpath="$classpath:$extra_cp"
86 | classpath=`fixclasspath "$classpath"`
87 |
88 |
89 | if [ "$usage" = 1 ]; then
90 | usage
91 | exit 0
92 | fi
93 |
94 | if [ "$verbose" = 1 ]; then
95 | echo "$java" "$vmargs" -classpath "'$classpath'" "$@"
96 | fi
97 |
98 | polyglot "$args"
--------------------------------------------------------------------------------
/bin/casperc:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | prg=`basename "$0"`
4 | dir=`dirname "$0"`/..
5 |
6 | usage() {
7 | polyglot -h
8 | cat < pass options to the Java VM
10 | -J use a different Java VM (default java in path)
11 | -V echo the java command
12 | EOF
13 | }
14 |
15 | fixclasspath() {
16 | windows=0
17 |
18 | if [ `uname | grep -c CYGWIN` -ne 0 ]; then
19 | windows=1
20 | fi
21 |
22 | cp="$1"
23 | if [ "$windows" = 1 ]; then
24 | cygpath -pw "$cp"
25 | else
26 | echo "$cp"
27 | fi
28 | }
29 |
30 | extra_cp=/home/Maaz/Desktop/Work/Alvin/Releases/Casper/lib/imagej-1.46.jar
31 | args=
32 | vmargs=-ea
33 | classpath=
34 | java=java
35 | ext=casper
36 |
37 | polyglot() {
38 | eval "$java" "$vmargs" -classpath "'$classpath'" casper.Main "$@"
39 | }
40 |
41 | while true; do
42 | case "$1" in
43 | "")
44 | break
45 | ;;
46 | -V)
47 | verbose=1
48 | shift
49 | ;;
50 | -classpath)
51 | shift
52 | extra_cp="$extra_cp:$1"
53 | shift
54 | ;;
55 | -j)
56 | shift
57 | vmargs="$vmargs '$1'"
58 | shift
59 | ;;
60 | -J)
61 | shift
62 | java="'$1'"
63 | shift
64 | ;;
65 | -h)
66 | usage=1
67 | break
68 | ;;
69 | *)
70 | args="$args '$1'"
71 | shift
72 | ;;
73 | esac
74 | done
75 |
76 | if [ -n "$ext" ]; then
77 | args=" $args"
78 | fi
79 |
80 |
81 | classpath="$dir/compiler/classes:$dir/runtime/classes:$dir/lib/polyglot.jar:$dir/lib/java_cup.jar"
82 | if [ -n "$ext" ]; then
83 | classpath="$classpath:$dir/lib/$ext.jar"
84 | fi
85 | classpath="$classpath:$extra_cp"
86 | classpath=`fixclasspath "$classpath"`
87 |
88 |
89 | if [ "$usage" = 1 ]; then
90 | usage
91 | exit 0
92 | fi
93 |
94 | if [ "$verbose" = 1 ]; then
95 | echo "$java" "$vmargs" -classpath "'$classpath'" "$@"
96 | fi
97 |
98 | polyglot "$args"
--------------------------------------------------------------------------------
/bin/check.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | function require-program {
4 | echo -n "checking for $1... "
5 | if ! which $1; then
6 | echo "MISSING!"
7 | return 1
8 | fi
9 | }
10 |
11 | require-program java;
12 | if [[ $? == 0 ]]; then
13 | echo "FOUND!"
14 | fi
15 |
16 | require-program nodejs;
17 | if [[ $? == 0 ]]; then
18 | echo "FOUND!"
19 | fi
20 |
21 | require-program dafny;
22 | if [[ $? == 0 ]]; then
23 | echo "FOUND!"
24 | fi
25 |
26 | require-program sketch;
27 | if [[ $? == 0 ]]; then
28 | echo "FOUND!"
29 | fi
30 |
31 | require-program ant;
32 | if [[ $? == 0 ]]; then
33 | echo "FOUND!"
34 | fi
--------------------------------------------------------------------------------
/bin/compileAndRun.sh:
--------------------------------------------------------------------------------
1 | BASEDIR=$(dirname "$0")
2 | INPUTDIR=$(readlink -f "$1")
3 | OUTPUTDIR=$(readlink -f "$2")
4 | cd $BASEDIR
5 | cd ..
6 | ant
7 | cd bin
8 | ./casperc -nooutput -stdout -w 10000 $INPUTDIR > $OUTPUTDIR
9 | nodejs indentationScript.js $OUTPUTDIR
--------------------------------------------------------------------------------
/bin/debug.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uwplse/Casper/a15e4f2ed4923ce9084b0175e045e7fa60965c71/bin/debug.txt
--------------------------------------------------------------------------------
/bin/debugRun.sh:
--------------------------------------------------------------------------------
1 | BASEDIR=$(dirname "$0")
2 | INPUTDIR=$(readlink -f "$1")
3 | OUTPUTDIR=$(readlink -f "$2")
4 | cd $BASEDIR
5 | cd ..
6 | ant
7 | cd bin
8 | ./casperc -nooutput -stdout -w 10000 $INPUTDIR slow > $OUTPUTDIR
9 | nodejs indentationScript.js $OUTPUTDIR
10 |
--------------------------------------------------------------------------------
/bin/output/Average.sk:
--------------------------------------------------------------------------------
1 | struct Average{
2 | }
--------------------------------------------------------------------------------
/bin/output/Count.sk:
--------------------------------------------------------------------------------
1 | struct Count{
2 | }
--------------------------------------------------------------------------------
/bin/output/MaxAbs.sk:
--------------------------------------------------------------------------------
1 | struct MaxAbs{
2 | }
--------------------------------------------------------------------------------
/bin/output/Mean.sk:
--------------------------------------------------------------------------------
1 | struct Mean{
2 | }
--------------------------------------------------------------------------------
/bin/output/Min.sk:
--------------------------------------------------------------------------------
1 | struct Min{
2 | }
--------------------------------------------------------------------------------
/bin/output/MulVecSca.sk:
--------------------------------------------------------------------------------
1 | struct MulVecSca{
2 | }
--------------------------------------------------------------------------------
/bin/output/Sum.sk:
--------------------------------------------------------------------------------
1 | struct Sum{
2 | }
--------------------------------------------------------------------------------
/bin/output/main_double_0.dfy:
--------------------------------------------------------------------------------
1 | /***************************** INCLUDES *************************************/
2 | include "utils.dfy"
3 |
4 | /******************************* UDTS ***************************************/
5 | class MulVecSca{
6 | }
7 |
8 |
9 | /***************************** DO MAP ***************************************/
10 |
11 | function emit_0_0(a: seq, i0: int, i: int, loop0: bool, b: int) :
12 |
13 | ensures emit_0_0(a, i0, i, loop0, b) == [((1,i),(b*a[i],b))]
14 | {
15 | [((1,i),(b*a[i],b))]
16 | }
17 |
18 |
19 |
20 | function domap_0 (a: seq, i0: int, i: int, loop0: bool, b: int) :
21 |
22 | ensures domap_0(a, i0, i, loop0, b) == emit_0_0(a, i0, i, loop0, b)
23 | {
24 | emit_0_0(a, i0, i, loop0, b)
25 | }
26 |
27 | /***************************** MAPPER ***************************************/
28 |
29 | function mapper_0 (a: seq, i0: int, i: int, loop0: bool, b: int) :
30 |
31 | {
32 | if then []
33 | else domap_0(a, i0, i-1, loop0, b) + mapper_0(a, i0, i-1, loop0, b)
34 | }
35 |
36 | /***************************** DO REDUCE ************************************/
37 |
38 |
39 |
40 |
41 |
42 | /******************************* HARNESS ************************************/
43 |
44 | predicate loopInvariant (a: seq, temp: seq, temp0: seq