Skip to content

Commit 0f54afc

Browse files
committed
Merge branch 'imagej-rebase'
2 parents ceca8fc + c3ad254 commit 0f54afc

583 files changed

Lines changed: 69938 additions & 1164 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎pom.xml‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,5 +136,43 @@
136136
<artifactId>junit</artifactId>
137137
<scope>test</scope>
138138
</dependency>
139+
140+
<!-- TEMP: BEGIN DEPENDENCIES FOR imagej-ops -->
141+
<dependency>
142+
<groupId>net.imagej</groupId>
143+
<artifactId>imagej-common</artifactId>
144+
</dependency>
145+
<dependency>
146+
<groupId>net.imagej</groupId>
147+
<artifactId>imagej-ops</artifactId>
148+
</dependency>
149+
<dependency>
150+
<groupId>net.imglib2</groupId>
151+
<artifactId>imglib2</artifactId>
152+
</dependency>
153+
<dependency>
154+
<groupId>net.imglib2</groupId>
155+
<artifactId>imglib2-algorithm</artifactId>
156+
</dependency>
157+
<dependency>
158+
<groupId>org.apache.commons</groupId>
159+
<artifactId>commons-math3</artifactId>
160+
</dependency>
161+
<dependency>
162+
<groupId>org.scijava</groupId>
163+
<artifactId>junit-benchmarks</artifactId>
164+
<scope>test</scope>
165+
</dependency>
166+
<dependency>
167+
<groupId>io.scif</groupId>
168+
<artifactId>scifio</artifactId>
169+
<scope>test</scope>
170+
</dependency>
171+
<dependency>
172+
<groupId>net.imagej</groupId>
173+
<artifactId>ij</artifactId>
174+
<scope>test</scope>
175+
</dependency>
176+
<!-- TEMP: END DEPENDENCIES FOR imagej-ops -->
139177
</dependencies>
140178
</project>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*-
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2014 - 2018 ImageJ developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
30+
package net.imagej.ops.coloc;
31+
32+
import java.util.Random;
33+
34+
import net.imglib2.IterableInterval;
35+
import net.imglib2.util.Intervals;
36+
import net.imglib2.util.Util;
37+
38+
/**
39+
* Utility class for coloc ops.
40+
*
41+
* @author Ellen Arena
42+
*/
43+
public final class ColocUtil
44+
{
45+
private ColocUtil() {
46+
// prevent instantiation of utility class
47+
}
48+
public static boolean sameIterationOrder(Iterable<?> i1, Iterable<?> i2) {
49+
if (!(i1 instanceof IterableInterval) || !(i2 instanceof IterableInterval)) {
50+
return true;
51+
}
52+
IterableInterval<?> ii1 = (IterableInterval<?>) i1;
53+
IterableInterval<?> ii2 = (IterableInterval<?>) i2;
54+
return Intervals.equalDimensions(ii1, ii2) && Util.equalIterationOrder(ii1, ii2);
55+
}
56+
57+
/** Fisher-Yates shuffle. */
58+
public static void shuffle(int[] array, Random rnd) {
59+
final int size = array.length;
60+
for (int i = size - 1; i > 0; i--) {
61+
final int j = rnd.nextInt(i + 1);
62+
final int v = array[i];
63+
array[i] = array[j];
64+
array[j] = v;
65+
}
66+
}
67+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*-
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2014 - 2018 ImageJ developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
package net.imagej.ops.coloc;
30+
31+
/**
32+
* Sorts and <code>int[]</code> according to a custom comparator.
33+
* <p>
34+
* This is an implementation of introsort, i.e. it is stable because
35+
* it tries the quicksort algorithm first and falls back to the heap
36+
* sort when it detects an unfavorable execution path.
37+
* </p>
38+
*
39+
* @author Johannes Schindelin
40+
*/
41+
public class IntArraySorter {
42+
43+
private final static int SORT_SIZE_THRESHOLD = 16;
44+
45+
public static void sort(int[] array, IntComparator comparator) {
46+
introSort(array, comparator, 0, array.length, array.length);
47+
insertionSort(array, comparator);
48+
}
49+
50+
private static void introSort(int[] array, IntComparator comparator, int begin, int end, int limit)
51+
{
52+
while (end - begin > SORT_SIZE_THRESHOLD) {
53+
if (limit == 0) {
54+
heapSort(array, comparator, begin, end);
55+
return;
56+
}
57+
limit >>= 1;
58+
59+
// median of three
60+
int a = array[begin];
61+
int b = array[begin + (end - begin) / 2 + 1];
62+
int c = array[end - 1];
63+
int median;
64+
if (comparator.compare(a, b) < 0) {
65+
median = comparator.compare(b, c) < 0 ?
66+
b : (comparator.compare(a, c) < 0 ? c : a);
67+
} else {
68+
median = comparator.compare(b, c) > 0 ?
69+
b : (comparator.compare(a, c) > 0 ? c : a);
70+
}
71+
72+
// partition
73+
int pivot, i = begin, j = end;
74+
for (;;) {
75+
while (comparator.compare(array[i], median) < 0) {
76+
++i;
77+
}
78+
--j;
79+
while (comparator.compare(median, array[j]) < 0) {
80+
--j;
81+
}
82+
if (i >= j) {
83+
pivot = i;
84+
break;
85+
}
86+
int swap = array[i];
87+
array[i] = array[j];
88+
array[j] = swap;
89+
++i;
90+
}
91+
92+
introSort(array, comparator, pivot, end, limit);
93+
end = pivot;
94+
}
95+
}
96+
97+
private static void heapSort(int[] array, IntComparator comparator,
98+
int begin, int end)
99+
{
100+
int count = end - begin;
101+
for (int i = count / 2 - 1; i >= 0; --i) {
102+
siftDown(array, comparator, i, count, begin);
103+
}
104+
for (int i = count - 1; i > 0; --i) {
105+
// swap begin and begin + i
106+
int swap = array[begin + i];
107+
array[begin + i] = array[begin];
108+
array[begin] = swap;
109+
110+
siftDown(array, comparator, 0, i, begin);
111+
}
112+
}
113+
114+
private static void siftDown(int[] array, IntComparator comparator,
115+
int i, int count, int offset)
116+
{
117+
int value = array[offset + i];
118+
while (i < count / 2) {
119+
int child = 2 * i + 1;
120+
if (child + 1 < count &&
121+
comparator.compare(array[child], array[child + 1]) < 0) {
122+
++child;
123+
}
124+
if (comparator.compare(value, array[child]) >= 0) {
125+
break;
126+
}
127+
array[offset + i] = array[offset + child];
128+
i = child;
129+
}
130+
array[offset + i] = value;
131+
}
132+
133+
private static void insertionSort(int[] array,
134+
IntComparator comparator)
135+
{
136+
for (int j = 1; j < array.length; ++j) {
137+
int t = array[j];
138+
int i = j - 1;
139+
while (i >= 0 && comparator.compare(array[i], t) > 0) {
140+
array[i + 1] = array[i];
141+
i = i - 1;
142+
}
143+
array[i + 1] = t;
144+
}
145+
}
146+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*-
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2014 - 2018 ImageJ developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
package net.imagej.ops.coloc;
30+
31+
public interface IntComparator {
32+
int compare(int a, int b);
33+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
2+
package net.imagej.ops.coloc;
3+
4+
/**
5+
* Helper class for MaxKendallTau op.
6+
*
7+
* @author Shulei Wang
8+
* @author Ellen Arena
9+
*/
10+
public class MergeSort {
11+
12+
private int[] data;
13+
private final IntComparator comparator;
14+
15+
public MergeSort(int[] data, IntComparator comparator) {
16+
this.data = data;
17+
this.comparator = comparator;
18+
}
19+
20+
public int[] getSortedData() {
21+
return data;
22+
}
23+
24+
/**
25+
* Sorts the {@link #data} array.
26+
* <p>
27+
* This implements a non-recursive merge sort.
28+
* </p>
29+
*
30+
* @return the equivalent number of BubbleSort swaps
31+
*/
32+
public long sort() {
33+
long swaps = 0;
34+
int n = data.length;
35+
// There are merge sorts which perform in-place, but their runtime is worse
36+
// than O(n log n)
37+
int[] data2 = new int[n];
38+
for (int step = 1; step < n; step <<= 1) {
39+
int begin = 0, k = 0;
40+
for (;;) {
41+
int begin2 = begin + step, end = begin2 + step;
42+
if (end >= n) {
43+
if (begin2 >= n) {
44+
break;
45+
}
46+
end = n;
47+
}
48+
49+
// calculate the equivalent number of BubbleSort swaps
50+
// and perform merge, too
51+
int i = begin, j = begin2;
52+
while (i < begin2 && j < end) {
53+
int compare = comparator.compare(data[i], data[j]);
54+
if (compare > 0) {
55+
swaps += (begin2 - i);
56+
data2[k++] = data[j++];
57+
}
58+
else {
59+
data2[k++] = data[i++];
60+
}
61+
}
62+
if (i < begin2) {
63+
64+
do {
65+
data2[k++] = data[i++];
66+
}
67+
while (i < begin2);
68+
}
69+
else {
70+
while (j < end) {
71+
data2[k++] = data[j++];
72+
}
73+
}
74+
begin = end;
75+
}
76+
if (k < n) {
77+
System.arraycopy(data, k, data2, k, n - k);
78+
}
79+
int[] swapIndex = data2;
80+
data2 = data;
81+
data = swapIndex;
82+
}
83+
84+
return swaps;
85+
}
86+
87+
}

0 commit comments

Comments
 (0)