Skip to content
Snippets Groups Projects

Update Vector.java

Open dylan.mpacko requested to merge dylan.mpacko/poo2019numeric:patch-1 into master
1 file
+ 100
24
Compare changes
  • Side-by-side
  • Inline
package ch.hepia.numeric;
import java.util.List;
import java.util.ArrayList;
import java.util.function.DoubleFunction;
import java.util.function.Function;
final public class Vector {
private List<Double> values;
private Vector() {}
private Vector(Double... elements) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
List<Double> vec = new ArrayList<>();
for (double elem : elements){vec.add(elem);}
this.values = vec;
}
private Vector(List<Double> elements) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
this.values = elements;
}
public Transposed t() {
throw new UnsupportedOperationException("This feature isn't implemented yet");
//return new Transposed(this);
throw new UnsupportedOperationException("This feature isn't implemented yet");
}
public List<Double> getValues(){
return this.values;
}
public int len() {
throw new UnsupportedOperationException("This feature isn't implemented yet");
return this.getValues().size();
}
public double get(int i) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
return this.getValues().get(i);
}
void set(int i, double value) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
this.values.set(i, value);
}
public Vector add(Vector that) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
List<Double> newVec = new ArrayList<>();
for(int i=0; i < this.len();i++){
newVec.add(this.get(i)+that.get(i));
}
this.values = newVec;
return new Vector(newVec);
}
public Vector mul(double m) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
List<Double> vec = new ArrayList<>();
for (double elem : this.getValues()){vec.add(elem);}
this.values = vec;
return new Vector(vec);
}
public Vector sub(Vector that) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
List<Double> vec = new ArrayList<>();
this.add(that.mul(-1.0));
vec = this.getValues();
this.values = vec;
return new Vector(vec);
}
public double norm() {
throw new UnsupportedOperationException("This feature isn't implemented yet");
double res=0;
for(int i = 0; i<this.len();i++)
{
res+= (this.get(i)*this.get(i));
}
return res;
}
public Vector sliceFrom(int i) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
List<Double> vec = new ArrayList<>();
for(int inc = 0; inc < this.len(); inc ++){
if(inc >= i){
vec.add(this.get(inc));
}
}
return new Vector(vec);
}
public Vector sliceTo(int i) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
List<Double> vec = new ArrayList<>();
for(int inc= 0; inc < i ;inc ++){
vec.add(this.get(inc));
}
return new Vector(vec);
}
public Vector slice(int from, int to) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
List<Double> vec = new ArrayList<>();
for(int i= from; i < to ;i ++){
vec.add(this.get(i));
}
return new Vector(vec);
}
public Vector removed(int i) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
List<Double> Vec = new ArrayList<>();
for(int inc=0; inc < this.len();inc++){
if (inc != i){
Vec.add(this.get(i));
}
}
return new Vector(Vec);
}
public Vector concat(Vector that) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
List<Double> Vec = new ArrayList<>();
for(int i=0; i < this.len();i++){
Vec.add(this.get(i));
}
for(int y=0; y < that.len();y++){
Vec.add(that.get(y));
}
return new Vector(Vec);
}
public Vector map(DoubleFunction<Double> f) {
@@ -69,7 +127,11 @@ final public class Vector {
}
public Vector copy() {
throw new UnsupportedOperationException("This feature isn't implemented yet");
List<Double> Vec = new ArrayList<>();
for(int i=0; i < this.len();i++){
Vec.add(this.get(i));
}
return new Vector(Vec);
}
void checkVectorLengthOrThrow(Vector that){
@@ -77,27 +139,41 @@ final public class Vector {
}
public static Vector of(Double... elements) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
return new Vector(elements);
}
public static Vector of(List<Double> elements) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
return new Vector(elements);
}
public static Vector empty() {
throw new UnsupportedOperationException("This feature isn't implemented yet");
List<Double> vec = new ArrayList<>();
return new Vector(vec);
}
public static Vector fill(int nb, double value) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
List<Double> Vec = new ArrayList<>();
for(int i=0; i <= nb ;i++){
Vec.add(value);
}
return new Vector(Vec);
}
public static Vector zeros(int nb) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
List<Double> Vec = new ArrayList<>();
for(int i=0; i <= nb ;i++){
Vec.add(0.0);
}
return new Vector(Vec);
}
public static Vector ones(int nb) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
List<Double> Vec = new ArrayList<>();
for(int i=0; i <= nb ;i++){
Vec.add(1.0);
}
return new Vector(Vec);
}
public static Vector linespace(double from, double to, int nb) {
@@ -126,4 +202,4 @@ final public class Vector {
public boolean equals(Object obj) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
}
}
}
\ No newline at end of file
Loading