/** * Matrix divide * * @param left * @param r * @return */ public static IMatrix div(IMatrix left, double r) { IMatrix g = new GuavaMatrix(); for (Cell<Integer, Integer, Double> l : left.getValueRange()) { int li = l.getRowKey(); int ri = l.getColumnKey(); g.incr(li, ri, (left.get(li, ri) / r)); } return g; }
/** * Matrix divide * * @param left * @param right * @return */ public static IMatrix div(IMatrix left, IMatrix right) { IMatrix g = new GuavaMatrix(); for (Cell<Integer, Integer, Double> l : left.getValueRange()) { for (Cell<Integer, Integer, Double> r : right.getValueRange()) { int li = l.getColumnKey(); int ri = l.getRowKey(); if (li == ri) { double lv = (Double) left.get(li, ri); double rv = (Double) right.get(r.getRowKey(), r.getColumnKey()); // System.out.println(lv+" "+rv+" "+lv*rv); g.incr((Integer) l.getRowKey(), (Integer) r.getColumnKey(), lv / rv); } } } return g; }
/** * Matrix product * * @param left * @param right * @return */ public static IMatrix prod(IMatrix left, IMatrix right) { IMatrix g = new GuavaMatrix(); double size = (left.getValueRange().size() * right.getValueRange().size()); System.out.println(size + " ~~~ "); double i = 0; for (Cell<Integer, Integer, Double> l : left.getValueRange()) { int li = (Integer) l.getColumnKey(); for (Cell<Integer, Integer, Double> r : right.getValueRange()) { int ri = (Integer) r.getRowKey(); if (li == ri) { double lv = (Double) left.get(l.getRowKey(), l.getColumnKey()); double rv = (Double) right.get(r.getRowKey(), r.getColumnKey()); // System.out.println(lv+" "+rv+" "+lv*rv); g.incr((Integer) l.getRowKey(), (Integer) r.getColumnKey(), lv * rv); } i++; // updateProgress((double) i / (double) size); } } System.out.println("Done!"); return g; }