View Javadoc
1   package org.opentrafficsim.core.value.vdouble.vector;
2   
3   import org.opentrafficsim.core.unit.Unit;
4   import org.opentrafficsim.core.value.Absolute;
5   import org.opentrafficsim.core.value.DenseData;
6   import org.opentrafficsim.core.value.Relative;
7   import org.opentrafficsim.core.value.SparseData;
8   import org.opentrafficsim.core.value.ValueException;
9   import org.opentrafficsim.core.value.ValueUtil;
10  import org.opentrafficsim.core.value.vdouble.DoubleMathFunctions;
11  import org.opentrafficsim.core.value.vdouble.DoubleMathFunctionsImpl;
12  import org.opentrafficsim.core.value.vdouble.scalar.DoubleScalar;
13  
14  import cern.colt.matrix.tdouble.DoubleMatrix1D;
15  import cern.colt.matrix.tdouble.impl.DenseDoubleMatrix1D;
16  import cern.colt.matrix.tdouble.impl.SparseDoubleMatrix1D;
17  import cern.jet.math.tdouble.DoubleFunctions;
18  
19  /**
20   * MutableDoubleVector.
21   * <p>
22   * This file was generated by the OpenTrafficSim value classes generator, 09 mrt, 2015
23   * <p>
24   * Copyright (c) 2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
25   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
26   * <p>
27   * @version 09 mrt, 2015 <br>
28   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
29   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
30   * @param <U> Unit; the unit of this MutableDoubleVector
31   */
32  public abstract class MutableDoubleVector<U extends Unit<U>> extends DoubleVector<U> implements
33          WriteDoubleVectorFunctions<U>, DoubleMathFunctions<MutableDoubleVector<U>>
34  {
35      /**  */
36      private static final long serialVersionUID = 20150309L;
37  
38      /**
39       * Construct a new MutableDoubleVector.
40       * @param unit U; the unit of the new MutableDoubleVector
41       */
42      protected MutableDoubleVector(final U unit)
43      {
44          super(unit);
45          // System.out.println("Created MutableDoubleVector");
46      }
47  
48      /** If set, any modification of the data must be preceded by replacing the data with a local copy. */
49      private boolean copyOnWrite = false;
50  
51      /**
52       * Retrieve the value of the copyOnWrite flag.
53       * @return boolean
54       */
55      private boolean isCopyOnWrite()
56      {
57          return this.copyOnWrite;
58      }
59  
60      /**
61       * Change the copyOnWrite flag.
62       * @param copyOnWrite boolean; the new value for the copyOnWrite flag
63       */
64      final void setCopyOnWrite(final boolean copyOnWrite)
65      {
66          this.copyOnWrite = copyOnWrite;
67      }
68  
69      /** {@inheritDoc} */
70      @Override
71      public final void normalize() throws ValueException
72      {
73          double sum = zSum();
74          if (0 == sum)
75          {
76              throw new ValueException("zSum is 0; cannot normalize");
77          }
78          checkCopyOnWrite();
79          for (int i = 0; i < size(); i++)
80          {
81              safeSet(i, safeGet(i) / sum);
82          }
83      }
84  
85      /**
86       * @param <U> Unit
87       */
88      public abstract static class Abs<U extends Unit<U>> extends MutableDoubleVector<U> implements Absolute
89      {
90          /**  */
91          private static final long serialVersionUID = 20150309L;
92  
93          /**
94           * Construct a new Absolute MutableDoubleVector.
95           * @param unit U; the unit of the new Absolute MutableDoubleVector
96           */
97          protected Abs(final U unit)
98          {
99              super(unit);
100             // System.out.println("Created Abs");
101         }
102 
103         /**
104          * @param <U> Unit
105          */
106         public static class Dense<U extends Unit<U>> extends Abs<U> implements DenseData
107         {
108             /**  */
109             private static final long serialVersionUID = 20150309L;
110 
111             /**
112              * Construct a new Absolute Dense MutableDoubleVector.
113              * @param values double[]; the initial values of the entries in the new Absolute Dense MutableDoubleVector
114              * @param unit U; the unit of the new Absolute Dense MutableDoubleVector
115              * @throws ValueException when values is null
116              */
117             public Dense(final double[] values, final U unit) throws ValueException
118             {
119                 super(unit);
120                 // System.out.println("Created Dense");
121                 initialize(values);
122             }
123 
124             /**
125              * Construct a new Absolute Dense MutableDoubleVector.
126              * @param values DoubleScalar.Abs&lt;U&gt;[]; the initial values of the entries in the new Absolute Dense
127              *            MutableDoubleVector
128              * @throws ValueException when values has zero entries
129              */
130             public Dense(final DoubleScalar.Abs<U>[] values) throws ValueException
131             {
132                 super(checkNonEmpty(values)[0].getUnit());
133                 // System.out.println("Created Dense");
134                 initialize(values);
135             }
136 
137             /**
138              * For package internal use only.
139              * @param values DoubleMatrix1D; the initial values of the entries in the new Absolute Dense
140              *            MutableDoubleVector
141              * @param unit U; the unit of the new Absolute Dense MutableDoubleVector
142              */
143             protected Dense(final DoubleMatrix1D values, final U unit)
144             {
145                 super(unit);
146                 // System.out.println("Created Dense");
147                 setCopyOnWrite(true);
148                 initialize(values); // shallow copy
149             }
150 
151             /** {@inheritDoc} */
152             @Override
153             public final DoubleVector.Abs.Dense<U> immutable()
154             {
155                 setCopyOnWrite(true);
156                 return new DoubleVector.Abs.Dense<U>(getVectorSI(), getUnit());
157             }
158 
159             /** {@inheritDoc} */
160             @Override
161             public final MutableDoubleVector.Abs.Dense<U> mutable()
162             {
163                 setCopyOnWrite(true);
164                 final MutableDoubleVector.Abs.Dense<U> result =
165                         new MutableDoubleVector.Abs.Dense<U>(getVectorSI(), getUnit());
166                 result.setCopyOnWrite(true);
167                 return result;
168             }
169 
170             /** {@inheritDoc} */
171             @Override
172             protected final DoubleMatrix1D createMatrix1D(final int size)
173             {
174                 return new DenseDoubleMatrix1D(size);
175             }
176 
177             /** {@inheritDoc} */
178             @Override
179             public final MutableDoubleVector.Abs.Dense<U> copy()
180             {
181                 return mutable();
182             }
183 
184         }
185 
186         /**
187          * @param <U> Unit
188          */
189         public static class Sparse<U extends Unit<U>> extends Abs<U> implements SparseData
190         {
191             /**  */
192             private static final long serialVersionUID = 20150309L;
193 
194             /**
195              * Construct a new Absolute Sparse MutableDoubleVector.
196              * @param values double[]; the initial values of the entries in the new Absolute Sparse MutableDoubleVector
197              * @param unit U; the unit of the new Absolute Sparse MutableDoubleVector
198              * @throws ValueException when values is null
199              */
200             public Sparse(final double[] values, final U unit) throws ValueException
201             {
202                 super(unit);
203                 // System.out.println("Created Sparse");
204                 initialize(values);
205             }
206 
207             /**
208              * Construct a new Absolute Sparse MutableDoubleVector.
209              * @param values DoubleScalar.Abs&lt;U&gt;[]; the initial values of the entries in the new Absolute Sparse
210              *            MutableDoubleVector
211              * @throws ValueException when values has zero entries
212              */
213             public Sparse(final DoubleScalar.Abs<U>[] values) throws ValueException
214             {
215                 super(checkNonEmpty(values)[0].getUnit());
216                 // System.out.println("Created Sparse");
217                 initialize(values);
218             }
219 
220             /**
221              * For package internal use only.
222              * @param values DoubleMatrix1D; the initial values of the entries in the new Absolute Sparse
223              *            MutableDoubleVector
224              * @param unit U; the unit of the new Absolute Sparse MutableDoubleVector
225              */
226             protected Sparse(final DoubleMatrix1D values, final U unit)
227             {
228                 super(unit);
229                 // System.out.println("Created Sparse");
230                 setCopyOnWrite(true);
231                 initialize(values); // shallow copy
232             }
233 
234             /** {@inheritDoc} */
235             @Override
236             public final DoubleVector.Abs.Sparse<U> immutable()
237             {
238                 setCopyOnWrite(true);
239                 return new DoubleVector.Abs.Sparse<U>(getVectorSI(), getUnit());
240             }
241 
242             /** {@inheritDoc} */
243             @Override
244             public final MutableDoubleVector.Abs.Sparse<U> mutable()
245             {
246                 setCopyOnWrite(true);
247                 final MutableDoubleVector.Abs.Sparse<U> result =
248                         new MutableDoubleVector.Abs.Sparse<U>(getVectorSI(), getUnit());
249                 result.setCopyOnWrite(true);
250                 return result;
251             }
252 
253             /** {@inheritDoc} */
254             @Override
255             protected final DoubleMatrix1D createMatrix1D(final int size)
256             {
257                 return new SparseDoubleMatrix1D(size);
258             }
259 
260             /** {@inheritDoc} */
261             @Override
262             public final MutableDoubleVector.Abs.Sparse<U> copy()
263             {
264                 return mutable();
265             }
266 
267         }
268 
269         /** {@inheritDoc} */
270         @Override
271         public final DoubleScalar.Abs<U> get(final int index) throws ValueException
272         {
273             return new DoubleScalar.Abs<U>(getInUnit(index, getUnit()), getUnit());
274         }
275 
276         /**
277          * Increment the value by the supplied value and return the result.
278          * @param increment DoubleVector.Rel&lt;U&gt;; amount by which the value is incremented
279          * @return MutableDoubleVector.Abs&lt;U&gt;
280          * @throws ValueException when the size of increment is not identical to the size of this
281          */
282         public final MutableDoubleVector.Abs<U> incrementBy(final DoubleVector.Rel<U> increment) throws ValueException
283         {
284             return (MutableDoubleVector.Abs<U>) incrementByImpl(increment);
285         }
286 
287         /**
288          * Decrement the value by the supplied value and return the result.
289          * @param decrement DoubleVector.Rel&lt;U&gt;; amount by which the value is decremented
290          * @return MutableDoubleVector.Abs&lt;U&gt;
291          * @throws ValueException when the size of increment is not identical to the size of this
292          */
293         public final MutableDoubleVector.Abs<U> decrementBy(final DoubleVector.Rel<U> decrement) throws ValueException
294         {
295             return (MutableDoubleVector.Abs<U>) decrementByImpl(decrement);
296         }
297 
298         /**********************************************************************************/
299         /********************************** MATH METHODS **********************************/
300         /**********************************************************************************/
301 
302         /** {@inheritDoc} */
303         @Override
304         public final MutableDoubleVector.Abs<U> abs()
305         {
306             assign(DoubleFunctions.abs);
307             return this;
308         }
309 
310         /** {@inheritDoc} */
311         @Override
312         public final MutableDoubleVector.Abs<U> acos()
313         {
314             assign(DoubleFunctions.acos);
315             return this;
316         }
317 
318         /** {@inheritDoc} */
319         @Override
320         public final MutableDoubleVector.Abs<U> asin()
321         {
322             assign(DoubleFunctions.asin);
323             return this;
324         }
325 
326         /** {@inheritDoc} */
327         @Override
328         public final MutableDoubleVector.Abs<U> atan()
329         {
330             assign(DoubleFunctions.atan);
331             return this;
332         }
333 
334         /** {@inheritDoc} */
335         @Override
336         public final MutableDoubleVector.Abs<U> cbrt()
337         {
338             assign(DoubleMathFunctionsImpl.cbrt);
339             return this;
340         }
341 
342         /** {@inheritDoc} */
343         @Override
344         public final MutableDoubleVector.Abs<U> ceil()
345         {
346             assign(DoubleFunctions.ceil);
347             return this;
348         }
349 
350         /** {@inheritDoc} */
351         @Override
352         public final MutableDoubleVector.Abs<U> cos()
353         {
354             assign(DoubleFunctions.cos);
355             return this;
356         }
357 
358         /** {@inheritDoc} */
359         @Override
360         public final MutableDoubleVector.Abs<U> cosh()
361         {
362             assign(DoubleMathFunctionsImpl.cosh);
363             return this;
364         }
365 
366         /** {@inheritDoc} */
367         @Override
368         public final MutableDoubleVector.Abs<U> exp()
369         {
370             assign(DoubleFunctions.exp);
371             return this;
372         }
373 
374         /** {@inheritDoc} */
375         @Override
376         public final MutableDoubleVector.Abs<U> expm1()
377         {
378             assign(DoubleMathFunctionsImpl.expm1);
379             return this;
380         }
381 
382         /** {@inheritDoc} */
383         @Override
384         public final MutableDoubleVector.Abs<U> floor()
385         {
386             assign(DoubleFunctions.floor);
387             return this;
388         }
389 
390         /** {@inheritDoc} */
391         @Override
392         public final MutableDoubleVector.Abs<U> log()
393         {
394             assign(DoubleFunctions.log);
395             return this;
396         }
397 
398         /** {@inheritDoc} */
399         @Override
400         public final MutableDoubleVector.Abs<U> log10()
401         {
402             assign(DoubleMathFunctionsImpl.log10);
403             return this;
404         }
405 
406         /** {@inheritDoc} */
407         @Override
408         public final MutableDoubleVector.Abs<U> log1p()
409         {
410             assign(DoubleMathFunctionsImpl.log1p);
411             return this;
412         }
413 
414         /** {@inheritDoc} */
415         @Override
416         public final MutableDoubleVector.Abs<U> pow(final double x)
417         {
418             assign(DoubleFunctions.pow(x));
419             return this;
420         }
421 
422         /** {@inheritDoc} */
423         @Override
424         public final MutableDoubleVector.Abs<U> rint()
425         {
426             assign(DoubleFunctions.rint);
427             return this;
428         }
429 
430         /** {@inheritDoc} */
431         @Override
432         public final MutableDoubleVector.Abs<U> round()
433         {
434             assign(DoubleMathFunctionsImpl.round);
435             return this;
436         }
437 
438         /** {@inheritDoc} */
439         @Override
440         public final MutableDoubleVector.Abs<U> signum()
441         {
442             assign(DoubleMathFunctionsImpl.signum);
443             return this;
444         }
445 
446         /** {@inheritDoc} */
447         @Override
448         public final MutableDoubleVector.Abs<U> sin()
449         {
450             assign(DoubleFunctions.sin);
451             return this;
452         }
453 
454         /** {@inheritDoc} */
455         @Override
456         public final MutableDoubleVector.Abs<U> sinh()
457         {
458             assign(DoubleMathFunctionsImpl.sinh);
459             return this;
460         }
461 
462         /** {@inheritDoc} */
463         @Override
464         public final MutableDoubleVector.Abs<U> sqrt()
465         {
466             assign(DoubleFunctions.sqrt);
467             return this;
468         }
469 
470         /** {@inheritDoc} */
471         @Override
472         public final MutableDoubleVector.Abs<U> tan()
473         {
474             assign(DoubleFunctions.tan);
475             return this;
476         }
477 
478         /** {@inheritDoc} */
479         @Override
480         public final MutableDoubleVector.Abs<U> tanh()
481         {
482             assign(DoubleMathFunctionsImpl.tanh);
483             return this;
484         }
485 
486         /** {@inheritDoc} */
487         @Override
488         public final MutableDoubleVector.Abs<U> toDegrees()
489         {
490             assign(DoubleMathFunctionsImpl.toDegrees);
491             return this;
492         }
493 
494         /** {@inheritDoc} */
495         @Override
496         public final MutableDoubleVector.Abs<U> toRadians()
497         {
498             assign(DoubleMathFunctionsImpl.toRadians);
499             return this;
500         }
501 
502         /** {@inheritDoc} */
503         @Override
504         public final MutableDoubleVector.Abs<U> inv()
505         {
506             assign(DoubleFunctions.inv);
507             return this;
508         }
509 
510     }
511 
512     /**
513      * @param <U> Unit
514      */
515     public abstract static class Rel<U extends Unit<U>> extends MutableDoubleVector<U> implements Relative
516     {
517         /**  */
518         private static final long serialVersionUID = 20150309L;
519 
520         /**
521          * Construct a new Relative MutableDoubleVector.
522          * @param unit U; the unit of the new Relative MutableDoubleVector
523          */
524         protected Rel(final U unit)
525         {
526             super(unit);
527             // System.out.println("Created Rel");
528         }
529 
530         /**
531          * @param <U> Unit
532          */
533         public static class Dense<U extends Unit<U>> extends Rel<U> implements DenseData
534         {
535             /**  */
536             private static final long serialVersionUID = 20150309L;
537 
538             /**
539              * Construct a new Relative Dense MutableDoubleVector.
540              * @param values double[]; the initial values of the entries in the new Relative Dense MutableDoubleVector
541              * @param unit U; the unit of the new Relative Dense MutableDoubleVector
542              * @throws ValueException when values is null
543              */
544             public Dense(final double[] values, final U unit) throws ValueException
545             {
546                 super(unit);
547                 // System.out.println("Created Dense");
548                 initialize(values);
549             }
550 
551             /**
552              * Construct a new Relative Dense MutableDoubleVector.
553              * @param values DoubleScalar.Rel&lt;U&gt;[]; the initial values of the entries in the new Relative Dense
554              *            MutableDoubleVector
555              * @throws ValueException when values has zero entries
556              */
557             public Dense(final DoubleScalar.Rel<U>[] values) throws ValueException
558             {
559                 super(checkNonEmpty(values)[0].getUnit());
560                 // System.out.println("Created Dense");
561                 initialize(values);
562             }
563 
564             /**
565              * For package internal use only.
566              * @param values DoubleMatrix1D; the initial values of the entries in the new Relative Dense
567              *            MutableDoubleVector
568              * @param unit U; the unit of the new Relative Dense MutableDoubleVector
569              */
570             protected Dense(final DoubleMatrix1D values, final U unit)
571             {
572                 super(unit);
573                 // System.out.println("Created Dense");
574                 setCopyOnWrite(true);
575                 initialize(values); // shallow copy
576             }
577 
578             /** {@inheritDoc} */
579             @Override
580             public final DoubleVector.Rel.Dense<U> immutable()
581             {
582                 setCopyOnWrite(true);
583                 return new DoubleVector.Rel.Dense<U>(getVectorSI(), getUnit());
584             }
585 
586             /** {@inheritDoc} */
587             @Override
588             public final MutableDoubleVector.Rel.Dense<U> mutable()
589             {
590                 setCopyOnWrite(true);
591                 final MutableDoubleVector.Rel.Dense<U> result =
592                         new MutableDoubleVector.Rel.Dense<U>(getVectorSI(), getUnit());
593                 result.setCopyOnWrite(true);
594                 return result;
595             }
596 
597             /** {@inheritDoc} */
598             @Override
599             protected final DoubleMatrix1D createMatrix1D(final int size)
600             {
601                 return new DenseDoubleMatrix1D(size);
602             }
603 
604             /** {@inheritDoc} */
605             @Override
606             public final MutableDoubleVector.Rel.Dense<U> copy()
607             {
608                 return mutable();
609             }
610 
611         }
612 
613         /**
614          * @param <U> Unit
615          */
616         public static class Sparse<U extends Unit<U>> extends Rel<U> implements SparseData
617         {
618             /**  */
619             private static final long serialVersionUID = 20150309L;
620 
621             /**
622              * Construct a new Relative Sparse MutableDoubleVector.
623              * @param values double[]; the initial values of the entries in the new Relative Sparse MutableDoubleVector
624              * @param unit U; the unit of the new Relative Sparse MutableDoubleVector
625              * @throws ValueException when values is null
626              */
627             public Sparse(final double[] values, final U unit) throws ValueException
628             {
629                 super(unit);
630                 // System.out.println("Created Sparse");
631                 initialize(values);
632             }
633 
634             /**
635              * Construct a new Relative Sparse MutableDoubleVector.
636              * @param values DoubleScalar.Rel&lt;U&gt;[]; the initial values of the entries in the new Relative Sparse
637              *            MutableDoubleVector
638              * @throws ValueException when values has zero entries
639              */
640             public Sparse(final DoubleScalar.Rel<U>[] values) throws ValueException
641             {
642                 super(checkNonEmpty(values)[0].getUnit());
643                 // System.out.println("Created Sparse");
644                 initialize(values);
645             }
646 
647             /**
648              * For package internal use only.
649              * @param values DoubleMatrix1D; the initial values of the entries in the new Relative Sparse
650              *            MutableDoubleVector
651              * @param unit U; the unit of the new Relative Sparse MutableDoubleVector
652              */
653             protected Sparse(final DoubleMatrix1D values, final U unit)
654             {
655                 super(unit);
656                 // System.out.println("Created Sparse");
657                 setCopyOnWrite(true);
658                 initialize(values); // shallow copy
659             }
660 
661             /** {@inheritDoc} */
662             @Override
663             public final DoubleVector.Rel.Sparse<U> immutable()
664             {
665                 setCopyOnWrite(true);
666                 return new DoubleVector.Rel.Sparse<U>(getVectorSI(), getUnit());
667             }
668 
669             /** {@inheritDoc} */
670             @Override
671             public final MutableDoubleVector.Rel.Sparse<U> mutable()
672             {
673                 setCopyOnWrite(true);
674                 final MutableDoubleVector.Rel.Sparse<U> result =
675                         new MutableDoubleVector.Rel.Sparse<U>(getVectorSI(), getUnit());
676                 result.setCopyOnWrite(true);
677                 return result;
678             }
679 
680             /** {@inheritDoc} */
681             @Override
682             protected final DoubleMatrix1D createMatrix1D(final int size)
683             {
684                 return new SparseDoubleMatrix1D(size);
685             }
686 
687             /** {@inheritDoc} */
688             @Override
689             public final MutableDoubleVector.Rel.Sparse<U> copy()
690             {
691                 return mutable();
692             }
693 
694         }
695 
696         /** {@inheritDoc} */
697         @Override
698         public final DoubleScalar.Rel<U> get(final int index) throws ValueException
699         {
700             return new DoubleScalar.Rel<U>(getInUnit(index, getUnit()), getUnit());
701         }
702 
703         /**
704          * Increment the value by the supplied value and return the result.
705          * @param increment DoubleVector.Rel&lt;U&gt;; amount by which the value is incremented
706          * @return MutableDoubleVector.Rel&lt;U&gt;
707          * @throws ValueException when the size of increment is not identical to the size of this
708          */
709         public final MutableDoubleVector.Rel<U> incrementBy(final DoubleVector.Rel<U> increment) throws ValueException
710         {
711             return (MutableDoubleVector.Rel<U>) incrementByImpl(increment);
712         }
713 
714         /**
715          * Decrement the value by the supplied value and return the result.
716          * @param decrement DoubleVector.Rel&lt;U&gt;; amount by which the value is decremented
717          * @return MutableDoubleVector.Rel&lt;U&gt;
718          * @throws ValueException when the size of increment is not identical to the size of this
719          */
720         public final MutableDoubleVector.Rel<U> decrementBy(final DoubleVector.Rel<U> decrement) throws ValueException
721         {
722             return (MutableDoubleVector.Rel<U>) decrementByImpl(decrement);
723         }
724 
725         /**********************************************************************************/
726         /********************************** MATH METHODS **********************************/
727         /**********************************************************************************/
728 
729         /** {@inheritDoc} */
730         @Override
731         public final MutableDoubleVector.Rel<U> abs()
732         {
733             assign(DoubleFunctions.abs);
734             return this;
735         }
736 
737         /** {@inheritDoc} */
738         @Override
739         public final MutableDoubleVector.Rel<U> acos()
740         {
741             assign(DoubleFunctions.acos);
742             return this;
743         }
744 
745         /** {@inheritDoc} */
746         @Override
747         public final MutableDoubleVector.Rel<U> asin()
748         {
749             assign(DoubleFunctions.asin);
750             return this;
751         }
752 
753         /** {@inheritDoc} */
754         @Override
755         public final MutableDoubleVector.Rel<U> atan()
756         {
757             assign(DoubleFunctions.atan);
758             return this;
759         }
760 
761         /** {@inheritDoc} */
762         @Override
763         public final MutableDoubleVector.Rel<U> cbrt()
764         {
765             assign(DoubleMathFunctionsImpl.cbrt);
766             return this;
767         }
768 
769         /** {@inheritDoc} */
770         @Override
771         public final MutableDoubleVector.Rel<U> ceil()
772         {
773             assign(DoubleFunctions.ceil);
774             return this;
775         }
776 
777         /** {@inheritDoc} */
778         @Override
779         public final MutableDoubleVector.Rel<U> cos()
780         {
781             assign(DoubleFunctions.cos);
782             return this;
783         }
784 
785         /** {@inheritDoc} */
786         @Override
787         public final MutableDoubleVector.Rel<U> cosh()
788         {
789             assign(DoubleMathFunctionsImpl.cosh);
790             return this;
791         }
792 
793         /** {@inheritDoc} */
794         @Override
795         public final MutableDoubleVector.Rel<U> exp()
796         {
797             assign(DoubleFunctions.exp);
798             return this;
799         }
800 
801         /** {@inheritDoc} */
802         @Override
803         public final MutableDoubleVector.Rel<U> expm1()
804         {
805             assign(DoubleMathFunctionsImpl.expm1);
806             return this;
807         }
808 
809         /** {@inheritDoc} */
810         @Override
811         public final MutableDoubleVector.Rel<U> floor()
812         {
813             assign(DoubleFunctions.floor);
814             return this;
815         }
816 
817         /** {@inheritDoc} */
818         @Override
819         public final MutableDoubleVector.Rel<U> log()
820         {
821             assign(DoubleFunctions.log);
822             return this;
823         }
824 
825         /** {@inheritDoc} */
826         @Override
827         public final MutableDoubleVector.Rel<U> log10()
828         {
829             assign(DoubleMathFunctionsImpl.log10);
830             return this;
831         }
832 
833         /** {@inheritDoc} */
834         @Override
835         public final MutableDoubleVector.Rel<U> log1p()
836         {
837             assign(DoubleMathFunctionsImpl.log1p);
838             return this;
839         }
840 
841         /** {@inheritDoc} */
842         @Override
843         public final MutableDoubleVector.Rel<U> pow(final double x)
844         {
845             assign(DoubleFunctions.pow(x));
846             return this;
847         }
848 
849         /** {@inheritDoc} */
850         @Override
851         public final MutableDoubleVector.Rel<U> rint()
852         {
853             assign(DoubleFunctions.rint);
854             return this;
855         }
856 
857         /** {@inheritDoc} */
858         @Override
859         public final MutableDoubleVector.Rel<U> round()
860         {
861             assign(DoubleMathFunctionsImpl.round);
862             return this;
863         }
864 
865         /** {@inheritDoc} */
866         @Override
867         public final MutableDoubleVector.Rel<U> signum()
868         {
869             assign(DoubleMathFunctionsImpl.signum);
870             return this;
871         }
872 
873         /** {@inheritDoc} */
874         @Override
875         public final MutableDoubleVector.Rel<U> sin()
876         {
877             assign(DoubleFunctions.sin);
878             return this;
879         }
880 
881         /** {@inheritDoc} */
882         @Override
883         public final MutableDoubleVector.Rel<U> sinh()
884         {
885             assign(DoubleMathFunctionsImpl.sinh);
886             return this;
887         }
888 
889         /** {@inheritDoc} */
890         @Override
891         public final MutableDoubleVector.Rel<U> sqrt()
892         {
893             assign(DoubleFunctions.sqrt);
894             return this;
895         }
896 
897         /** {@inheritDoc} */
898         @Override
899         public final MutableDoubleVector.Rel<U> tan()
900         {
901             assign(DoubleFunctions.tan);
902             return this;
903         }
904 
905         /** {@inheritDoc} */
906         @Override
907         public final MutableDoubleVector.Rel<U> tanh()
908         {
909             assign(DoubleMathFunctionsImpl.tanh);
910             return this;
911         }
912 
913         /** {@inheritDoc} */
914         @Override
915         public final MutableDoubleVector.Rel<U> toDegrees()
916         {
917             assign(DoubleMathFunctionsImpl.toDegrees);
918             return this;
919         }
920 
921         /** {@inheritDoc} */
922         @Override
923         public final MutableDoubleVector.Rel<U> toRadians()
924         {
925             assign(DoubleMathFunctionsImpl.toRadians);
926             return this;
927         }
928 
929         /** {@inheritDoc} */
930         @Override
931         public final MutableDoubleVector.Rel<U> inv()
932         {
933             assign(DoubleFunctions.inv);
934             return this;
935         }
936 
937     }
938 
939     /**
940      * Make (immutable) DoubleVector equivalent for any type of MutableDoubleVector.
941      * @return DoubleVector&lt;U&gt;; immutable version of this DoubleVector
942      */
943     public abstract DoubleVector<U> immutable();
944 
945     /**
946      * Check the copyOnWrite flag and, if it is set, make a deep copy of the data and clear the flag.
947      */
948     protected final void checkCopyOnWrite()
949     {
950         if (isCopyOnWrite())
951         {
952             // System.out.println("copyOnWrite is set: Copying data");
953             deepCopyData();
954             setCopyOnWrite(false);
955         }
956     }
957 
958     /** {@inheritDoc} */
959     @Override
960     public final void setSI(final int index, final double valueSI) throws ValueException
961     {
962         checkIndex(index);
963         checkCopyOnWrite();
964         safeSet(index, valueSI);
965     }
966 
967     /** {@inheritDoc} */
968     @Override
969     public final void set(final int index, final DoubleScalar<U> value) throws ValueException
970     {
971         setSI(index, value.getSI());
972     }
973 
974     /** {@inheritDoc} */
975     @Override
976     public final void setInUnit(final int index, final double value, final U valueUnit) throws ValueException
977     {
978         setSI(index, ValueUtil.expressAsSIUnit(value, valueUnit));
979     }
980 
981     /**
982      * Execute a function on a cell by cell basis.
983      * @param d cern.colt.function.tdouble.DoubleFunction; the function to apply
984      */
985     public final void assign(final cern.colt.function.tdouble.DoubleFunction d)
986     {
987         checkCopyOnWrite();
988         getVectorSI().assign(d);
989     }
990 
991     /** {@inheritDoc} */
992     @Override
993     public final MutableDoubleVector<U> multiply(final double constant)
994     {
995         assign(DoubleFunctions.mult(constant));
996         return this;
997     }
998 
999     /** {@inheritDoc} */
1000     @Override
1001     public final MutableDoubleVector<U> divide(final double constant)
1002     {
1003         assign(DoubleFunctions.div(constant));
1004         return this;
1005     }
1006 
1007     /**********************************************************************************/
1008     /******************************* NON-STATIC METHODS *******************************/
1009     /**********************************************************************************/
1010 
1011     /**
1012      * Increment the values in this MutableDoubleVector by the corresponding values in a DoubleVector.
1013      * @param increment DoubleVector&lt;U&gt;; the values by which to increment the corresponding values in this
1014      *            MutableDoubleVector
1015      * @return MutableDoubleVector&lt;U&gt;; this modified MutableDoubleVector
1016      * @throws ValueException when the vectors do not have the same size
1017      */
1018     private MutableDoubleVector<U> incrementValueByValue(final DoubleVector<U> increment) throws ValueException
1019     {
1020         checkSizeAndCopyOnWrite(increment);
1021         for (int index = size(); --index >= 0;)
1022         {
1023             safeSet(index, safeGet(index) + increment.safeGet(index));
1024         }
1025         return this;
1026     }
1027 
1028     /**
1029      * Decrement the values in this MutableDoubleVector by the corresponding values in a DoubleVector.
1030      * @param decrement DoubleVector&lt;U&gt;; the values by which to decrement the corresponding values in this
1031      *            MutableDoubleVector
1032      * @return MutableDoubleVector&lt;U&gt;; this modified MutableDoubleVector
1033      * @throws ValueException when the vectors do not have the same size
1034      */
1035     private MutableDoubleVector<U> decrementValueByValue(final DoubleVector<U> decrement) throws ValueException
1036     {
1037         checkSizeAndCopyOnWrite(decrement);
1038         for (int index = size(); --index >= 0;)
1039         {
1040             safeSet(index, safeGet(index) - decrement.safeGet(index));
1041         }
1042         return this;
1043     }
1044 
1045     /**
1046      * Increment the values in this MutableDoubleVector by the corresponding values in a Relative DoubleVector. <br>
1047      * Only Relative values are allowed; adding an Absolute value to an Absolute value is not allowed. Adding an
1048      * Absolute value to an existing Relative value would require the result to become Absolute, which is a type change
1049      * that is impossible. For that operation use a static method.
1050      * @param rel DoubleVector.Rel&lt;U&gt;; the Relative DoubleVector
1051      * @return MutableDoubleVector&lt;U&gt;; this modified MutableDoubleVector
1052      * @throws ValueException when the vectors do not have the same size
1053      */
1054     protected final MutableDoubleVector<U> incrementByImpl(final DoubleVector.Rel<U> rel) throws ValueException
1055     {
1056         return incrementValueByValue(rel);
1057     }
1058 
1059     /**
1060      * Decrement the corresponding values of this Relative DoubleVector from the values of this MutableDoubleVector. <br>
1061      * Only Relative values are allowed; subtracting an Absolute value from a Relative value is not allowed. Subtracting
1062      * an Absolute value from an existing Absolute value would require the result to become Relative, which is a type
1063      * change that is impossible. For that operation use a static method.
1064      * @param rel DoubleVector.Rel&lt;U&gt;; the Relative DoubleVector
1065      * @return MutableDoubleVector&lt;U&gt;; this modified MutableDoubleVector
1066      * @throws ValueException when the vectors do not have the same size
1067      */
1068     protected final MutableDoubleVector<U> decrementByImpl(final DoubleVector.Rel<U> rel) throws ValueException
1069     {
1070         return decrementValueByValue(rel);
1071     }
1072 
1073     // FIXME It makes no sense to subtract an Absolute from a Relative
1074     /**
1075      * Decrement the values in this Relative MutableDoubleVector by the corresponding values in an Absolute
1076      * DoubleVector.
1077      * @param abs DoubleVector.Abs&lt;U&gt;; the Absolute DoubleVector
1078      * @return MutableDoubleVector.Rel&lt;U&gt;; this modified Relative MutableDoubleVector
1079      * @throws ValueException when the vectors do not have the same size
1080      */
1081     protected final MutableDoubleVector.Rel<U> decrementBy(final DoubleVector.Abs<U> abs) throws ValueException
1082     {
1083         return (MutableDoubleVector.Rel<U>) decrementValueByValue(abs);
1084     }
1085 
1086     /**
1087      * Scale the values in this MutableDoubleVector by the corresponding values in a DoubleVector.
1088      * @param factor DoubleVector&lt;?&gt;; contains the values by which to scale the corresponding values in this
1089      *            MutableDoubleVector
1090      * @throws ValueException when the vectors do not have the same size
1091      */
1092     protected final void scaleValueByValue(final DoubleVector<?> factor) throws ValueException
1093     {
1094         checkSizeAndCopyOnWrite(factor);
1095         for (int index = size(); --index >= 0;)
1096         {
1097             safeSet(index, safeGet(index) * factor.safeGet(index));
1098         }
1099     }
1100 
1101     /**
1102      * Scale the values in this MutableDoubleVector by the corresponding values in a double array.
1103      * @param factor double[]; contains the values by which to scale the corresponding values in this
1104      *            MutableDoubleVector
1105      * @return MutableDoubleVector&lt;U&gt;; this modified MutableDoubleVector
1106      * @throws ValueException when the vector and the array do not have the same size
1107      */
1108     protected final MutableDoubleVector<U> scaleValueByValue(final double[] factor) throws ValueException
1109     {
1110         checkSizeAndCopyOnWrite(factor);
1111         for (int index = size(); --index >= 0;)
1112         {
1113             safeSet(index, safeGet(index) * factor[index]);
1114         }
1115         return this;
1116     }
1117 
1118     /**
1119      * Check sizes and copy the data if the copyOnWrite flag is set.
1120      * @param other DoubleVector&lt;?&gt;; partner for the size check
1121      * @throws ValueException when the vectors do not have the same size
1122      */
1123     private void checkSizeAndCopyOnWrite(final DoubleVector<?> other) throws ValueException
1124     {
1125         checkSize(other);
1126         checkCopyOnWrite();
1127     }
1128 
1129     /**
1130      * Check sizes and copy the data if the copyOnWrite flag is set.
1131      * @param other double[]; partner for the size check
1132      * @throws ValueException when the vectors do not have the same size
1133      */
1134     private void checkSizeAndCopyOnWrite(final double[] other) throws ValueException
1135     {
1136         checkSize(other);
1137         checkCopyOnWrite();
1138     }
1139 
1140 }