Menu

[r976]: / arrayabs.tex  Maximize  Restore  History

Download this file

131 lines (92 with data), 4.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
\section*{Array types}
The array type mechanism of Pascal has been extended to
provide better support for data parallel programming in general,
and SIMD image processing in particular.
Data parallel programming can be built up from certain underlying
abstractions\cite{Ewing}:
\begin{itemize}
\item operations on whole arrays
\item array slicing
\item conditional operations
\item reduction operations
\item scan operations
\item data reorganisation
\end{itemize}
\subsection*{Dynamic Arrays}
A dynamic array is an array whose bounds are determined at run time. Operations
on dynamic arrays are essential in general purpose image processing software since
the size of an image loaded from a file may not be known at compile time.
Pascal 90\cite{ISO90} introduced the notion of schematic or parameterised types
as a means of creating dynamic arrays. Thus where \textbf{r} is some integral
type one can write
\textbf{type z(a,b:r)=array{[}a..b{]} of t;}
If \textbf{p:\textasciicircum{}z}, then
\textbf{new(p,n,m)}
where \textbf{n,m:r} initialises \textbf{p} to point to an array of bounds \textbf{n..m}.
The bounds of the array can then be accessed as \textbf{p\textasciicircum{}.a,
p\textasciicircum{}.b}. Vector Pascal incorporates this notation from Pascal
90 for dynamic arrays
\footnote{
It should be noted that the use of schematic array types preserves the semantic distinction
present in Standard Pascal, between assigning a pointer to an array, and assigining an array itself.
This distinction is confused with the "open array" construct allowed by Delphi and Free Pascal.
}.
\subsection*{Indexed Ranges}
Image processing applications often have to deal with regions of interest, rectangular
sub-images within a larger image. Vector Pascal extends the array abstraction to
define sub-ranges of arrays. A sub-range of an array variable are denoted by the variable followed
by a range expression in brackets.
%\vspace{0.3cm}
%{\centering \begin{tabular}{|c|c|}
%\hline
%<indexed range>&
%<variable> '{[}' <range expression>{[}',' <range expression>{]}{*} '{]}'\\
%\hline
%\end{tabular}\par}
%\vspace{0.3cm}
%\vspace{0.3cm}
%{\centering \begin{tabular}{|c|c|}
%\hline
%<range expression>&
%<expression> '..' <expression>\\
%\hline
%\end{tabular}\par}
%\vspace{0.3cm}
The expressions within the range expression must conform to the index type of
the array variable. The type of a range expression \textbf{a{[}i..j{]}} where
\textbf{a: array{[}p..q{]} of t} is \textbf{array{[}0..j-i{]} of t.}
Examples
\textbf{dataset{[}i..i+2{]}:=blank;}
\textbf{twoDdata{[}2..3,5..6{]}:=twoDdata{[}4..5,11..12{]}{*}0.5;}
Subranges may be passed in as actual parameters to procedures whose corresponding
formal parameters are declared as variables of a schematic type. Hence given
the following declarations:
\textbf{type image(miny,maxy,minx,maxx:integer)=array{[}miny..maxy,minx..maxx{]}
of pixel;}
\textbf{procedure invert(var im:image);begin im:= - im; end;}
\textbf{var screen:array{[}0..319,0..199{]} of pixel;}
then the following statement would be valid:
\textbf{invert(screen{[}40..60,20..30{]});}
An array may be indexed
by another array. If \textbf{x:array{[}t0{]} of t1} and \textbf{y:array{[}t1{]}
of t2}, then \textbf{y{[}x{]}} denotes the virtual array of type \textbf{array{[}t0{]}
of t2} such that \textbf{y{[}x{]}{[}i{]}=y{[}x{[}i{]}{]}}. This construct is
useful for performing permutations.
%To fully understand the following example
%refer to sections \ref{iota},\ref{implicitindices}.
\paragraph{Example}
Given the declarations
\textbf{const perm:array{[}0..3{]} of integer=(3,1,2,0);}
\textbf{var ma,m0:array{[}0..3{]} of integer; }
then the statements
\textbf{m0:= (iota 0)+1;}
%\textbf{write('m0=');for j:=0 to 3 do write(m0{[}j{]});writeln;}
\textbf{ma:=m0{[}perm{]}; }
%\textbf{write('perm=');for j:=0 to 3 do write(perm{[}j{]});writeln; }
%\textbf{writeln('ma:=m0{[}perm{]}');for j:=0 to 3 do write(ma{[}j{]});writeln;}
would set the variables such that
\begin{verbatim}
m0= 1 2 3 4
perm= 3 1 2 0
ma= 4 2 3 1
\end{verbatim}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.