Skip to content

Commit 2c3eafd

Browse files
committed
Remove randomGaussian and randomUniform Ops
Some of these Ops were non-deterministic. Others seemed useless, because they would just generate the same number every time.
1 parent 9962d01 commit 2c3eafd

3 files changed

Lines changed: 1 addition & 129 deletions

File tree

scijava-ops-image/src/main/java/org/scijava/ops/image/math/UnaryRealTypeMath.java

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -468,76 +468,6 @@ else if (xt == 1)
468468
}
469469
};
470470

471-
/**
472-
* Sets the real component of an output real number to a random value using a
473-
* gaussian distribution. The input value is considered the standard deviation
474-
* of the desired distribution and must be positive. The output value has mean
475-
* value 0.
476-
* @input input
477-
* @input random
478-
* @container output
479-
* @implNote op names='math.randomGaussian'
480-
*/
481-
public final Computers.Arity2<I, Random, O> randomGaussian = (input, random, output) -> output
482-
.setReal(random.nextGaussian() * Math.abs(input.getRealDouble()));
483-
484-
/**
485-
* Calls the above method with a new Random object (for efficiency the user
486-
* should make a Random object and call the above method if using more than
487-
* once)
488-
* @input input
489-
* @container output
490-
* @implNote op names='math.randomGaussian'
491-
*/
492-
public final Computers.Arity1<I, O> randomGaussianWithoutRandom = (input, output) -> randomGaussian.accept(input,
493-
new Random(), output);
494-
495-
/**
496-
* Calls the above method with a new Random object defined by a passed seed (for
497-
* efficiency the user should make a Random object and call the above method if
498-
* using more than once)
499-
* @input input
500-
* @input seed
501-
* @container output
502-
* @implNote op names='math.randomGaussian'
503-
*/
504-
public final Computers.Arity2<I, Long, O> randomGaussianWithSeed = (input, seed, output) -> randomGaussian.accept(input,
505-
new Random(seed), output);
506-
507-
/**
508-
* Sets the real component of an output real number to a random value between 0
509-
* and (input real number).
510-
* @input input
511-
* @input random
512-
* @container output
513-
* @implNote op names='math.randomUniform'
514-
*/
515-
public final Computers.Arity2<I, Random, O> randomUniform = (input, random, output) -> output
516-
.setReal(random.nextDouble() * Math.abs(input.getRealDouble()));
517-
518-
/**
519-
* Calls the above method with a new Random object (for efficiency the user
520-
* should make a Random object and call the above method if using more than
521-
* once)
522-
* @input input
523-
* @container output
524-
* @implNote op names='math.randomUniform'
525-
*/
526-
public final Computers.Arity1<I, O> randomUniformWithoutRandom = (input, output) -> randomUniform.accept(input,
527-
new Random(), output);
528-
529-
/**
530-
* Calls the above method with a new Random object defined by a passed seed (for
531-
* efficiency the user should make a Random object and call the above method if
532-
* using more than once)
533-
* @input input
534-
* @input seed
535-
* @container output
536-
* @implNote op names='math.randomUniform'
537-
*/
538-
public final Computers.Arity2<I, Long, O> randomUniformWithSeed = (input, seed, output) -> randomUniform.accept(input,
539-
new Random(seed), output);
540-
541471
/**
542472
* Sets the real component of an output real number to the reciprocal of the
543473
* real component of an input real number.

scijava-ops-image/src/test/java/org/scijava/ops/image/OpRegressionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class OpRegressionTest {
4242

4343
@Test
4444
public void opDiscoveryRegressionIT() {
45-
long expected = 1882;
45+
long expected = 1876;
4646
long actual = ops.infos().size();
4747
assertEquals(expected, actual);
4848
}

scijava-ops-image/src/test/java/org/scijava/ops/image/math/UnaryRealTypeMathTest.java

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -482,22 +482,6 @@ public void testArcsecIllegalArgument() {
482482
"arcsec(x) : x out of range"));
483483
}
484484

485-
@Test
486-
public void testRandomGaussian() {
487-
final long seed = 0xabcdef1234567890L;
488-
assertRandomGaussian(23, 16.53373419964066, seed);
489-
assertRandomGaussian(27, -15.542815799078497, 0xfeeddeadbeefbeefL);
490-
assertRandomGaussian(123, -49.838353142718006, 124, 181.75101003563117);
491-
}
492-
493-
@Test
494-
public void testRandomUniform() {
495-
final long seed = 0xabcdef1234567890L;
496-
assertRandomUniform(23, 14.278690684728433, seed);
497-
assertRandomUniform(27, 5.940945158572171, 0xfeeddeadbeefbeefL);
498-
assertRandomUniform(123, 52.3081016051914, 124, 95.52110798318904);
499-
}
500-
501485
// -- Helper methods --
502486

503487
private void assertArccsc(final double i, final double o) {
@@ -513,46 +497,4 @@ private void assertArcsec(final double i, final double o) {
513497
ops.op("math.arcsec").arity1().input(in).output(out).compute();
514498
assertEquals(o, out.get(), 1e-15);
515499
}
516-
517-
private void assertRandomGaussian(final double i, final double o, final long seed) {
518-
final DoubleType in = new DoubleType(i);
519-
final DoubleType out = in.createVariable();
520-
ops.op("math.randomGaussian").arity2().input(in, seed).output(out).compute();
521-
assertEquals(o, out.get(), 0);
522-
}
523-
524-
private void assertRandomGaussian(final double i, final double o, final double i2, final double o2) {
525-
final DoubleType in = new DoubleType(i);
526-
final DoubleType out = new DoubleType();
527-
final long seed = 0xcafebabe12345678L;
528-
final Random rng = new Random(seed);
529-
final Computers.Arity2<DoubleType, Random, DoubleType> op = OpBuilder.matchComputer(ops, "math.randomGaussian",
530-
new Nil<DoubleType>() {}, new Nil<Random>() {}, new Nil<DoubleType>() {});
531-
op.compute(in, rng, out);
532-
assertEquals(o, out.get(), 0);
533-
in.set(i2);
534-
op.compute(in, rng, out);
535-
assertEquals(o2, out.get(), 0);
536-
}
537-
538-
private void assertRandomUniform(final double i, final double o, final long seed) {
539-
final DoubleType in = new DoubleType(i);
540-
final DoubleType out = in.createVariable();
541-
ops.op("math.randomUniform").arity2().input(in, seed).output(out).compute();
542-
assertEquals(o, out.get(), 0);
543-
}
544-
545-
private void assertRandomUniform(final double i, final double o, final double i2, final double o2) {
546-
final DoubleType in = new DoubleType(i);
547-
final DoubleType out = new DoubleType();
548-
final long seed = 0xcafebabe12345678L;
549-
final Random rng = new Random(seed);
550-
final Computers.Arity2<DoubleType, Random, DoubleType> op = OpBuilder.matchComputer(ops, "math.randomUniform",
551-
new Nil<DoubleType>() {}, new Nil<Random>() {}, new Nil<DoubleType>() {});
552-
op.compute(in, rng, out);
553-
assertEquals(o, out.get(), 0);
554-
in.set(i2);
555-
op.compute(in, rng, out);
556-
assertEquals(o2, out.get(), 0);
557-
}
558500
}

0 commit comments

Comments
 (0)