Skip to content
Snippets Groups Projects

David

Open david.carballo requested to merge david.carballo/poo2019numeric:David into master
4 files
+ 53
35
Compare changes
  • Side-by-side
  • Inline
Files
4
package ch.hepia.numeric;
package ch.hepia.numeric;
import java.util.List;
import java.util.List;
 
import java.util.ArrayList;
import java.util.function.DoubleFunction;
import java.util.function.DoubleFunction;
import java.util.function.Function;
import java.util.function.Function;
final public class Vector {
final public class Vector {
private Vector() {}
 
final private List<Double> lstVector;// = new ArrayList<Double>();
 
 
private Vector() {
 
this.lstVector=new ArrayList<Double>();
 
}
 
private Vector(Double... elements) {
private Vector(Double... elements) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
this.lstVector=new ArrayList<Double>();
 
for(double e:elements)
 
{
 
lstVector.add(e);
 
}
}
}
 
private Vector(List<Double> elements) {
private Vector(List<Double> elements) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
this.lstVector=elements;
}
}
public Transposed t() {
public Transposed t() {
throw new UnsupportedOperationException("This feature isn't implemented yet");
return new Transposed(this);
}
}
public int len() {
public int len() {
throw new UnsupportedOperationException("This feature isn't implemented yet");
return this.lstVector.size();
}
}
public double get(int i) {
public double get(int i) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
return this.lstVector.get(i);
}
}
void set(int i, double value) {
void set(int i, double value) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
this.lstVector.set(i,value);
}
}
public Vector add(Vector that) {
public Vector add(Vector that) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
Vector v = new Vector();
 
for(int i=0;i<this.len();i++)
 
{
 
v.lstVector.add(Double.sum(this.get(i),that.get(i)));
 
}
 
return v;
}
}
public Vector mul(double m) {
public Vector mul(double m) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
Vector v = new Vector();
 
for(double e:this.lstVector)
 
{
 
v.lstVector.add(e*m);
 
}
 
return v;
}
}
public Vector sub(Vector that) {
public Vector sub(Vector that) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
Vector v = new Vector();
 
for(int i=0;i<this.len();i++)
 
{
 
v.lstVector.add(this.get(i)-that.get(i));
 
}
 
return v;
}
}
public double norm() {
public double norm() {
throw new UnsupportedOperationException("This feature isn't implemented yet");
double power=0;
 
for(double e:this.lstVector)
 
{
 
power+=(e*e);
 
}
 
return Math.sqrt(power);
}
}
public Vector sliceFrom(int i) {
public Vector sliceFrom(int i) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
return slice (i,this.len());
}
}
public Vector sliceTo(int i) {
public Vector sliceTo(int i) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
return slice (0,i);
}
}
public Vector slice(int from, int to) {
public Vector slice(int from, int to) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
Vector v =new Vector();
}
if (from>=to){
return v;
public Vector removed(int i) {
}
throw new UnsupportedOperationException("This feature isn't implemented yet");
else
}
{
for (double d : this.lstVector.subList(from,to))
public Vector concat(Vector that) {
{
throw new UnsupportedOperationException("This feature isn't implemented yet");
v.lstVector.add(d);
}
}
return v;
public Vector map(DoubleFunction<Double> f) {
}
throw new UnsupportedOperationException("This feature isn't implemented yet");
}
}
public Vector removed(int i)
public Vector copy() {
{
throw new UnsupportedOperationException("This feature isn't implemented yet");
Vector v = this.copy();
 
v.lstVector.remove(i);
 
return v;
 
}
 
 
public Vector concat(Vector that)
 
{
 
Vector v = Vector.zeros(this.len()+that.len());
 
for(int i=0;i<v.len();i++)
 
{
 
if(i<this.len())
 
{
 
v.set(i,this.get(i));
 
}
 
else
 
{
 
v.set(i,that.get(i-this.len()));
 
}
 
}
 
return v;
 
}
 
 
public Vector map(DoubleFunction<Double> f) {//ne pas faire
 
throw new UnsupportedOperationException("This feature isn't implemented yet");
 
}
 
 
public Vector copy()
 
{
 
Vector v = Vector.zeros(this.len());
 
for(int i=0;i<v.len();i++)
 
{
 
v.set(i,this.get(i));
 
}
 
return v;
}
}
void checkVectorLengthOrThrow(Vector that){
void checkVectorLengthOrThrow(Vector that){
@@ -77,53 +142,100 @@ final public class Vector {
@@ -77,53 +142,100 @@ final public class Vector {
}
}
public static Vector of(Double... elements) {
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) {
public static Vector of(List<Double> elements) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
return new Vector(elements);
}
}
public static Vector empty() {
public static Vector empty() {
throw new UnsupportedOperationException("This feature isn't implemented yet");
return new Vector();
}
}
public static Vector fill(int nb, double value) {
public static Vector fill(int nb, double value) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
Vector v = new Vector();
 
for(int i = 0; i < nb; i++)
 
{
 
v.lstVector.add(value);
 
}
 
return v;
}
}
public static Vector zeros(int nb) {
public static Vector zeros(int nb) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
return Vector.fill(nb,0.0);
}
}
public static Vector ones(int nb) {
public static Vector ones(int nb) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
return Vector.fill(nb,1.0);
}
}
public static Vector linespace(double from, double to, int nb) {
public static Vector linespace(double from, double to, int nb)
throw new UnsupportedOperationException("This feature isn't implemented yet");
{
 
double step=(to-from)/(nb-1);
 
Vector v = Vector.zeros(nb);
 
for(int i=0;i<nb;i++)
 
{
 
v.set(i,from+(step*i));
 
}
 
return v;
}
}
public static Vector tabulate(int nb, Function<Integer, Double> f) {
//ne pas faire
 
public static Vector tabulate(int nb, Function<Integer, Double> f)
 
{
throw new UnsupportedOperationException("This feature isn't implemented yet");
throw new UnsupportedOperationException("This feature isn't implemented yet");
}
}
public static Vector sum(List<Vector> vs) {
public static Vector sum(List<Vector> vs)
throw new UnsupportedOperationException("This feature isn't implemented yet");
{
 
int length=vs.get(0).len();
 
Vector v = Vector.zeros(length);
 
for(int e=0;e<length;e++)
 
{
 
for(Vector vLst:vs)
 
{
 
v.set(e,Double.sum(v.get(e),vLst.get(e)));
 
}
 
}
 
return v;
}
}
public static double norms(List<Vector> vs) {
public static double norms(List<Vector> vs) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
return sum(vs).norm();
}
}
/*
 
Overrides ecrits avant le cours sur le sujet ces fonctions sont
 
a reecrire avec les nouvelles connaisances d'ici le deuxieme tag.
 
*/
@Override
@Override
public String toString() {
public String toString() {
throw new UnsupportedOperationException("This feature isn't implemented yet");
List<String> strings = new ArrayList<String>();
 
for (Double d : this.lstVector) {
 
// Apply formatting to the string if necessary
 
strings.add(d.toString());
 
}
 
return "Vector"+String.valueOf(strings);
}
}
 
@Override
@Override
public boolean equals(Object obj) {
public boolean equals(Object obj) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
if(obj instanceof Vector)
 
{
 
for(int i=0;i<this.len();i++)
 
{
 
if(((Vector)obj).get(i)!=this.get(i))
 
{
 
return false;
 
}
 
}
 
return true;
 
}
 
else
 
{
 
return false;
 
}
}
}
}
}
Loading