1 package org.djunits.value.vfloat.vector;
2
3 import java.util.stream.IntStream;
4
5 import org.djunits.value.StorageType;
6 import org.djunits.value.ValueException;
7 import org.djunits.value.vfloat.FloatFunction;
8
9
10
11
12
13
14
15
16
17
18
19
20 public class FloatVectorDataDense extends FloatVectorData
21 {
22
23 private static final long serialVersionUID = 1L;
24
25
26
27
28
29 public FloatVectorDataDense(final float[] vectorSI)
30 {
31 super(StorageType.DENSE);
32 this.vectorSI = new float[vectorSI.length];
33 System.arraycopy(vectorSI, 0, this.vectorSI, 0, vectorSI.length);
34 }
35
36
37
38
39 public final void assign(final FloatFunction floatFunction)
40 {
41 IntStream.range(0, size()).parallel().forEach(i -> this.vectorSI[i] = floatFunction.apply(this.vectorSI[i]));
42 }
43
44
45 @Override
46 public final FloatVectorDataSparse toSparse()
47 {
48 return FloatVectorDataSparse.instantiate(this.vectorSI);
49 }
50
51
52 @Override
53 public final int size()
54 {
55 return this.vectorSI.length;
56 }
57
58
59 @Override
60 public final float getSI(final int index)
61 {
62 return this.vectorSI[index];
63 }
64
65
66 @Override
67 public final void setSI(final int index, final float valueSI)
68 {
69 this.vectorSI[index] = valueSI;
70 }
71
72
73 @Override
74 public final float[] getDenseVectorSI()
75 {
76 return this.vectorSI.clone();
77 }
78
79
80 @Override
81 public final FloatVectorDataDense copy()
82 {
83 float[] vCopy = new float[this.vectorSI.length];
84 System.arraycopy(this.vectorSI, 0, vCopy, 0, this.vectorSI.length);
85 return new FloatVectorDataDense(vCopy);
86 }
87
88
89 @Override
90 public final void incrementBy(final FloatVectorData right) throws ValueException
91 {
92 IntStream.range(0, size()).parallel().forEach(i -> this.vectorSI[i] += right.getSI(i));
93 }
94
95
96 @Override
97 public final void decrementBy(final FloatVectorData right) throws ValueException
98 {
99 IntStream.range(0, size()).parallel().forEach(i -> this.vectorSI[i] -= right.getSI(i));
100 }
101
102
103 @Override
104 public final void multiplyBy(final FloatVectorData right) throws ValueException
105 {
106 IntStream.range(0, size()).parallel().forEach(i -> this.vectorSI[i] *= right.getSI(i));
107 }
108
109
110 @Override
111 public final void divideBy(final FloatVectorData right) throws ValueException
112 {
113 IntStream.range(0, size()).parallel().forEach(i -> this.vectorSI[i] /= right.getSI(i));
114 }
115 }