0

I am making a numpy equivalent library like nd4j in java but I want to implement it myself. However, I cannot find any resources online to help my research. I hope to support basic numpy features like randn and shape and dot product

I have made a barebones Matrix class but already encountered a problem. It uses generics to define the Matrix but I have to use the Object class to store the n-dimensional matrix.

public class Matrix<T> {

    Object values;
    int size;

    Matrix() {

    }

    Matrix(int[] shape) {

        size = shape.length;

   }

    Matrix(Object values) {
        this.values = values;

    }

}

The libary should perfrom matrix operation like numpy syntas such as

Matrix<int> m = new Matrix<T>([100,100]);
m=m*m;
m++;
m+=10;
m = m+m;
m = m^2
m = np.dot(m,m)

I will convert the java files to kotlin, as kotlin supports operator overloading

Michał Krzywański
  • 15,659
  • 4
  • 36
  • 63
Clement
  • 128
  • 11
  • why "have to use the Object class"? why not `T`? – Sharon Ben Asher Mar 30 '19 at 10:53
  • this `new Matrix([100,100])` does not compile (in Java) – Sharon Ben Asher Mar 30 '19 at 10:54
  • 1
    You seem to be starting with Java, coming from another language, I suppose. I'd recommend to work through a Java course. When you've come to the part covering generics, you'll surely be able to answer your current question. – Ralf Kleberhoff Mar 30 '19 at 12:50
  • I know I can declare an Type T array like this `T[] array` but I want my class to support arrays of multi dimentions like 1D or 2D or 3D. If I use a declaration like above, the array will have fixed dimentions. – Clement Mar 31 '19 at 12:41

0 Answers0