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