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