예제 #1
0
 public AMatrix innerProduct(ADiagonalMatrix a) {
   int dims = this.dimensions;
   if (dims != a.dimensions)
     throw new IllegalArgumentException(ErrorMessages.incompatibleShapes(this, a));
   DiagonalMatrix result = DiagonalMatrix.createDimensions(dims);
   for (int i = 0; i < dims; i++) {
     result.data[i] = unsafeGetDiagonalValue(i) * a.unsafeGetDiagonalValue(i);
   }
   return result;
 }
예제 #2
0
 @Override
 public void transformInPlace(AVector v) {
   if (v instanceof AArrayVector) {
     transformInPlace((AArrayVector) v);
     return;
   }
   if (v.length() != dimensions)
     throw new IllegalArgumentException(ErrorMessages.incompatibleShapes(this, v));
   for (int i = 0; i < dimensions; i++) {
     v.unsafeSet(i, v.unsafeGet(i) * unsafeGetDiagonalValue(i));
   }
 }
예제 #3
0
 @Override
 public Matrix innerProduct(Matrix a) {
   if (!(dimensions == a.rowCount()))
     throw new IllegalArgumentException(ErrorMessages.incompatibleShapes(this, a));
   int acc = a.columnCount();
   Matrix m = Matrix.create(dimensions, acc);
   for (int i = 0; i < dimensions; i++) {
     double dv = unsafeGetDiagonalValue(i);
     for (int j = 0; j < acc; j++) {
       m.unsafeSet(i, j, dv * a.unsafeGet(i, j));
     }
   }
   return m;
 }
예제 #4
0
 @Override
 public Matrix transposeInnerProduct(Matrix s) {
   if (s.rowCount() != 1)
     throw new IllegalArgumentException(ErrorMessages.incompatibleShapes(this, s));
   int rc = this.columnCount();
   int cc = s.columnCount();
   Matrix m = Matrix.create(rc, cc);
   for (int i = 0; i < rc; i++) {
     double ti = this.get(i);
     for (int j = 0; j < cc; j++) {
       m.unsafeSet(i, j, ti * s.unsafeGet(0, j));
     }
   }
   return m;
 }