Skip to content

Commit

Permalink
Fix formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
johncbowman committed Sep 1, 2020
1 parent 24b74e9 commit 6bae061
Show file tree
Hide file tree
Showing 52 changed files with 1,422 additions and 1,422 deletions.
36 changes: 18 additions & 18 deletions Array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,67 +25,67 @@ int main()
{
array3<double> A(n,m,p);
double sum=0.0;

// Sequential access:
int size=A.Size();
for(int i=0; i < size; i++) A(i)=i;

// Random access:
for(int i=0; i < n; i++) {

// The following statements are equivalent, but the first one optimizes better.
array2<double> Ai=A[i];
// array2<double> Ai(m,p); Ai=A[i]; // This does an extra memory copy.

for(int j=0; j < m; j++) {
// array1<double> Aij=Ai[j];
// For 1D arrays: many compilers optimize array1<>::opt better than array1<>.
vector Aij=Ai[j];

for(int k=0; k < p; k++) {
// The following statements are equivalent, but the first one optimizes better.
sum=sum+Aij[k];
// sum=sum+A(i,j,k); // This does extra index multiplication.
}
}
}

cout << sum << endl;
f(A);
g(A);

f(A);
g(A);

vector x;
Allocate(x,1);
x[0]=1.0;
cout << h<double>(x) << endl;

cout << endl;

// Arrays with offsets:

const int offx=-1;
const int offy=-1;

Array1<double> B(n,offx); // B(offx)...B(n-1+offx)
Array2<double> C(n,m,offx,offy);
Array1<double> D(5); // Functionally equivalent to array1<double> D(n);

B=1.0;
C=2.0;
D=3.0;

for(int i=offx; i < n+offx; i++) cout << B[i] << endl;

cout << endl;

for(int i=offx; i < n+offx; i++) {
Vector Ci=C[i];
for(int j=offy; j < m+offy; j++)
for(int j=offy; j < m+offy; j++)
cout << Ci[j] << endl;
}

cout << D << endl;

return 0;
}
Loading

0 comments on commit 6bae061

Please sign in to comment.