View Javadoc
1   package org.djunits.value.vdouble.matrix;
2   
3   import org.djunits.unit.AbsoluteLinearUnit;
4   import org.djunits.unit.Unit;
5   import org.djunits.value.StorageType;
6   import org.djunits.value.ValueException;
7   import org.djunits.value.vdouble.scalar.DoubleScalar;
8   
9   /**
10   * Immutable DoubleMatrix.
11   * <p>
12   * This file was generated by the djunits value classes generator, 26 jun, 2015
13   * <p>
14   * Copyright (c) 2015-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
16   * <p>
17   * $LastChangedDate: 2018-01-28 03:17:44 +0100 (Sun, 28 Jan 2018) $, @version $Revision: 256 $, by $Author: averbraeck $,
18   * initial version 26 jun, 2015 <br>
19   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
21   */
22  public abstract class DoubleMatrix
23  {
24      /**
25       * ABSOLUTE implementation of DoubleMatrix.
26       * @param <AU> Absolute unit
27       * @param <RU> Relative unit
28       */
29      public static class Abs<AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>> extends AbstractDoubleMatrixAbs<AU, RU,
30              DoubleMatrix.Abs<AU, RU>, DoubleMatrix.Rel<RU>, MutableDoubleMatrix.Abs<AU, RU>, DoubleScalar.Abs<AU, RU>>
31      {
32          /**  */
33          private static final long serialVersionUID = 20151003L;
34  
35          /**
36           * Construct a new Absolute Immutable DoubleMatrix.
37           * @param values double[][]; the values of the entries in the new Absolute Immutable DoubleMatrix
38           * @param unit AU; the unit of the new Absolute Immutable DoubleMatrix
39           * @param storageType the data type to use (e.g., DENSE or SPARSE)
40           * @throws ValueException when values is null
41           */
42          public Abs(final double[][] values, final AU unit, final StorageType storageType) throws ValueException
43          {
44              super(values, unit, storageType);
45          }
46  
47          /**
48           * Construct a new Absolute Immutable DoubleMatrix.
49           * @param values DoubleScalar.Abs&lt;U&gt;[][]; the values of the entries in the new Absolute Immutable DoubleMatrix
50           * @param storageType the data type to use (e.g., DENSE or SPARSE)
51           * @throws ValueException when values has zero entries
52           */
53          public Abs(final DoubleScalar.Abs<AU, RU>[][] values, final StorageType storageType) throws ValueException
54          {
55              super(values, storageType);
56          }
57  
58          /**
59           * Construct a new Absolute Immutable DoubleMatrix.
60           * @param data an internal data object
61           * @param unit the unit
62           */
63          Abs(final DoubleMatrixData data, final AU unit)
64          {
65              super(data, unit);
66          }
67  
68          /** {@inheritDoc} */
69          @Override
70          @SuppressWarnings("designforextension")
71          public DoubleMatrix.Abs<AU, RU> toDense()
72          {
73              return this.data.isDense() ? this : instantiateTypeAbs(this.data.toDense(), getUnit());
74          }
75  
76          /** {@inheritDoc} */
77          @Override
78          @SuppressWarnings("designforextension")
79          public DoubleMatrix.Abs<AU, RU> toSparse()
80          {
81              return this.data.isSparse() ? this : instantiateTypeAbs(this.data.toSparse(), getUnit());
82          }
83  
84          /** {@inheritDoc} */
85          @Override
86          protected final DoubleMatrix.Abs<AU, RU> instantiateTypeAbs(final DoubleMatrixData dmd, final AU unit)
87          {
88              return new DoubleMatrix.Abs<AU, RU>(dmd, unit);
89          }
90  
91          /** {@inheritDoc} */
92          @Override
93          protected final DoubleMatrix.Rel<RU> instantiateTypeRel(final DoubleMatrixData dmd, final RU unit)
94          {
95              return new DoubleMatrix.Rel<RU>(dmd, unit);
96          }
97  
98          /** {@inheritDoc} */
99          @Override
100         protected final MutableDoubleMatrix.Abs<AU, RU> instantiateMutableType(final DoubleMatrixData dmd, final AU unit)
101         {
102             return new MutableDoubleMatrix.Abs<AU, RU>(dmd, unit);
103         }
104 
105         /** {@inheritDoc} */
106         @Override
107         protected final DoubleScalar.Abs<AU, RU> instantiateScalar(final double value, final AU unit)
108         {
109             return new DoubleScalar.Abs<AU, RU>(value, unit);
110         }
111     }
112 
113     /**
114      * RELATIVE implementation of DoubleMatrix.
115      * @param <U> Unit the unit for which this Matrix will be created
116      */
117     public static class Rel<U extends Unit<U>>
118             extends AbstractDoubleMatrixRel<U, DoubleMatrix.Rel<U>, MutableDoubleMatrix.Rel<U>, DoubleScalar.Rel<U>>
119 
120     {
121         /** */
122         private static final long serialVersionUID = 20151003L;
123 
124         /**
125          * Construct a new Relative Immutable DoubleMatrix.
126          * @param values double[][]; the values of the entries in the new Relative Immutable DoubleMatrix
127          * @param unit U; the unit of the new Relative Immutable DoubleMatrix
128          * @param storageType the data type to use (e.g., DENSE or SPARSE)
129          * @throws ValueException when values is null
130          */
131         public Rel(final double[][] values, final U unit, final StorageType storageType) throws ValueException
132         {
133             super(values, unit, storageType);
134         }
135 
136         /**
137          * Construct a new Relative Immutable DoubleMatrix.
138          * @param values DoubleScalar.Abs&lt;U&gt;[][]; the values of the entries in the new Relative Immutable DoubleMatrix
139          * @param storageType the data type to use (e.g., DENSE or SPARSE)
140          * @throws ValueException when values has zero entries
141          */
142         public Rel(final DoubleScalar.Rel<U>[][] values, final StorageType storageType) throws ValueException
143         {
144             super(values, storageType);
145         }
146 
147         /**
148          * Construct a new Relative Immutable DoubleMatrix.
149          * @param data an internal data object
150          * @param unit the unit
151          */
152         Rel(final DoubleMatrixData data, final U unit)
153         {
154             super(data, unit);
155         }
156 
157         /** {@inheritDoc} */
158         @Override
159         @SuppressWarnings("designforextension")
160         public DoubleMatrix.Rel<U> toDense()
161         {
162             return this.data.isDense() ? this : instantiateType(this.data.toDense(), getUnit());
163         }
164 
165         /** {@inheritDoc} */
166         @Override
167         @SuppressWarnings("designforextension")
168         public DoubleMatrix.Rel<U> toSparse()
169         {
170             return this.data.isSparse() ? this : instantiateType(this.data.toSparse(), getUnit());
171         }
172 
173         /** {@inheritDoc} */
174         @Override
175         protected final DoubleMatrix.Rel<U> instantiateType(final DoubleMatrixData dmd, final U unit)
176         {
177             return new DoubleMatrix.Rel<U>(dmd, unit);
178         }
179 
180         /** {@inheritDoc} */
181         @Override
182         protected final MutableDoubleMatrix.Rel<U> instantiateMutableType(final DoubleMatrixData dmd, final U unit)
183         {
184             return new MutableDoubleMatrix.Rel<U>(dmd, unit);
185         }
186 
187         /** {@inheritDoc} */
188         @Override
189         protected final DoubleScalar.Rel<U> instantiateScalar(final double value, final U unit)
190         {
191             return new DoubleScalar.Rel<U>(value, unit);
192         }
193     }
194 
195     /* ============================================================================================ */
196     /* =========================== STATIC CALCULATION MATRIX METHODS ============================== */
197     /* ============================================================================================ */
198 
199     /**
200      * Add the content of two matrices with a static method on a cell-by-cell basis; Abs + Rel = Abs.
201      * @param left the first matrix
202      * @param right the second matrix
203      * @param <AU> the absolute unit
204      * @param <RU> the corresponding relative unit
205      * @return the sum of the two matrices
206      * @throws ValueException when the two matrices have unequal size, or when one of the matrices is null or not well-formed
207      */
208     static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>> DoubleMatrix.Abs<AU, RU> plus(
209             final DoubleMatrix.Abs<AU, RU> left, final DoubleMatrix.Rel<RU> right) throws ValueException
210     {
211         return left.mutable().plus(right);
212     }
213 
214     /**
215      * Add the content of two matrices with a static method on a cell-by-cell basis; Rel + Rel = Rel.
216      * @param left the first matrix
217      * @param right the second matrix
218      * @param <U> the relative unit
219      * @return the sum of the two matrices
220      * @throws ValueException when the two matrices have unequal size, or when one of the matrices is null or not well-formed
221      */
222     static <U extends Unit<U>> DoubleMatrix.Rel<U> plus(final DoubleMatrix.Rel<U> left, final DoubleMatrix.Rel<U> right)
223             throws ValueException
224     {
225         return left.mutable().plus(right);
226     }
227 
228     /**
229      * Subtract the content of two matrices with a static method on a cell-by-cell basis; Abs - Rel = Abs.
230      * @param left the first matrix
231      * @param right the second matrix
232      * @param <AU> the absolute unit
233      * @param <RU> the corresponding relative unit
234      * @return the difference of the two matrices
235      * @throws ValueException when the two matrices have unequal size, or when one of the matrices is null or not well-formed
236      */
237     static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>> DoubleMatrix.Abs<AU, RU> minus(
238             final DoubleMatrix.Abs<AU, RU> left, final DoubleMatrix.Rel<RU> right) throws ValueException
239     {
240         return left.mutable().minus(right);
241     }
242 
243     /**
244      * Subtract the content of two matrices with a static method on a cell-by-cell basis; Abs - Abs = Rel.
245      * @param left the first matrix
246      * @param right the second matrix
247      * @param <AU> the absolute unit
248      * @param <RU> the corresponding relative unit
249      * @return the difference of the two matrices
250      * @throws ValueException when the two matrices have unequal size, or when one of the matrices is null or not well-formed
251      */
252     static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>> DoubleMatrix.Rel<RU> minus(
253             final DoubleMatrix.Abs<AU, RU> left, final DoubleMatrix.Abs<AU, RU> right) throws ValueException
254     {
255         return left.mutable().minus(right);
256     }
257 
258     /**
259      * Subtract the content of two matrices with a static method on a cell-by-cell basis; Rel - Rel = Rel.
260      * @param left the first matrix
261      * @param right the second matrix
262      * @param <U> the unit
263      * @return the difference of the two matrices
264      * @throws ValueException when the two matrices have unequal size, or when one of the matrices is null or not well-formed
265      */
266     static <U extends Unit<U>> DoubleMatrix.Rel<U> minus(final DoubleMatrix.Rel<U> left, final DoubleMatrix.Rel<U> right)
267             throws ValueException
268     {
269         return left.mutable().minus(right);
270     }
271 
272     /**
273      * Multiply the content of two matrices with a static method on a cell-by-cell basis; Rel * Rel = Rel. The unit is not
274      * changed by this method.
275      * @param left the first matrix
276      * @param right the second matrix
277      * @param <U> the unit
278      * @return the cell-by-cell multiplication of the two matrices
279      * @throws ValueException when the two matrices have unequal size, or when one of the matrices is null or not well-formed
280      */
281     static <U extends Unit<U>> DoubleMatrix.Rel<U> times(final DoubleMatrix.Rel<U> left, final DoubleMatrix.Rel<U> right)
282             throws ValueException
283     {
284         return left.mutable().times(right);
285     }
286 
287     /**
288      * Divide the content of two matrices with a static method on a cell-by-cell basis; Rel / Rel = Rel. The unit is not changed
289      * by this method.
290      * @param left the first matrix
291      * @param right the second matrix
292      * @param <U> the unit
293      * @return the cell-by-cell division of the two matrices
294      * @throws ValueException when the two matrices have unequal size, or when one of the matrices is null or not well-formed
295      */
296     static <U extends Unit<U>> DoubleMatrix.Rel<U> divide(final DoubleMatrix.Rel<U> left, final DoubleMatrix.Rel<U> right)
297             throws ValueException
298     {
299         return left.mutable().divide(right);
300     }
301 
302 }