2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-25 22:38:04 +02:00

fixed minted label issue

This commit is contained in:
Martin Thoma 2014-03-28 10:01:36 +01:00
parent 0eaf43e026
commit 3e4c3f876f
6 changed files with 244 additions and 75 deletions

View file

@ -0,0 +1,85 @@
import x10.io.Console;
import x10.util.Random;
public class Mergesort {
private static val rand = new Random();
private static val MIN_ELEMENTS_PARALLEL = 65536;
public static def sort(values : Array[Int](1)) : Array[Int](1) {
val numbers = new Array[Int](values.size);
val helper = new Array[Int](values.size);
Array.copy(values, numbers);
mergesort(0, values.size - 1, numbers, helper);
return numbers;
}
private static def mergesort(low : Int, high : Int, numbers : Array[Int](1), helper : Array[Int](1)) {
if (low < high) {
val middle = (low + high) / 2;
if (high - low >= MIN_ELEMENTS_PARALLEL) {
finish {
async mergesort(low, middle, numbers, helper);
async mergesort(middle + 1, high, numbers, helper);
}
} else {
mergesort(low, middle, numbers, helper);
mergesort(middle + 1, high, numbers, helper);
}
merge(low, middle, high, numbers, helper);
}
}
private static def merge(low : Int, middle : Int, high : Int, numbers : Array[Int](1), helper : Array[Int](1)) {
// Copy the part to be merged into the helper (from low to high)
Array.copy(numbers, low, helper, low, high - low + 1);
var left : Int = low;
var right : Int = middle + 1;
var position : Int = low;
while(left <= middle && right <= high) {
if (helper(left) <= helper(right)) {
numbers(position++) = helper(left++);
} else {
numbers(position++) = helper(right++);
}
}
while(left <= middle) {
numbers(position++) = helper(left++);
}
// Nothing needs to be done for the right half, because is still
// is where it was copied from, which happens to be the right
// location.
}
public static def main(args:Array[String](1)) {
if (args.size < 1) {
Console.OUT.println("Expect array length as argument");
return;
}
val sort_count = Int.parse(args(0));
val to_sort:Array[Int] = new Array[Int](sort_count, (_:Int) => { return rand.nextInt(); });
for (i in to_sort) {
Console.OUT.print(to_sort(i) + " ");
}
Console.OUT.println();
val start = System.nanoTime();
val sorted = sort(to_sort);
val duration = System.nanoTime() - start;
Console.OUT.println("Sorting took " + duration / 1000000.0 + "ms");
Console.OUT.println("Checking for sortedness...");
for (i in sorted) {
Console.OUT.print(sorted(i) + " ");
}
Console.OUT.println();
}
}

View file

@ -0,0 +1,68 @@
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:8: Could not find type "Array(x10.lang.Long)".
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:9: Could not find type "Array".
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:9: Field size not found in type "Array[x10.lang.Int]{self==values}".
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:10: Could not find type "Array".
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:10: Field size not found in type "Array[x10.lang.Int]{self==values}".
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:11: Could not find Array
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:11: No valid method call found for call in given type.
Call: copy(Array[x10.lang.Int], Array[x10.lang.Int])
Type: Array
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:13: Field size not found in type "Array[x10.lang.Int]{self==values}".
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:18: Could not find type "Array(x10.lang.Long)".
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:15: Cannot return expression; base type incompatible with method return type.
Expression: numbers
Base type: Array[x10.lang.Int]
Expected base type: Array[x10.lang.Int]
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:23: No valid method call found for call in given type.
Call: mergesort(x10.lang.Int, x10.lang.Long, Array[x10.lang.Int], Array[x10.lang.Int])
Type: Mergesort
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:24: No valid method call found for call in given type.
Call: mergesort(x10.lang.Long, x10.lang.Int, Array[x10.lang.Int], Array[x10.lang.Int])
Type: Mergesort
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:27: No valid method call found for call in given type.
Call: mergesort(x10.lang.Int, x10.lang.Long, Array[x10.lang.Int], Array[x10.lang.Int])
Type: Mergesort
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:28: No valid method call found for call in given type.
Call: mergesort(x10.lang.Long, x10.lang.Int, Array[x10.lang.Int], Array[x10.lang.Int])
Type: Mergesort
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:34: Could not find type "Array(x10.lang.Long)".
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:30: No valid method call found for call in given type.
Call: merge(x10.lang.Int, x10.lang.Long, x10.lang.Int, Array[x10.lang.Int], Array[x10.lang.Int])
Type: Mergesort
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:36: Could not find Array
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:36: No valid method call found for call in given type.
Call: copy(Array[x10.lang.Int], x10.lang.Int, Array[x10.lang.Int], x10.lang.Int, x10.lang.Long)
Type: Array
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:39: Cannot assign expression to target; base types are incompatible.
Expression: x10.lang.Long.implicit_operator_as(middle) + 1L
Expected base type: x10.lang.Int
Found base type: x10.lang.Long
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:43: Method or static constructor not found for given call.
Call: helper(x10.lang.Int)
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:44: Method or static constructor not found for given call.
Call: helper(x10.lang.Int)
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:46: Method or static constructor not found for given call.
Call: helper(x10.lang.Int)
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:51: Method or static constructor not found for given call.
Call: helper(x10.lang.Int)
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:58: Could not find type "Array(x10.lang.Long)".
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:59: Field size not found in type "Array[x10.lang.String]{self==args}".
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:64: Method or static constructor not found for given call.
Call: args(x10.lang.Long{self==0L})
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:65: Could not find type "Array".
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:65: No valid constructor found for Array[x10.lang.Int](x10.lang.Int{self==sort_count}, (_:x10.lang.Int)=> x10.lang.Int).
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:65: Cannot assign expression to target; base types are incompatible.
Expression: new Array[x10.lang.Int](...)
Expected base type: Array[x10.lang.Int]
Found base type: Array[x10.lang.Int]
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:67: Could not infer type for formal parameter.
Formal parameter name: i
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:67-69: The loop iterator is a Point whose rank is not the same as the rank of the loop domain.
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:73: No valid method call found for call in given type.
Call: sort(Array[x10.lang.Int])
Type: Mergesort
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:80: Could not infer type for formal parameter.
Formal parameter name: i
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:81: Possible closure call on uninitialized variable sorted.
/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:80-82: The loop iterator is a Point whose rank is not the same as the rank of the loop domain.
35 errors.