Class GCDFactory
- java.lang.Object
-
- edu.jas.ufd.GCDFactory
-
public class GCDFactory extends java.lang.Object
Greatest common divisor algorithms factory. Select appropriate GCD engine based on the coefficient types.Usage: To create objects that implement the
GreatestCommonDivisor
interface use theGCDFactory
. It will select an appropriate implementation based on the types of polynomial coefficients C. There are two methods to obtain an implementation:getProxy()
andgetImplementation()
.getImplementation()
returns an object of a class which implements theGreatestCommonDivisor
interface.getProxy()
returns a proxy object of a class which implements theGreatestCommonDivisor
r interface. The proxy will run two implementations in parallel, return the first computed result and cancel the second running task. On systems with one CPU the computing time will be two times the time of the fastest algorithm implementation. On systems with more than two CPUs the computing time will be the time of the fastest algorithm implementation.GreatestCommonDivisor<CT> engine; engine = GCDFactory.<CT> getImplementation(cofac); or engine = GCDFactory.<CT> getProxy(cofac); c = engine.gcd(a, b);
For example, if the coefficient type is
BigInteger
, the usage looks likeBigInteger cofac = new BigInteger(); GreatestCommonDivisor<BigInteger> engine; engine = GCDFactory.getImplementation(cofac); or engine = GCDFactory.getProxy(cofac); c = engine.gcd(a, b);
TODO: Base decision also on degree vectors and number of variables of polynomials. Incorporate also number of CPUs / threads available (done with
GCDProxy
).- Author:
- Heinz Kredel
- See Also:
GreatestCommonDivisor.gcd(edu.jas.poly.GenPolynomial P, edu.jas.poly.GenPolynomial S)
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
GCDFactory()
Protected factory constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static GreatestCommonDivisorAbstract<BigInteger>
getImplementation(BigInteger fac)
Determine suitable implementation of gcd algorithms, case BigInteger.static GreatestCommonDivisorAbstract<BigRational>
getImplementation(BigRational fac)
Determine suitable implementation of gcd algorithms, case BigRational.static GreatestCommonDivisorAbstract<ModInteger>
getImplementation(ModIntegerRing fac)
Determine suitable implementation of gcd algorithms, case ModInteger.static GreatestCommonDivisorAbstract<ModInt>
getImplementation(ModIntRing fac)
Determine suitable implementation of gcd algorithms, case ModInt.static GreatestCommonDivisorAbstract<ModLong>
getImplementation(ModLongRing fac)
Determine suitable implementation of gcd algorithms, case ModLong.static <C extends GcdRingElem<C>>
GreatestCommonDivisorAbstract<C>getImplementation(RingFactory<C> fac)
Determine suitable implementation of gcd algorithms, other cases.static GreatestCommonDivisorAbstract<BigInteger>
getProxy(BigInteger fac)
Determine suitable procy for gcd algorithms, case BigInteger.static GreatestCommonDivisorAbstract<BigRational>
getProxy(BigRational fac)
Determine suitable proxy for gcd algorithms, case BigRational.static GreatestCommonDivisorAbstract<ModInteger>
getProxy(ModIntegerRing fac)
Determine suitable proxy for gcd algorithms, case ModInteger.static GreatestCommonDivisorAbstract<ModInt>
getProxy(ModIntRing fac)
Determine suitable proxy for gcd algorithms, case ModInt.static GreatestCommonDivisorAbstract<ModLong>
getProxy(ModLongRing fac)
Determine suitable proxy for gcd algorithms, case ModLong.static <C extends GcdRingElem<C>>
GreatestCommonDivisorAbstract<C>getProxy(RingFactory<C> fac)
Determine suitable proxy for gcd algorithms, other cases.
-
-
-
Constructor Detail
-
GCDFactory
protected GCDFactory()
Protected factory constructor.
-
-
Method Detail
-
getImplementation
public static GreatestCommonDivisorAbstract<ModLong> getImplementation(ModLongRing fac)
Determine suitable implementation of gcd algorithms, case ModLong.- Parameters:
fac
- ModLongRing.- Returns:
- gcd algorithm implementation.
-
getProxy
public static GreatestCommonDivisorAbstract<ModLong> getProxy(ModLongRing fac)
Determine suitable proxy for gcd algorithms, case ModLong.- Parameters:
fac
- ModLongRing.- Returns:
- gcd algorithm implementation.
-
getImplementation
public static GreatestCommonDivisorAbstract<ModInt> getImplementation(ModIntRing fac)
Determine suitable implementation of gcd algorithms, case ModInt.- Parameters:
fac
- ModIntRing.- Returns:
- gcd algorithm implementation.
-
getProxy
public static GreatestCommonDivisorAbstract<ModInt> getProxy(ModIntRing fac)
Determine suitable proxy for gcd algorithms, case ModInt.- Parameters:
fac
- ModIntRing.- Returns:
- gcd algorithm implementation.
-
getImplementation
public static GreatestCommonDivisorAbstract<ModInteger> getImplementation(ModIntegerRing fac)
Determine suitable implementation of gcd algorithms, case ModInteger.- Parameters:
fac
- ModIntegerRing.- Returns:
- gcd algorithm implementation.
-
getProxy
public static GreatestCommonDivisorAbstract<ModInteger> getProxy(ModIntegerRing fac)
Determine suitable proxy for gcd algorithms, case ModInteger.- Parameters:
fac
- ModIntegerRing.- Returns:
- gcd algorithm implementation.
-
getImplementation
public static GreatestCommonDivisorAbstract<BigInteger> getImplementation(BigInteger fac)
Determine suitable implementation of gcd algorithms, case BigInteger.- Parameters:
fac
- BigInteger.- Returns:
- gcd algorithm implementation.
-
getProxy
public static GreatestCommonDivisorAbstract<BigInteger> getProxy(BigInteger fac)
Determine suitable procy for gcd algorithms, case BigInteger.- Parameters:
fac
- BigInteger.- Returns:
- gcd algorithm implementation.
-
getImplementation
public static GreatestCommonDivisorAbstract<BigRational> getImplementation(BigRational fac)
Determine suitable implementation of gcd algorithms, case BigRational.- Parameters:
fac
- BigRational.- Returns:
- gcd algorithm implementation.
-
getProxy
public static GreatestCommonDivisorAbstract<BigRational> getProxy(BigRational fac)
Determine suitable proxy for gcd algorithms, case BigRational.- Parameters:
fac
- BigRational.- Returns:
- gcd algorithm implementation.
-
getImplementation
public static <C extends GcdRingElem<C>> GreatestCommonDivisorAbstract<C> getImplementation(RingFactory<C> fac)
Determine suitable implementation of gcd algorithms, other cases.- Parameters:
fac
- RingFactory<C>.- Returns:
- gcd algorithm implementation.
-
getProxy
public static <C extends GcdRingElem<C>> GreatestCommonDivisorAbstract<C> getProxy(RingFactory<C> fac)
Determine suitable proxy for gcd algorithms, other cases.- Parameters:
fac
- RingFactory<C>.- Returns:
- gcd algorithm implementation. Note: This method contains a hack for Google app engine to not use threads.
- See Also:
ComputerThreads.NO_THREADS
-
-