MutableFloatMatrix.java

package org.opentrafficsim.core.value.vfloat.matrix;

import org.opentrafficsim.core.unit.Unit;
import org.opentrafficsim.core.value.Absolute;
import org.opentrafficsim.core.value.DenseData;
import org.opentrafficsim.core.value.Relative;
import org.opentrafficsim.core.value.SparseData;
import org.opentrafficsim.core.value.ValueException;
import org.opentrafficsim.core.value.ValueUtil;
import org.opentrafficsim.core.value.vfloat.FloatMathFunctions;
import org.opentrafficsim.core.value.vfloat.FloatMathFunctionsImpl;
import org.opentrafficsim.core.value.vfloat.scalar.FloatScalar;

import cern.colt.matrix.tfloat.FloatMatrix2D;
import cern.colt.matrix.tfloat.impl.DenseFloatMatrix2D;
import cern.colt.matrix.tfloat.impl.SparseFloatMatrix2D;
import cern.jet.math.tfloat.FloatFunctions;

/**
 * MutableFloatMatrix.
 * <p>
 * This file was generated by the OpenTrafficSim value classes generator, 09 mrt, 2015
 * <p>
 * Copyright (c) 2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
 * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
 * <p>
 * @version 09 mrt, 2015 <br>
 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
 * @param <U> Unit; the unit of this MutableFloatMatrix
 */
