Changeset 3417 in Sophya
- Timestamp:
- Dec 6, 2007, 7:33:22 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/Manual/sophya.tex
r3415 r3417 49 49 \vspace{1cm} 50 50 \begin{center} 51 {\bf \Large Sophya Version: 2.1 (V\_ Sep2007) }51 {\bf \Large Sophya Version: 2.1 (V\_Nov2007) } 52 52 \end{center} 53 53 \titrebp{1} … … 987 987 \end{verbatim} 988 988 989 \centerline{\bf Warning: } 990 989 {\bf Warning: } 991 990 There is a drawback in this behaviour: only a single 992 991 copy of an array is written to a file, even if the array is modified, 993 without being resized and written to a PPF stream. 992 without being resized and written (dumped) again to the same PPF stream. 993 However, this behavior can be changed using the {\tt RenewObjId()} method, 994 as illustrated below. 994 995 \begin{verbatim} 995 996 { … … 997 998 TArray<int_4> ia(5,3); 998 999 ia = 8; 999 pos << ia; 1000 pos << ia; // (1) 1000 1001 ia = 16; 1001 pos << ia; 1002 pos << ia; // (2) Only a reference to the previously ia array is written 1002 1003 ia = 32; 1003 pos << ia; 1004 ia.RenewObjId(); // We change the object Id 1005 pos << ia; // (3) The complete array is dumped again 1004 1006 } 1005 1007 \end{verbatim} 1006 1008 1007 1009 Only a single copy of the data is effectively written to the output 1008 PPF file, corresponding to the value 8 for array elements. When we 1010 PPF file, corresponding to the value 8 for array elements, for the first two 1011 write operations. When we 1009 1012 read the three array from the file mca.ppf, the same array elements 1010 are obtained three times (all elements equal to 8): 1013 are obtained two times (all elements equal to 8), and a different array is obtained 1014 the third time 1011 1015 \begin{verbatim} 1012 1016 { … … 1049 1053 \end{verbatim} 1050 1054 1055 \subsection{Cast without conversion} 1056 Data conversion between arrays with different data type is handled transparently, 1057 through the copy constructor or the assignment (=) operator . However, in rare cases, 1058 one wants to access the same memory locations, without data type conversion. 1059 The template functions defined in {\tt arrctcast.h} can be used to access the same 1060 memory locations, by arrays with different data types. The SOPHYA/NDataBlock 1061 reference sharing mechanism is effective When using these functions. 1062 Notice that the array size or stride may change during these cast operations. \\ 1063 {\tt arrctcast.h} has been introduced in version V=2.1 (Nov 2007), and has not been 1064 fully tested for non packed arrays. 1065 \begin{verbatim} 1066 // We define and initialize a real array : 1067 TArray<r_4> fa(5); 1068 fa = RegularSequence(1.25,0.5); 1069 cout << " fa= " << fa; 1070 // We construct an integer array from fa, where the floating point values 1071 // are converted to integer values 1072 TArray<uint_2> ia(fa); 1073 cout << " ia= " << ia; 1074 cout << " ia (in hex)= " << hex << ia << dec; 1075 // We can also access the fa memory locations interpreted as short integers 1076 uint_2 ui2; 1077 // Note that sfia size is double the fa size 1078 TArray<uint_2> sfia = ArrayCast(fa, ui2); 1079 cout << " sfia= " << sfia; 1080 cout << " sfia (in hex)= " << hex << sfia << dec; 1081 \end{verbatim} 1082 One of the most useful case of these array type cast without conversion 1083 correspond to accessing the real or imaginary part of a complex array. 1084 Two specific template functions {\tt SDRealPart()} and {\tt SDImagPart()} 1085 are also defined in {\tt arrctcast.h}. Two other functions {\tt ArrCastR2C()} 1086 and {\tt ArrCastC2R() } are also defined for real to complex, and 1087 complex to real cast. 1088 Their usage is shown in the next paragraph on complex arrays. 1051 1089 1052 1090 \subsection{Complex arrays} … … 1059 1097 \item[\bul] Functions returning arrays corresponding to real and imaginary 1060 1098 parts of a complex array: {\tt real(za) , imag(za) } 1061 ({\bf Warning:} Note that the present implementation doesnot provide1099 ({\bf Warning:} Note that the these functions do not provide 1062 1100 shared memory access to real and imaginary parts.) 1063 1101 \item[\bul] Functions returning arrays corresponding to the module, … … 1098 1136 \end{verbatim} 1099 1137 1100 \subsection{Cast without conversion} 1138 \noindent {\bf Shared data access :} It is possible to access a complex array 1139 elements (real and imaginary parts) through the template functions defined 1140 in {\tt arrctcast.h} and discussed above. The example below shows how to use 1141 these functions. 1142 1143 \begin{verbatim} 1144 // We define a complex array 1145 TArray< complex<r_4> > za(5); 1146 cout << " za= " << za; 1147 // And two real arrays, corresponding to the real and imaginary parts 1148 TArray<r_4> rza = SDRealPart(za); 1149 TArray<r_4> iza = SDImagPart(za); 1150 // We initialize the real and imaginary parts of the complex array 1151 rza = RegularSequence(10.,2.); 1152 iza = RegularSequence(5.,0.75); 1153 cout << " rza=..., iza=... ----> za = " << za; 1154 // The complex array seen as a real array (double size) 1155 TArray<r_4> aza = ArrCastC2R(za); 1156 cout << " za --> aza= " << aza; 1157 \end{verbatim} 1101 1158 1102 1159 \subsection{Memory organisation}
Note:
See TracChangeset
for help on using the changeset viewer.