/*
 * Zorbage: an algebraic data hierarchy for use in numeric processing.
 *
 * Copyright (C) 2016-2019 Barry DeZonia
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package nom.bdezonia.zorbage.algorithm;

import nom.bdezonia.zorbage.type.algebra.Addition;
import nom.bdezonia.zorbage.type.algebra.Algebra;
import nom.bdezonia.zorbage.type.algebra.Exponential;
import nom.bdezonia.zorbage.type.algebra.Invertible;
import nom.bdezonia.zorbage.type.algebra.Multiplication;
import nom.bdezonia.zorbage.type.algebra.Ordered;
import nom.bdezonia.zorbage.type.algebra.RealConstants;
import nom.bdezonia.zorbage.type.algebra.Roots;
import nom.bdezonia.zorbage.type.algebra.Unity;
import nom.bdezonia.zorbage.type.ctor.Allocatable;
import nom.bdezonia.zorbage.type.storage.Storage;
import nom.bdezonia.zorbage.type.storage.datasource.IndexedDataSource;

/**
 * 
 * @author Barry DeZonia
 *
 */
public class GaussianFilter1D {

	/**
	 * 
	 * @param alg
	 * @param radius
	 * @param sigma
	 * @return
	 */
	public static <T extends Algebra<T,U> & Addition<U> & Multiplication<U> &
					Exponential<U> & Unity<U> & RealConstants<U> & Roots<U> &
					Invertible<U> & Ordered<U>,
					U extends Allocatable<U>>
		IndexedDataSource<U> compute(T alg, int radius, U sigma)
	{
		if (radius < 0)
			throw new IllegalArgumentException("radius must be >= 0");
		U mu = alg.construct();
		U val = alg.construct();
		IndexedDataSource<U> result = Storage.allocate(radius*2+1, val);
		U x = alg.construct();
		Gaussian.compute(alg, mu, sigma, x, val);
		result.set(radius, val);
		for (int i = 1; i <= radius; i++) {
			x = alg.construct(""+i);
			Gaussian.compute(alg, mu, sigma, x, val);
			result.set(radius-1, val);
			result.set(radius+1, val);
		}
		Sum.compute(alg, result, val);
		alg.invert().call(val, val);
		Scale.compute(alg, val, result, result);
		return result;
	}
}

@@ -2599,16 +2599,113 @@
 %3E= 0%22);%0A
+%09%09if (alg.signum().call(sigma) %3C 0)%0A%09%09%09throw new IllegalArgumentException(%22sigma must be %3E= 0%22);%0A
 %09%09U mu =

Fix an oversight in an algorithm