package jaolho.data.lma.implementations;

import java.util.Arrays;
import flanagan.math.Matrix;

// KEEP THE .txt SUFFIX FOR THIS FILE IF YOU DONT WANT TO USE FLANAGAN MATRIX CLASSES
public class FlanaganMatrix extends Matrix implements LMAMatrix {
	
	public FlanaganMatrix(int rows, int cols) {
		super(rows, cols);
	}
	
	public FlanaganMatrix(double[][] elements) {
		super(elements);
	}

	public void invert() {
		Matrix inv = this.inverse();
		this.setTwoDarray(inv.getArrayPointer());
	}

	public void setElement(int row, int col, double value) {
		super.setElement(row, col, value);
	}

	public double getElement(int row, int col) {
		return this.getElementCopy(row, col);
	}

	public void multiply(double[] vector, double[] result) {
		for (int i = 0; i < this.getNrow(); i++) {
			result[i] = 0;
			for (int j = 0; j < this.getNcol(); j++) {
				 result[i] += this.getElement(i, j) * vector[j];
			}
		}
	}
	
	public static void main(String[] args) {
		FlanaganMatrix f = new FlanaganMatrix(new double[][] {{12, 32, 2}, {72, 18, 6}, {22, 15, 6}});
		double[] a = {7, 8, 2};
		double[] b = {0, 0, 0};
		f.multiply(a, b);
		System.out.println(Arrays.toString(b));
		f.invert();
		a[0] = 0;
		a[1] = 0;
		f.multiply(b, a);
		System.out.println(Arrays.toString(a));
		f.invert();
		b[0] = 0;
		b[1] = 0;
		f.multiply(a, b);
		System.out.println(Arrays.toString(b));
	}
}
