PHP를 사용하여 strassen 행렬 알고리즘을 준비 중입니다. 내가 봤 거든 파이썬, 자바, 같은 다른 언어로 비슷한 프로젝트를 발견 ... 내 생각에 자바는 PHP와 가장 유사하기 때문에, 나는 PHP로 자바 코드를 설정하기로 결정했습니다. 다음 부분을 제외하고 전체 Java 코드를 PHP로 변환했습니다. 나는 <
과 >>
기호의 의미와이 코드에서 무엇을하는지 이해하지 못합니다. 아이디어가 있으십니까?Java ArrayList for PHP
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;
}
당신은 자바에서 ArrayList
클래스에 이러한 ArrayList있는 원래의 코드 here
그것은 Arraylist의 Arraylist뿐입니다. –
ArrayList>을 의미합니까? http://en.wikipedia.org/wiki/Generics_in_Java –
Vartlok
'ArrayList>'는 단순히 ArrayList가 정수를 보유하는 ArrayList를 보유한다고 말합니다. PHP는 배열과 객체에 대한 타입 힌트만을 지원하므로 메소드의 서명에서 배열을 타입 힌트로 사용할 수 있다고 생각합니다. 그리고 그 코드는 PHP에서 타입 힌트와 같은 종류의 2D 배열 일뿐입니다. –
teeyo