Beispiel #1
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;
 }
Beispiel #2
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;
 }
 /** {@inheritDoc} */
 public FieldVector<T> mapInvToSelf() {
   final T one = field.getOne();
   for (int i = 0; i < data.length; i++) {
     data[i] = one.divide(data[i]);
   }
   return this;
 }
 /**
  * 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 FieldVector<T> mapInv() {
   T[] out = buildArray(data.length);
   final T one = field.getOne();
   for (int i = 0; i < data.length; i++) {
     out[i] = one.divide(data[i]);
   }
   return new ArrayFieldVector<T>(field, out, false);
 }
 /** {@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;
   }
 }
Beispiel #7
0
 /**
  * Build an array of elements.
  *
  * @param length size of the array to build
  * @return a new array
  */
 @SuppressWarnings("unchecked") // field is of type T
 private T[] buildArray(final int length) {
   return (T[]) Array.newInstance(field.getRuntimeClass(), length);
 }
 /**
  * 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());
 }