0

I'm preparing a strassen matrix algorithm using PHP. I've googled and found some similar projects in other languages like python, java ,... Since in my opinion Java is most similar to PHP, I decided to turn the Java code to PHP. I turned the whole java code to PHP except the following part. I don't understand the meaning of < and >> symbols and what they do in this code. Any Idea?

public static int[][] strassen(ArrayList<ArrayList<Integer>> A,
        ArrayList<ArrayList<Integer>> B) {
    // Make the matrices bigger so that you can apply the strassen
    // algorithm recursively without having to deal with odd
    // matrix sizes
    int n = A.size();
    int m = nextPowerOfTwo(n);
    int[][] APrep = new int[m][m];
    int[][] BPrep = new int[m][m];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            APrep[i][j] = A.get(i).get(j);
            BPrep[i][j] = B.get(i).get(j);
        }
    }

    int[][] CPrep = strassenR(APrep, BPrep);
    int[][] C = new int[n][n];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            C[i][j] = CPrep[i][j];
        }
    }
    return C;
}

you can see the original code here

3
  • it is nothing but Arraylist of Arraylists. Commented Dec 24, 2014 at 13:16
  • Do you mean ArrayList<ArrayList<Integer>>? en.wikipedia.org/wiki/Generics_in_Java Commented Dec 24, 2014 at 13:16
  • ArrayList<ArrayList<Integer>> simply says that an ArrayList will hold an ArrayList that holds integers. PHP only supports type hints for arrays and object so I think you can use array as type hint in the method's signature. And keeps in mind that that code is nothing but a 2D array with kind of types hint in PHP. Commented Dec 24, 2014 at 13:19

1 Answer 1

1

These are ArrayList, and the closest PHP likeness to the ArrayList class from Java is the ArrayObject class. The method names are different, but the functionality between the two is fairly close.

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry but I'm new in PHP too. May you turn this part to PHP for me? strassen(ArrayList<ArrayList<Integer>> A, ArrayList<ArrayList<Integer>> B)
We are here to help you not to do your job, I am Sorry.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.