Example #1
0
//************************************************
Arr Arr::transpose(){
    //---------------------------------------------//
    // Transpose a row ordered array, arr,
    // Inputs:
    //     arr: 1d array in column ordered format
    //     nc:  number of columns
    //     nr:  number of rows
    // Returns:
    //     transpose of arr
    //---------------------------------------------//
    Arr RtnArray;
    RtnArray.Init(N,M);
    for (int ii = 0; ii < M; ii++){
        for (int jj = 0; jj <N; jj++){
            RtnArray.push(element(jj,ii),ii,jj);
        }
    }
    return RtnArray;

}
Example #2
0
//************************************************
Arr Arr::cholesky(){
    //---------------------------------------------//
    // Solve cholesky of a square array
    // Inputs: 
    //    S: input array
    //    D: output array. Cholesky of input array. 
    //---------------------------------------------//
    Arr D;
    D.Init(M,N);
    int d = M;
    D.M = M;D.N=N;
    for(int k=0;k<d;++k){
        double sum=0.;
        for(int p=0;p<k;++p)sum+=D.val[k*d+p]*D.val[k*d+p];
        D.val[k*d+k]=sqrt(val[k*d+k]-sum);
        for(int i=k+1;i<d;++i){
           double sum=0.;
           for(int p=0;p<k;++p)sum+=D.val[i*d+p]*D.val[k*d+p];
           D.val[i*d+k]=(val[i*d+k]-sum)/D.val[k*d+k];
        }
    }
    return D;
}
Example #3
0
Arr concatinate(Arr& obj1, Arr& obj2,int dim){
    Arr ArrRtn;
    int M,N;
    //If the concatinate rows
    if (dim == 1){
        M = obj1.M;
        N = obj1.N+obj2.N;
    }else{//concatinate columns
        M = obj1.M+obj2.M;
        N = obj1.N;
    }
    ArrRtn.Init(0.0,M,N);
    //fill using first array
    for (int ii = 0; ii < obj1.N; ii++){
        for (int jj = 0; jj < obj1.M; jj++){
            ArrRtn.push(obj1.element(ii,jj),ii,jj);
        }
    } 
    //---------------------------------------------//
    //       fill using second array
    //---------------------------------------------//
    //concatinate rows
    if (dim == 1){
        for (int ii = obj1.N; ii < N; ii++){
            for (int jj = 0; jj < M; jj++){
                ArrRtn.push(obj2.element(ii-obj1.N,jj),ii,jj);
            }
        } 
    }else{//concatinate columns
        for (int ii = 0; ii < N; ii++){
            for (int jj = obj1.M; jj < M; jj++){
                ArrRtn.push(obj2.element(ii,jj-obj1.M),ii,jj);
            }
        } 
    }
    return ArrRtn;
}