|
1 " |
|
2 COPYRIGHT (c) 2018 by Claus Gittinger |
|
3 All Rights Reserved |
|
4 |
|
5 This software is furnished under a license and may be used |
|
6 only in accordance with the terms of that license and with the |
|
7 inclusion of the above copyright notice. This software may not |
|
8 be provided or otherwise made available to, or used by, any |
|
9 other person. No title to or ownership of the software is |
|
10 hereby transferred. |
|
11 " |
|
12 "{ Package: 'stx:libbasic2' }" |
|
13 |
|
14 "{ NameSpace: Smalltalk }" |
|
15 |
|
16 AbstractNumberVector variableFloatSubclass:#ComplexFloatArray |
|
17 instanceVariableNames:'' |
|
18 classVariableNames:'' |
|
19 poolDictionaries:'' |
|
20 category:'Collections-Arrayed' |
|
21 ! |
|
22 |
|
23 !ComplexFloatArray class methodsFor:'documentation'! |
|
24 |
|
25 copyright |
|
26 " |
|
27 COPYRIGHT (c) 2018 by Claus Gittinger |
|
28 All Rights Reserved |
|
29 |
|
30 This software is furnished under a license and may be used |
|
31 only in accordance with the terms of that license and with the |
|
32 inclusion of the above copyright notice. This software may not |
|
33 be provided or otherwise made available to, or used by, any |
|
34 other person. No title to or ownership of the software is |
|
35 hereby transferred. |
|
36 " |
|
37 ! |
|
38 |
|
39 documentation |
|
40 " |
|
41 ComplexFloatArrays store complex numbers (in single prevision) and nothing else. |
|
42 They have been added to support heavy duty number crunching and |
|
43 data exchange with openGL frameworks and other mass data libraries |
|
44 somewhat better than other smalltalks do. |
|
45 Storing Complex numbers in these objects (instead of Arrays) |
|
46 has some benefits: |
|
47 |
|
48 1) since the values are stored directly (instead of pointers to them) |
|
49 both access overhead and garbage collect overhead is minimized. |
|
50 |
|
51 2) they can be much faster passed to c functions (such as graphics |
|
52 libraries or heavy duty math packages), since the double values |
|
53 come packed and can be used in C by using a (double *) or double[]. |
|
54 There is no need to loop over the array extracting doubles. |
|
55 |
|
56 3) they could (in theory) be much more easily be processed by things like |
|
57 vector and array processors |
|
58 |
|
59 Be aware however, that ComplexFloatArrays are not supported in other |
|
60 smalltalks - your program will thus become somewhat less portable. |
|
61 (since their protocol is the same as normal arrays filled with floats, |
|
62 they can of course be easily simulated - a bit slower though) |
|
63 |
|
64 However, they could be simulated by a ByteArray, using doubleAt: and |
|
65 doubleAtPut: messages to access the elements, but that seems a bit |
|
66 clumsy and unelegant. Also, the stc-compiler may learn how to deal |
|
67 with Float- and DoubleArrays, making accesses very fast in the future. |
|
68 Hint: if you use doubleArrays in your application and must port it |
|
69 to some other smalltalk, define a DoubleArray class there, which is derived |
|
70 from ByteArray, and add access methods. |
|
71 |
|
72 Of course, ComplexFloatArrays can be subclassed, |
|
73 and named instance variables can be added there. |
|
74 |
|
75 [memory requirements:] |
|
76 OBJ-HEADER + (size * float-size * 2) |
|
77 |
|
78 [See also:] |
|
79 ComplexSoubleArray DoubleArray FloatArray Array |
|
80 |
|
81 [author:] |
|
82 Claus Gittinger |
|
83 " |
|
84 ! |
|
85 |
|
86 examples |
|
87 " |
|
88 [exBegin] |
|
89 |vec| |
|
90 |
|
91 vec := ComplexFloatArray new:4. |
|
92 vec size. |
|
93 vec at:1. |
|
94 vec at:2. |
|
95 vec at:3. |
|
96 vec at:4. |
|
97 vec at:1 put:(1 + 4i). |
|
98 vec at:2 put:(2 + 4i). |
|
99 vec at:4 put:(4 + 4i). |
|
100 vec |
|
101 [exEnd] |
|
102 " |
|
103 ! ! |
|
104 |
|
105 !ComplexFloatArray class methodsFor:'instance creation'! |
|
106 |
|
107 new:size |
|
108 ^ super new:(size * 2) |
|
109 ! ! |
|
110 |
|
111 !ComplexFloatArray class methodsFor:'queries'! |
|
112 |
|
113 elementByteSize |
|
114 "for bit-like containers, return the number of bytes stored per element. |
|
115 Here, 2*4 is returned" |
|
116 |
|
117 ^ 8 |
|
118 ! ! |
|
119 |
|
120 !ComplexFloatArray methodsFor:'accessing'! |
|
121 |
|
122 at:index |
|
123 |baseIdx| |
|
124 |
|
125 baseIdx := index * 2. |
|
126 ^ Complex basicNew |
|
127 setReal:(self basicAt:(baseIdx - 1)) |
|
128 setImaginary:(self basicAt:(baseIdx)) |
|
129 ! |
|
130 |
|
131 at:index put:aComplex |
|
132 |baseIdx| |
|
133 |
|
134 baseIdx := index * 2. |
|
135 self basicAt:(baseIdx - 1) put:aComplex real. |
|
136 self basicAt:(baseIdx) put:aComplex imaginary. |
|
137 ! ! |
|
138 |
|
139 !ComplexFloatArray methodsFor:'queries'! |
|
140 |
|
141 defaultElement |
|
142 ^ Complex zero |
|
143 ! |
|
144 |
|
145 isValidElement:anObject |
|
146 "return true, if I can hold this kind of object" |
|
147 |
|
148 ^ anObject isNumber |
|
149 ! |
|
150 |
|
151 size |
|
152 ^ super size // 2 |
|
153 ! ! |
|
154 |
|
155 !ComplexFloatArray class methodsFor:'documentation'! |
|
156 |
|
157 version |
|
158 ^ '$Header$' |
|
159 ! |
|
160 |
|
161 version_CVS |
|
162 ^ '$Header$' |
|
163 ! ! |
|
164 |