public abstract class MutableFloatMatrix<U extends Unit<U>> extends FloatMatrix<U> implements
        WriteFloatMatrixFunctions<U>, FloatMathFunctions<MutableFloatMatrix<U>>
{
    /**  */
    private static final long serialVersionUID = 20150309L;

    /**
     * Construct a new MutableFloatMatrix.
     * @param unit U; the unit of the new MutableFloatMatrix
     */
    protected MutableFloatMatrix(final U unit)
    {
        super(unit);
        // System.out.println("Created MutableFloatMatrix");
    }

    /** If set, any modification of the data must be preceded by replacing the data with a local copy. */
    private boolean copyOnWrite = false;

    /**
     * Retrieve the value of the copyOnWrite flag.
     * @return boolean
     */
    private boolean isCopyOnWrite()
    {
        return this.copyOnWrite;
    }

    /**
     * Change the copyOnWrite flag.
     * @param copyOnWrite boolean; the new value for the copyOnWrite flag
     */
    final void setCopyOnWrite(final boolean copyOnWrite)
    {
        this.copyOnWrite = copyOnWrite;
    }

    /** {@inheritDoc} */
    @Override
    public final void normalize() throws ValueException
    {
        float sum = zSum();
        if (0 == sum)
        {
            throw new ValueException("zSum is 0; cannot normalize");
        }
        checkCopyOnWrite();
        for (int row = rows(); --row >= 0;)
        {
            for (int column = columns(); --column >= 0;)
            {
                safeSet(row, column, safeGet(row, column) / sum);
            }
        }
    }

    /**
     * @param <U> Unit
     */
    public abstract static class Abs<U extends Unit<U>> extends MutableFloatMatrix<U> implements Absolute
    {
        /**  */
        private static final long serialVersionUID = 20150309L;

        /**
         * Construct a new Absolute MutableFloatMatrix.
         * @param unit U; the unit of the new Absolute MutableFloatMatrix
         */
        protected Abs(final U unit)
        {
            super(unit);
            // System.out.println("Created Abs");
        }

        /**
         * @param <U> Unit
         */
        public static class Dense<U extends Unit<U>> extends Abs<U> implements DenseData
        {
            /**  */
            private static final long serialVersionUID = 20150309L;

            /**
             * Construct a new Absolute Dense MutableFloatMatrix.
             * @param values float[][]; the initial values of the entries in the new Absolute Dense MutableFloatMatrix
             * @param unit U; the unit of the new Absolute Dense MutableFloatMatrix
             * @throws ValueException when values is null, or is not rectangular
             */
            public Dense(final float[][] values, final U unit) throws ValueException
            {
                super(unit);
                // System.out.println("Created Dense");
                initialize(values);
            }

            /**
             * Construct a new Absolute Dense MutableFloatMatrix.
             * @param values FloatScalar.Abs&lt;U&gt;[][]; the initial values of the entries in the new Absolute Dense
             *            MutableFloatMatrix
             * @throws ValueException when values has zero entries, or is not rectangular
             */
            public Dense(final FloatScalar.Abs<U>[][] values) throws ValueException
            {
                super(checkNonEmpty(values)[0][0].getUnit());
                // System.out.println("Created Dense");
                initialize(values);
            }

            /**
             * For package internal use only.
             * @param values FloatMatrix2D; the initial values of the entries in the new Absolute Dense
             *            MutableFloatMatrix
             * @param unit U; the unit of the new Absolute Dense MutableFloatMatrix
             */
            protected Dense(final FloatMatrix2D values, final U unit)
            {
                super(unit);
                // System.out.println("Created Dense");
                setCopyOnWrite(true);
                initialize(values); // shallow copy
            }

            /** {@inheritDoc} */
            @Override
            public final FloatMatrix.Abs.Dense<U> immutable()
            {
                setCopyOnWrite(true);
                return new FloatMatrix.Abs.Dense<U>(getMatrixSI(), getUnit());
            }

            /** {@inheritDoc} */
            @Override
            public final MutableFloatMatrix.Abs.Dense<U> mutable()
            {
                setCopyOnWrite(true);
                final MutableFloatMatrix.Abs.Dense<U> result =
                        new MutableFloatMatrix.Abs.Dense<U>(getMatrixSI(), getUnit());
                result.setCopyOnWrite(true);
                return result;
            }

            /** {@inheritDoc} */
            @Override
            protected final FloatMatrix2D createMatrix2D(final int rows, final int columns)
            {
                return new DenseFloatMatrix2D(rows, columns);
            }

            /** {@inheritDoc} */
            @Override
            public final MutableFloatMatrix.Abs.Dense<U> copy()
            {
                return mutable();
            }

        }

        /**
         * @param <U> Unit
         */
        public static class Sparse<U extends Unit<U>> extends Abs<U> implements SparseData
        {
            /**  */
            private static final long serialVersionUID = 20150309L;

            /**
             * Construct a new Absolute Sparse MutableFloatMatrix.
             * @param values float[][]; the initial values of the entries in the new Absolute Sparse MutableFloatMatrix
             * @param unit U; the unit of the new Absolute Sparse MutableFloatMatrix
             * @throws ValueException when values is null, or is not rectangular
             */
            public Sparse(final float[][] values, final U unit) throws ValueException
            {
                super(unit);
                // System.out.println("Created Sparse");
                initialize(values);
            }

            /**
             * Construct a new Absolute Sparse MutableFloatMatrix.
             * @param values FloatScalar.Abs&lt;U&gt;[][]; the initial values of the entries in the new Absolute Sparse
             *            MutableFloatMatrix
             * @throws ValueException when values has zero entries, or is not rectangular
             */
            public Sparse(final FloatScalar.Abs<U>[][] values) throws ValueException
            {
                super(checkNonEmpty(values)[0][0].getUnit());
                // System.out.println("Created Sparse");
                initialize(values);
            }

            /**
             * For package internal use only.
             * @param values FloatMatrix2D; the initial values of the entries in the new Absolute Sparse
             *            MutableFloatMatrix
             * @param unit U; the unit of the new Absolute Sparse MutableFloatMatrix
             */
            protected Sparse(final FloatMatrix2D values, final U unit)
            {
                super(unit);
                // System.out.println("Created Sparse");
                setCopyOnWrite(true);
                initialize(values); // shallow copy
            }

            /** {@inheritDoc} */
            @Override
            public final FloatMatrix.Abs.Sparse<U> immutable()
            {
                setCopyOnWrite(true);
                return new FloatMatrix.Abs.Sparse<U>(getMatrixSI(), getUnit());
            }

            /** {@inheritDoc} */
            @Override
            public final MutableFloatMatrix.Abs.Sparse<U> mutable()
            {
                setCopyOnWrite(true);
                final MutableFloatMatrix.Abs.Sparse<U> result =
                        new MutableFloatMatrix.Abs.Sparse<U>(getMatrixSI(), getUnit());
                result.setCopyOnWrite(true);
                return result;
            }

            /** {@inheritDoc} */
            @Override
            protected final FloatMatrix2D createMatrix2D(final int rows, final int columns)
            {
                return new SparseFloatMatrix2D(rows, columns);
            }

            /** {@inheritDoc} */
            @Override
            public final MutableFloatMatrix.Abs.Sparse<U> copy()
            {
                return mutable();
            }

        }

        /** {@inheritDoc} */
        @Override
        public final FloatScalar.Abs<U> get(final int row, final int column) throws ValueException
        {
            return new FloatScalar.Abs<U>(getInUnit(row, column, getUnit()), getUnit());
        }

        /**
         * Increment the value by the supplied value and return the result.
         * @param increment FloatMatrix.Rel&lt;U&gt;; amount by which the value is incremented
         * @return MutableFloatMatrix.Abs&lt;U&gt;
         * @throws ValueException when the size of increment is not identical to the size of this
         */
        public final MutableFloatMatrix.Abs<U> incrementBy(final FloatMatrix.Rel<U> increment) throws ValueException
        {
            return (MutableFloatMatrix.Abs<U>) incrementByImpl(increment);
        }

        /**
         * Decrement the value by the supplied value and return the result.
         * @param decrement FloatMatrix.Rel&lt;U&gt;; amount by which the value is decremented
         * @return MutableFloatMatrix.Abs&lt;U&gt;
         * @throws ValueException when the size of increment is not identical to the size of this
         */
        public final MutableFloatMatrix.Abs<U> decrementBy(final FloatMatrix.Rel<U> decrement) throws ValueException
        {
            return (MutableFloatMatrix.Abs<U>) decrementByImpl(decrement);
        }

        /**********************************************************************************/
        /********************************** MATH METHODS **********************************/
        /**********************************************************************************/

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> abs()
        {
            assign(FloatFunctions.abs);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> acos()
        {
            assign(FloatFunctions.acos);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> asin()
        {
            assign(FloatFunctions.asin);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> atan()
        {
            assign(FloatFunctions.atan);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> cbrt()
        {
            assign(FloatMathFunctionsImpl.cbrt);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> ceil()
        {
            assign(FloatFunctions.ceil);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> cos()
        {
            assign(FloatFunctions.cos);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> cosh()
        {
            assign(FloatMathFunctionsImpl.cosh);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> exp()
        {
            assign(FloatFunctions.exp);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> expm1()
        {
            assign(FloatMathFunctionsImpl.expm1);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> floor()
        {
            assign(FloatFunctions.floor);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> log()
        {
            assign(FloatFunctions.log);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> log10()
        {
            assign(FloatMathFunctionsImpl.log10);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> log1p()
        {
            assign(FloatMathFunctionsImpl.log1p);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> pow(final double x)
        {
            assign(FloatFunctions.pow((float) x));
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> rint()
        {
            assign(FloatFunctions.rint);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> round()
        {
            assign(FloatMathFunctionsImpl.round);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> signum()
        {
            assign(FloatMathFunctionsImpl.signum);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> sin()
        {
            assign(FloatFunctions.sin);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> sinh()
        {
            assign(FloatMathFunctionsImpl.sinh);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> sqrt()
        {
            assign(FloatFunctions.sqrt);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> tan()
        {
            assign(FloatFunctions.tan);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> tanh()
        {
            assign(FloatMathFunctionsImpl.tanh);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> toDegrees()
        {
            assign(FloatMathFunctionsImpl.toDegrees);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> toRadians()
        {
            assign(FloatMathFunctionsImpl.toRadians);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Abs<U> inv()
        {
            assign(FloatFunctions.inv);
            return this;
        }

    }

    /**
     * @param <U> Unit
     */
    public abstract static class Rel<U extends Unit<U>> extends MutableFloatMatrix<U> implements Relative
    {
        /**  */
        private static final long serialVersionUID = 20150309L;

        /**
         * Construct a new Relative MutableFloatMatrix.
         * @param unit U; the unit of the new Relative MutableFloatMatrix
         */
        protected Rel(final U unit)
        {
            super(unit);
            // System.out.println("Created Rel");
        }

        /**
         * @param <U> Unit
         */
        public static class Dense<U extends Unit<U>> extends Rel<U> implements DenseData
        {
            /**  */
            private static final long serialVersionUID = 20150309L;

            /**
             * Construct a new Relative Dense MutableFloatMatrix.
             * @param values float[][]; the initial values of the entries in the new Relative Dense MutableFloatMatrix
             * @param unit U; the unit of the new Relative Dense MutableFloatMatrix
             * @throws ValueException when values is null, or is not rectangular
             */
            public Dense(final float[][] values, final U unit) throws ValueException
            {
                super(unit);
                // System.out.println("Created Dense");
                initialize(values);
            }

            /**
             * Construct a new Relative Dense MutableFloatMatrix.
             * @param values FloatScalar.Rel&lt;U&gt;[][]; the initial values of the entries in the new Relative Dense
             *            MutableFloatMatrix
             * @throws ValueException when values has zero entries, or is not rectangular
             */
            public Dense(final FloatScalar.Rel<U>[][] values) throws ValueException
            {
                super(checkNonEmpty(values)[0][0].getUnit());
                // System.out.println("Created Dense");
                initialize(values);
            }

            /**
             * For package internal use only.
             * @param values FloatMatrix2D; the initial values of the entries in the new Relative Dense
             *            MutableFloatMatrix
             * @param unit U; the unit of the new Relative Dense MutableFloatMatrix
             */
            protected Dense(final FloatMatrix2D values, final U unit)
            {
                super(unit);
                // System.out.println("Created Dense");
                setCopyOnWrite(true);
                initialize(values); // shallow copy
            }

            /** {@inheritDoc} */
            @Override
            public final FloatMatrix.Rel.Dense<U> immutable()
            {
                setCopyOnWrite(true);
                return new FloatMatrix.Rel.Dense<U>(getMatrixSI(), getUnit());
            }

            /** {@inheritDoc} */
            @Override
            public final MutableFloatMatrix.Rel.Dense<U> mutable()
            {
                setCopyOnWrite(true);
                final MutableFloatMatrix.Rel.Dense<U> result =
                        new MutableFloatMatrix.Rel.Dense<U>(getMatrixSI(), getUnit());
                result.setCopyOnWrite(true);
                return result;
            }

            /** {@inheritDoc} */
            @Override
            protected final FloatMatrix2D createMatrix2D(final int rows, final int columns)
            {
                return new DenseFloatMatrix2D(rows, columns);
            }

            /** {@inheritDoc} */
            @Override
            public final MutableFloatMatrix.Rel.Dense<U> copy()
            {
                return mutable();
            }

        }

        /**
         * @param <U> Unit
         */
        public static class Sparse<U extends Unit<U>> extends Rel<U> implements SparseData
        {
            /**  */
            private static final long serialVersionUID = 20150309L;

            /**
             * Construct a new Relative Sparse MutableFloatMatrix.
             * @param values float[][]; the initial values of the entries in the new Relative Sparse MutableFloatMatrix
             * @param unit U; the unit of the new Relative Sparse MutableFloatMatrix
             * @throws ValueException when values is null, or is not rectangular
             */
            public Sparse(final float[][] values, final U unit) throws ValueException
            {
                super(unit);
                // System.out.println("Created Sparse");
                initialize(values);
            }

            /**
             * Construct a new Relative Sparse MutableFloatMatrix.
             * @param values FloatScalar.Rel&lt;U&gt;[][]; the initial values of the entries in the new Relative Sparse
             *            MutableFloatMatrix
             * @throws ValueException when values has zero entries, or is not rectangular
             */
            public Sparse(final FloatScalar.Rel<U>[][] values) throws ValueException
            {
                super(checkNonEmpty(values)[0][0].getUnit());
                // System.out.println("Created Sparse");
                initialize(values);
            }

            /**
             * For package internal use only.
             * @param values FloatMatrix2D; the initial values of the entries in the new Relative Sparse
             *            MutableFloatMatrix
             * @param unit U; the unit of the new Relative Sparse MutableFloatMatrix
             */
            protected Sparse(final FloatMatrix2D values, final U unit)
            {
                super(unit);
                // System.out.println("Created Sparse");
                setCopyOnWrite(true);
                initialize(values); // shallow copy
            }

            /** {@inheritDoc} */
            @Override
            public final FloatMatrix.Rel.Sparse<U> immutable()
            {
                setCopyOnWrite(true);
                return new FloatMatrix.Rel.Sparse<U>(getMatrixSI(), getUnit());
            }

            /** {@inheritDoc} */
            @Override
            public final MutableFloatMatrix.Rel.Sparse<U> mutable()
            {
                setCopyOnWrite(true);
                final MutableFloatMatrix.Rel.Sparse<U> result =
                        new MutableFloatMatrix.Rel.Sparse<U>(getMatrixSI(), getUnit());
                result.setCopyOnWrite(true);
                return result;
            }

            /** {@inheritDoc} */
            @Override
            protected final FloatMatrix2D createMatrix2D(final int rows, final int columns)
            {
                return new SparseFloatMatrix2D(rows, columns);
            }

            /** {@inheritDoc} */
            @Override
            public final MutableFloatMatrix.Rel.Sparse<U> copy()
            {
                return mutable();
            }

        }

        /** {@inheritDoc} */
        @Override
        public final FloatScalar.Rel<U> get(final int row, final int column) throws ValueException
        {
            return new FloatScalar.Rel<U>(getInUnit(row, column, getUnit()), getUnit());
        }

        /**
         * Increment the value by the supplied value and return the result.
         * @param increment FloatMatrix.Rel&lt;U&gt;; amount by which the value is incremented
         * @return MutableFloatMatrix.Rel&lt;U&gt;
         * @throws ValueException when the size of increment is not identical to the size of this
         */
        public final MutableFloatMatrix.Rel<U> incrementBy(final FloatMatrix.Rel<U> increment) throws ValueException
        {
            return (MutableFloatMatrix.Rel<U>) incrementByImpl(increment);
        }

        /**
         * Decrement the value by the supplied value and return the result.
         * @param decrement FloatMatrix.Rel&lt;U&gt;; amount by which the value is decremented
         * @return MutableFloatMatrix.Rel&lt;U&gt;
         * @throws ValueException when the size of increment is not identical to the size of this
         */
        public final MutableFloatMatrix.Rel<U> decrementBy(final FloatMatrix.Rel<U> decrement) throws ValueException
        {
            return (MutableFloatMatrix.Rel<U>) decrementByImpl(decrement);
        }

        /**********************************************************************************/
        /********************************** MATH METHODS **********************************/
        /**********************************************************************************/

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> abs()
        {
            assign(FloatFunctions.abs);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> acos()
        {
            assign(FloatFunctions.acos);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> asin()
        {
            assign(FloatFunctions.asin);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> atan()
        {
            assign(FloatFunctions.atan);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> cbrt()
        {
            assign(FloatMathFunctionsImpl.cbrt);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> ceil()
        {
            assign(FloatFunctions.ceil);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> cos()
        {
            assign(FloatFunctions.cos);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> cosh()
        {
            assign(FloatMathFunctionsImpl.cosh);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> exp()
        {
            assign(FloatFunctions.exp);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> expm1()
        {
            assign(FloatMathFunctionsImpl.expm1);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> floor()
        {
            assign(FloatFunctions.floor);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> log()
        {
            assign(FloatFunctions.log);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> log10()
        {
            assign(FloatMathFunctionsImpl.log10);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> log1p()
        {
            assign(FloatMathFunctionsImpl.log1p);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> pow(final double x)
        {
            assign(FloatFunctions.pow((float) x));
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> rint()
        {
            assign(FloatFunctions.rint);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> round()
        {
            assign(FloatMathFunctionsImpl.round);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> signum()
        {
            assign(FloatMathFunctionsImpl.signum);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> sin()
        {
            assign(FloatFunctions.sin);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> sinh()
        {
            assign(FloatMathFunctionsImpl.sinh);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> sqrt()
        {
            assign(FloatFunctions.sqrt);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> tan()
        {
            assign(FloatFunctions.tan);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> tanh()
        {
            assign(FloatMathFunctionsImpl.tanh);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> toDegrees()
        {
            assign(FloatMathFunctionsImpl.toDegrees);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> toRadians()
        {
            assign(FloatMathFunctionsImpl.toRadians);
            return this;
        }

        /** {@inheritDoc} */
        @Override
        public final MutableFloatMatrix.Rel<U> inv()
        {
            assign(FloatFunctions.inv);
            return this;
        }

    }

    /**
     * Make (immutable) FloatMatrix equivalent for any type of MutableFloatMatrix.
     * @return FloatMatrix&lt;U&gt;; immutable version of this FloatMatrix
     */
    public abstract FloatMatrix<U> immutable();

    /**
     * Check the copyOnWrite flag and, if it is set, make a deep copy of the data and clear the flag.
     */
    protected final void checkCopyOnWrite()
    {
        if (isCopyOnWrite())
        {
            // System.out.println("copyOnWrite is set: Copying data");
            deepCopyData();
            setCopyOnWrite(false);
        }
    }

    /** {@inheritDoc} */
    @Override
    public final void setSI(final int row, final int column, final float valueSI) throws ValueException
    {
        checkIndex(row, column);
        checkCopyOnWrite();
        safeSet(row, column, valueSI);
    }

    /** {@inheritDoc} */
    @Override
    public final void set(final int row, final int column, final FloatScalar<U> value) throws ValueException
    {
        setSI(row, column, value.getSI());
    }

    /** {@inheritDoc} */
    @Override
    public final void setInUnit(final int row, final int column, final float value, final U valueUnit)
            throws ValueException
    {
        setSI(row, column, (float) ValueUtil.expressAsSIUnit(value, valueUnit));
    }

    /**
     * Execute a function on a cell by cell basis.
     * @param f cern.colt.function.tfloat.FloatFunction; the function to apply
     */
    public final void assign(final cern.colt.function.tfloat.FloatFunction f)
    {
        checkCopyOnWrite();
        getMatrixSI().assign(f);
    }

    /** {@inheritDoc} */
    @Override
    public final MutableFloatMatrix<U> multiply(final float constant)
    {
        assign(FloatFunctions.mult(constant));
        return this;
    }

    /** {@inheritDoc} */
    @Override
    public final MutableFloatMatrix<U> divide(final float constant)
    {
        assign(FloatFunctions.div(constant));
        return this;
    }

    /**********************************************************************************/
    /******************************* NON-STATIC METHODS *******************************/
    /**********************************************************************************/

    /**
     * Increment the values in this MutableFloatMatrix by the corresponding values in a FloatMatrix.
     * @param increment FloatMatrix&lt;U&gt;; the values by which to increment the corresponding values in this
     *            MutableFloatMatrix
     * @return MutableFloatMatrix&lt;U&gt;; this modified MutableFloatMatrix
     * @throws ValueException when the matrices do not have the same size
     */
    private MutableFloatMatrix<U> incrementValueByValue(final FloatMatrix<U> increment) throws ValueException
    {
        checkSizeAndCopyOnWrite(increment);
        for (int row = rows(); --row >= 0;)
        {
            for (int column = columns(); --column >= 0;)
            {
                safeSet(row, column, safeGet(row, column) + increment.safeGet(row, column));
            }
        }
        return this;
    }

    /**
     * Decrement the values in this MutableFloatMatrix by the corresponding values in a FloatMatrix.
     * @param decrement FloatMatrix&lt;U&gt;; the values by which to decrement the corresponding values in this
     *            MutableFloatMatrix
     * @return MutableFloatMatrix&lt;U&gt;; this modified MutableFloatMatrix
     * @throws ValueException when the matrices do not have the same size
     */
    private MutableFloatMatrix<U> decrementValueByValue(final FloatMatrix<U> decrement) throws ValueException
    {
        checkSizeAndCopyOnWrite(decrement);
        for (int row = rows(); --row >= 0;)
        {
            for (int column = columns(); --column >= 0;)
            {
                safeSet(row, column, safeGet(row, column) - decrement.safeGet(row, column));
            }
        }
        return this;
    }

    /**
     * Increment the values in this MutableFloatMatrix by the corresponding values in a Relative FloatMatrix. <br>
     * Only Relative values are allowed; adding an Absolute value to an Absolute value is not allowed. Adding an
     * Absolute value to an existing Relative value would require the result to become Absolute, which is a type change
     * that is impossible. For that operation use a static method.
     * @param rel FloatMatrix.Rel&lt;U&gt;; the Relative FloatMatrix
     * @return MutableFloatMatrix&lt;U&gt;; this modified MutableFloatMatrix
     * @throws ValueException when the matrices do not have the same size
     */
    protected final MutableFloatMatrix<U> incrementByImpl(final FloatMatrix.Rel<U> rel) throws ValueException
    {
        return incrementValueByValue(rel);
    }

    /**
     * Decrement the corresponding values of this Relative FloatMatrix from the values of this MutableFloatMatrix. <br>
     * Only Relative values are allowed; subtracting an Absolute value from a Relative value is not allowed. Subtracting
     * an Absolute value from an existing Absolute value would require the result to become Relative, which is a type
     * change that is impossible. For that operation use a static method.
     * @param rel FloatMatrix.Rel&lt;U&gt;; the Relative FloatMatrix
     * @return MutableFloatMatrix&lt;U&gt;; this modified MutableFloatMatrix
     * @throws ValueException when the matrices do not have the same size
     */
    protected final MutableFloatMatrix<U> decrementByImpl(final FloatMatrix.Rel<U> rel) throws ValueException
    {
        return decrementValueByValue(rel);
    }

    // FIXME It makes no sense to subtract an Absolute from a Relative
    /**
     * Decrement the values in this Relative MutableFloatMatrix by the corresponding values in an Absolute FloatMatrix.
     * @param abs FloatMatrix.Abs&lt;U&gt;; the Absolute FloatMatrix
     * @return MutableFloatMatrix.Rel&lt;U&gt;; this modified Relative MutableFloatMatrix
     * @throws ValueException when the matrices do not have the same size
     */
    protected final MutableFloatMatrix.Rel<U> decrementBy(final FloatMatrix.Abs<U> abs) throws ValueException
    {
        return (MutableFloatMatrix.Rel<U>) decrementValueByValue(abs);
    }

    /**
     * Scale the values in this MutableFloatMatrix by the corresponding values in a FloatMatrix.
     * @param factor FloatMatrix&lt;?&gt;; contains the values by which to scale the corresponding values in this
     *            MutableFloatMatrix
     * @throws ValueException when the matrices do not have the same size
     */
    protected final void scaleValueByValue(final FloatMatrix<?> factor) throws ValueException
    {
        checkSizeAndCopyOnWrite(factor);
        for (int row = rows(); --row >= 0;)
        {
            for (int column = columns(); --column >= 0;)
            {
                safeSet(row, column, safeGet(row, column) * factor.safeGet(row, column));
            }
        }
    }

    /**
     * Scale the values in this MutableFloatMatrix by the corresponding values in a float array.
     * @param factor float[][]; contains the values by which to scale the corresponding values in this
     *            MutableFloatMatrix
     * @return MutableFloatMatrix&lt;U&gt;; this modified MutableFloatMatrix
     * @throws ValueException when the matrix and the array do not have the same size
     */
    protected final MutableFloatMatrix<U> scaleValueByValue(final float[][] factor) throws ValueException
    {
        checkSizeAndCopyOnWrite(factor);
        for (int row = rows(); --row >= 0;)
        {
            for (int column = columns(); --column >= 0;)
            {
                safeSet(row, column, safeGet(row, column) * factor[row][column]);
            }
        }
        return this;
    }

    /**
     * Check sizes and copy the data if the copyOnWrite flag is set.
     * @param other FloatMatrix&lt;?&gt;; partner for the size check
     * @throws ValueException when the matrices do not have the same size
     */
    private void checkSizeAndCopyOnWrite(final FloatMatrix<?> other) throws ValueException
    {
        checkSize(other);
        checkCopyOnWrite();
    }

    /**
     * Check sizes and copy the data if the copyOnWrite flag is set.
     * @param other float[][]; partner for the size check
     * @throws ValueException when the matrices do not have the same size
     */
    private void checkSizeAndCopyOnWrite(final float[][] other) throws ValueException
    {
        checkSize(other);
        checkCopyOnWrite();
    }

}