Beispiel #1
0
 public T dotProduct(T[] v) {
   T dot = field.getZero();
   for (int i = 0; i < data.length; i++) {
     dot = dot.add(data[i].multiply(v[i]));
   }
   return dot;
 }
Beispiel #2
0
 public T dotProduct(FieldVector<T> v) {
   T dot = field.getZero();
   for (int i = 0; i < data.length; i++) {
     dot = dot.add(data[i].multiply(v.getEntry(i)));
   }
   return dot;
 }
 /**
  * Compute the dot product.
  *
  * @param v vector with which dot product should be computed
  * @return the scalar dot product between instance and v
  * @exception IllegalArgumentException if v is not the same size as this
  */
 public T dotProduct(ArrayFieldVector<T> v) {
   checkVectorDimensions(v.data.length);
   T dot = field.getZero();
   for (int i = 0; i < data.length; i++) {
     dot = dot.add(data[i].multiply(v.data[i]));
   }
   return dot;
 }
 /** {@inheritDoc} */
 public T dotProduct(FieldVector<T> v) {
   try {
     return dotProduct((ArrayFieldVector<T>) v);
   } catch (ClassCastException cce) {
     checkVectorDimensions(v);
     T dot = field.getZero();
     for (int i = 0; i < data.length; i++) {
       dot = dot.add(data[i].multiply(v.getEntry(i)));
     }
     return dot;
   }
 }
 /**
  * Construct a vector of zeroes.
  *
  * @param field Field to which the elements belong.
  * @param size Size of the vector.
  */
 public ArrayFieldVector(Field<T> field, int size) {
   this.field = field;
   data = buildArray(size);
   Arrays.fill(data, field.getZero());
 }