コード例 #1
0
void strassen_mm(
    const unsigned int m,
    const unsigned int n,
    const unsigned int k,
    const Dtype *A, const int incRowA,
    const Dtype *B, const int incRowB,
    Dtype *C, const int incRowC){

    int max_length = maxThree(m, n, k);
    int new_length = getNumberLargerThanXAndIsPowerOfTwo(max_length);
    Dtype* newA = pad_matrix(A, m, k, incRowA, new_length, new_length);
    Dtype* newB = pad_matrix(B, k, n, incRowB, new_length, new_length);
    Dtype* newC = pad_matrix(C, m, n, incRowC, new_length, new_length);

    strassen_mm_worker(
        new_length, new_length, new_length,
        newA, new_length,
        newB, new_length,
        newC, new_length);

    matrix_copyTo(newC, new_length, new_length, new_length,
                  C, m, n, incRowC);

    // remove the extra workspace
    remove_matrix(newA);
    remove_matrix(newB);
    remove_matrix(newC);
}
コード例 #2
0
 int maxProduct(int A[], int n) {
     if (!A) {
         return 0;
     }
     int lMinPrev = 1;
     int lMaxPrev = 1;
     int lMax = INT_MIN;
     int curProduct = 1;
     for (int i = 0; i< n; ++i) {
         
         curProduct  = maxThree(lMinPrev*A[i], lMaxPrev*A[i], A[i]);
         lMinPrev = minThree(lMinPrev*A[i], lMaxPrev*A[i], A[i]);
         lMaxPrev = curProduct;
         
         if (curProduct > lMax) {
             lMax = curProduct;
         }
     }
     
     return lMax;
 }