1 package org.djunits.value.vdouble.matrix.base;
2
3 import org.djunits.unit.SIUnit;
4 import org.djunits.unit.Unit;
5 import org.djunits.unit.util.UnitException;
6 import org.djunits.value.Relative;
7 import org.djunits.value.ValueRuntimeException;
8 import org.djunits.value.vdouble.function.DoubleMathFunctions;
9 import org.djunits.value.vdouble.matrix.SIMatrix;
10 import org.djunits.value.vdouble.matrix.data.DoubleMatrixData;
11 import org.djunits.value.vdouble.scalar.base.DoubleScalar;
12 import org.djunits.value.vdouble.scalar.base.DoubleScalarRel;
13 import org.djunits.value.vdouble.vector.base.DoubleVector;
14 import org.djunits.value.vdouble.vector.base.DoubleVectorRel;
15
16
17
18
19
20
21
22
23
24
25
26
27
28 public abstract class DoubleMatrixRel<U extends Unit<U>, S extends DoubleScalarRel<U, S>,
29 RV extends DoubleVectorRel<U, S, RV>, RM extends DoubleMatrixRel<U, S, RV, RM>>
30 extends DoubleMatrix<U, S, RV, RM> implements Relative<U, RM>
31 {
32
33 private static final long serialVersionUID = 20190908L;
34
35
36
37
38
39
40 protected DoubleMatrixRel(final DoubleMatrixData data, final U unit)
41 {
42 super(data.copy(), unit);
43 }
44
45
46
47
48
49 public final S zSum()
50 {
51 return instantiateScalarSI(this.data.zSum(), getDisplayUnit());
52 }
53
54 @Override
55 public final RM plus(final RM rel) throws ValueRuntimeException
56 {
57 return instantiateMatrix(this.getData().plus(rel.getData()), getDisplayUnit());
58 }
59
60 @Override
61 public final RM minus(final RM rel) throws ValueRuntimeException
62 {
63 return instantiateMatrix(this.getData().minus(rel.getData()), getDisplayUnit());
64 }
65
66
67
68
69
70
71
72 @SuppressWarnings("unchecked")
73 public RM incrementBy(final S increment)
74 {
75 checkCopyOnWrite();
76 assign(DoubleMathFunctions.INC(increment.si));
77 return (RM) this;
78 }
79
80
81
82
83
84
85
86
87
88 @SuppressWarnings("unchecked")
89 public RM incrementBy(final RM increment)
90 {
91 checkCopyOnWrite();
92 this.data.incrementBy(increment.getData());
93 return (RM) this;
94 }
95
96
97
98
99
100
101
102 @SuppressWarnings("unchecked")
103 public RM decrementBy(final S decrement)
104 {
105 checkCopyOnWrite();
106 assign(DoubleMathFunctions.DEC(decrement.si));
107 return (RM) this;
108 }
109
110
111
112
113
114
115
116
117
118 @SuppressWarnings("unchecked")
119 public final RM decrementBy(final RM decrement)
120 {
121 checkCopyOnWrite();
122 this.data.decrementBy(decrement.getData());
123 return (RM) this;
124 }
125
126
127
128
129
130
131
132 public RM multiplyBy(final double multiplier)
133 {
134 return assign(DoubleMathFunctions.MULT(multiplier));
135 }
136
137
138
139
140
141
142
143 public RM divideBy(final double divisor)
144 {
145 return assign(DoubleMathFunctions.DIV(divisor));
146 }
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161 public final <UT extends Unit<UT>, ST extends DoubleScalar<UT, ST>, VT extends DoubleVector<UT, ST, VT>,
162 MT extends DoubleMatrix<UT, ST, VT, MT> & Relative<UT, MT>> SIMatrix times(final MT rel)
163 throws ValueRuntimeException, UnitException
164 {
165 return new SIMatrix(this.getData().times(rel.getData()), SIUnit.of(
166 getDisplayUnit().getQuantity().getSiDimensions().plus(rel.getDisplayUnit().getQuantity().getSiDimensions())));
167 }
168
169 @Override
170 public final RM times(final double multiplier)
171 {
172 RM result = clone().mutable();
173 result.assign(DoubleMathFunctions.MULT(multiplier));
174 return result.immutable();
175 }
176
177 @Override
178 public final RM times(final float multiplier)
179 {
180 return times((double) multiplier);
181 }
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196 public final <UT extends Unit<UT>, ST extends DoubleScalar<UT, ST>, VT extends DoubleVector<UT, ST, VT>,
197 MT extends DoubleMatrix<UT, ST, VT, MT> & Relative<UT, MT>> SIMatrix divide(final MT rel)
198 throws ValueRuntimeException, UnitException
199 {
200 return new SIMatrix(this.getData().divide(rel.getData()), SIUnit.of(
201 getDisplayUnit().getQuantity().getSiDimensions().minus(rel.getDisplayUnit().getQuantity().getSiDimensions())));
202 }
203
204 @Override
205 public final RM divide(final float divisor)
206 {
207 return divide((double) divisor);
208 }
209
210 @Override
211 public final RM divide(final double divisor)
212 {
213 RM result = clone().mutable();
214 result.assign(DoubleMathFunctions.DIV(divisor));
215 return result.immutable();
216 }
217
218 }