author | Claus Gittinger <cg@exept.de> |
Mon, 16 Dec 2019 16:00:23 +0100 | |
changeset 25135 | 98f799af1e48 |
parent 23969 | f77a2da0552f |
permissions | -rw-r--r-- |
13824 | 1 |
" |
2 |
COPYRIGHT (c) 2011 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:libbasic' }" |
|
13 |
||
19029 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
14026 | 16 |
UninterpretedBytes subclass:#AbstractNumberVector |
13824 | 17 |
instanceVariableNames:'' |
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Collections-Arrayed' |
|
21 |
! |
|
22 |
||
23 |
!AbstractNumberVector class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 2011 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 |
abstract superclass for all direct storing number vector classes |
|
42 |
(float, double, integer arrays) |
|
43 |
||
44 |
Mostly to share double dispatch code. |
|
20627 | 45 |
|
46 |
[see also:] |
|
47 |
IntegerArray FloatArray DoubleArray |
|
48 |
ByteArray |
|
49 |
(and many others) |
|
13824 | 50 |
" |
51 |
! ! |
|
52 |
||
23808 | 53 |
!AbstractNumberVector class methodsFor:'queries'! |
54 |
||
23969 | 55 |
isAbstract |
56 |
"Return if this class is an abstract class. |
|
57 |
True is returned here for myself only; false for subclasses. |
|
58 |
Abstract subclasses must redefine this again." |
|
59 |
||
60 |
^ self == AbstractNumberVector. |
|
61 |
! |
|
62 |
||
23808 | 63 |
maxVal |
64 |
"the maximum value which can be stored in instances of me" |
|
65 |
||
66 |
^ self subclassResponsibility. |
|
67 |
! |
|
68 |
||
69 |
minVal |
|
70 |
"the minimum value which can be stored in instances of me" |
|
71 |
||
72 |
^ self subclassResponsibility. |
|
73 |
! ! |
|
74 |
||
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
75 |
!AbstractNumberVector methodsFor:'arithmetic'! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
76 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
77 |
* anObject |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
78 |
"return the product of the receiver and the argument. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
79 |
The argument may either be a scalar or another vector" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
80 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
81 |
^ self clone *= anObject |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
82 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
83 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
84 |
#(1 2 3 4) asFloatArray * 3 |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
85 |
#(1 2 3 4) asFloatArray * #(1 2 3 4) asFloatArray |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
86 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
87 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
88 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
89 |
+ anObject |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
90 |
"return the sum of the receiver and the argument. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
91 |
The argument may either be a scalar or another vector" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
92 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
93 |
^ self clone += anObject |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
94 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
95 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
96 |
#(1 2 3 4) asFloatArray + 3 |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
97 |
#(1 2 3 4) asFloatArray + #(1 2 3 4) asFloatArray |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
98 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
99 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
100 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
101 |
- anObject |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
102 |
"return the difference of the receiver and the argument. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
103 |
The argument may either be a scalar or another vector" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
104 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
105 |
^ self clone -= anObject |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
106 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
107 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
108 |
#(1 2 3 4) asFloatArray - 3 |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
109 |
#(1 2 3 4) asFloatArray - #(1 2 3 4) asFloatArray |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
110 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
111 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
112 |
"Created: / 30-05-2007 / 17:41:46 / cg" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
113 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
114 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
115 |
/ anObject |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
116 |
"return the division of the receiver and the argument. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
117 |
The argument may either be a scalar or another vector" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
118 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
119 |
^ self clone /= anObject |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
120 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
121 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
122 |
#(1 2 3 4) asFloatArray / 3 |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
123 |
#(1 2 3 4) asFloatArray / #(1 2 3 4) asFloatArray |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
124 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
125 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
126 |
"Created: / 30-05-2007 / 17:46:05 / cg" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
127 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
128 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
129 |
abs |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
130 |
"return a new vector containing absolute values. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
131 |
The receiver is unchanged" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
132 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
133 |
^ self clone primAbs |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
134 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
135 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
136 |
#( -1 2 -3 4 -5 6 -7 8) abs. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
137 |
#( -1 2 -3 4 -5 6 -7 8) asFloatArray abs. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
138 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
139 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
140 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
141 |
negated |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
142 |
"return a new vector containing negated values. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
143 |
The receiver is unchanged" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
144 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
145 |
^ self clone primNegated |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
146 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
147 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
148 |
#( -1 2 -3 4 -5 6 -7 8) negated. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
149 |
#( -1 2 -3 4 -5 6 -7 8) asFloatArray negated. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
150 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
151 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
152 |
"Modified: / 30-05-2007 / 17:51:47 / cg" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
153 |
! ! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
154 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
155 |
!AbstractNumberVector methodsFor:'arithmetic destructive'! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
156 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
157 |
*= anObject |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
158 |
"multiply the argument into the receiver (destructive). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
159 |
The argument may either be a scalar or another vector" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
160 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
161 |
^ anObject isNumber |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
162 |
ifTrue:[self primMulScalar: anObject asFloat] |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
163 |
ifFalse:[self primMulArray: anObject] |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
164 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
165 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
166 |
|f| |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
167 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
168 |
f := #(1 2 3 4) asFloatArray. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
169 |
f *= 3. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
170 |
f |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
171 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
172 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
173 |
|f| |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
174 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
175 |
f := #(1 2 3 4) asFloatArray. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
176 |
f *= #(1 2 3 4) asFloatArray. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
177 |
f |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
178 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
179 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
180 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
181 |
+= anObject |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
182 |
"add the argument into the receiver (destructive). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
183 |
The argument may either be a scalar or another vector" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
184 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
185 |
^ anObject isNumber |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
186 |
ifTrue:[self primAddScalar: anObject asFloat] |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
187 |
ifFalse:[self primAddArray: anObject] |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
188 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
189 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
190 |
|f| |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
191 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
192 |
f := #(1 2 3 4) asFloatArray. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
193 |
f += 3. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
194 |
f |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
195 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
196 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
197 |
|f| |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
198 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
199 |
f := #(1 2 3 4) asFloatArray. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
200 |
f += #(1 2 3 4) asFloatArray. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
201 |
f |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
202 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
203 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
204 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
205 |
-= anObject |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
206 |
"subtract the argument from the receiver (destructive). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
207 |
The argument may either be a scalar or another vector" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
208 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
209 |
^ anObject isNumber |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
210 |
ifTrue:[self primSubtractScalar: anObject asFloat] |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
211 |
ifFalse:[self primSubtractArray: anObject] |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
212 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
213 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
214 |
|f| |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
215 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
216 |
f := #(1 2 3 4) asFloatArray. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
217 |
f -= 3. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
218 |
f |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
219 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
220 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
221 |
|f| |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
222 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
223 |
f := #(1 2 3 4) asFloatArray. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
224 |
f += #(1 2 3 4) asFloatArray. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
225 |
f |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
226 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
227 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
228 |
"Created: / 30-05-2007 / 17:42:13 / cg" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
229 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
230 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
231 |
/= anObject |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
232 |
"divide the argument into the receiver (destructive). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
233 |
The argument may either be a scalar or another vector" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
234 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
235 |
^ anObject isNumber |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
236 |
ifTrue:[self primDivScalar: anObject asFloat] |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
237 |
ifFalse:[self primDivArray: anObject] |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
238 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
239 |
"Modified: / 30-05-2007 / 17:45:46 / cg" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
240 |
! ! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
241 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
242 |
!AbstractNumberVector methodsFor:'destructive arithmetic support'! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
243 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
244 |
primAbs |
19921 | 245 |
"low performance fall back: destructive replace each element by its absolute value. |
246 |
May be redefined in subclasses to use vector instructions" |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
247 |
|
19921 | 248 |
|sz "{ Class: SmallInteger }"| |
249 |
||
250 |
sz := self size. |
|
251 |
1 to: sz do:[:i| self at:i put: (self at:i) abs]. |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
252 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
253 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
254 |
|f| |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
255 |
f := FloatArray withAll:#(-1 2 -3 4 -5). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
256 |
Transcript showCR:f. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
257 |
Transcript showCR:f abs. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
258 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
259 |
|i| |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
260 |
i := SignedIntegerArray withAll:#(-1 2 -3 4 -5). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
261 |
Transcript showCR:i. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
262 |
Transcript showCR:i abs. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
263 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
264 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
265 |
|
19921 | 266 |
primAddArray:anArray |
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
267 |
"low performance fallback: destructively add the vector argument into the receiver. |
19921 | 268 |
The argument must be another vector. |
269 |
May be redefined in subclasses to use vector instructions" |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
270 |
|
19921 | 271 |
|sz "{ Class: SmallInteger }"| |
272 |
||
273 |
sz := self size. |
|
274 |
1 to:sz do:[:i| self at:i put: (self at:i) + (anArray at:i)]. |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
275 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
276 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
277 |
|f1 f2| |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
278 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
279 |
f1 := FloatArray withAll:#(1 2 3 4 5). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
280 |
f2 := FloatArray withAll:#(2 2 2 3 3). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
281 |
f1 += f2. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
282 |
f1 |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
283 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
284 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
285 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
286 |
primAddScalar: aScalar |
19921 | 287 |
"low performance fallback: destructively add the scalar argument into the receiver. |
288 |
May be redefined in subclasses to use vector instructions" |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
289 |
|
19921 | 290 |
|sz "{ Class: SmallInteger }"| |
291 |
||
292 |
sz := self size. |
|
293 |
1 to:sz do:[:i| self at:i put:(self at:i) + aScalar]. |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
294 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
295 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
296 |
primDivArray: floatArray |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
297 |
"low performance fallback: destructively divide the vector argument into the receiver. |
19921 | 298 |
The argument must be another vector. |
299 |
May be redefined in subclasses to use vector instructions" |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
300 |
|
19921 | 301 |
|sz "{ Class: SmallInteger }"| |
302 |
||
303 |
sz := self size. |
|
304 |
1 to: sz do:[:i| self at: i put: (self at: i) / (floatArray at: i)]. |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
305 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
306 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
307 |
|f1 f2| |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
308 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
309 |
f1 := FloatArray withAll:#(1 2 3 4 5). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
310 |
f2 := FloatArray withAll:#(2 2 2 3 3). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
311 |
f1 /= f2. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
312 |
f1 |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
313 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
314 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
315 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
316 |
primDivScalar: aScalar |
19921 | 317 |
"low performace fallback: destructively divide each element of the receiver |
318 |
by the scalar argument. |
|
319 |
May be redefined in subclasses to use vector instructions" |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
320 |
|
19921 | 321 |
|sz "{ Class: SmallInteger }"| |
322 |
||
323 |
sz := self size. |
|
324 |
1 to: sz do:[:i| self at: i put: (self at: i) / aScalar ]. |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
325 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
326 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
327 |
primMulArray: floatArray |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
328 |
"low performance fallback: destructively multiply the vector argument into the receiver. |
19921 | 329 |
The argument must be another vector. |
330 |
May be redefined in subclasses to use vector instructions" |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
331 |
|
19921 | 332 |
|sz "{ Class: SmallInteger }"| |
333 |
||
334 |
sz := self size. |
|
335 |
1 to: sz do:[:i| self at: i put: (self at: i) * (floatArray at: i)]. |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
336 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
337 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
338 |
|f1 f2| |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
339 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
340 |
f1 := FloatArray withAll:#(1 2 3 4 5). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
341 |
f2 := FloatArray withAll:#(2 2 2 3 3). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
342 |
f1 *= f2. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
343 |
f1 |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
344 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
345 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
346 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
347 |
primMulScalar: aScalar |
19921 | 348 |
"low performace fallback: destructively multiply each element of the receiver |
349 |
by the scalar argument. |
|
350 |
May be redefined in subclasses to use vector instructions" |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
351 |
|
19921 | 352 |
|sz "{ Class: SmallInteger }"| |
353 |
||
354 |
sz := self size. |
|
355 |
1 to: sz do:[:i| self at: i put: (self at: i) * aScalar ]. |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
356 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
357 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
358 |
primNegated |
19921 | 359 |
"low performance fallback: destructively negative value of each element. |
360 |
May be redefined in subclasses to use vector instructions" |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
361 |
|
19921 | 362 |
|sz "{ Class: SmallInteger }"| |
363 |
||
364 |
sz := self size. |
|
365 |
1 to: sz do:[:i| self at: i put: (self at: i) negated]. |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
366 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
367 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
368 |
|f| |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
369 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
370 |
f := FloatArray withAll:#(-1 2 -3 4 -5). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
371 |
f negated. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
372 |
f |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
373 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
374 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
375 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
376 |
primSubtractArray: floatArray |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
377 |
"low performance fallback: destructively subtract the vector argument into the receiver. |
19921 | 378 |
The argument must be another vector. |
379 |
May be redefined in subclasses to use vector instructions" |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
380 |
|
19921 | 381 |
|sz "{ Class: SmallInteger }"| |
382 |
||
383 |
sz := self size. |
|
384 |
1 to: sz do:[:i| self at: i put: (self at: i) - (floatArray at: i)]. |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
385 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
386 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
387 |
|f1 f2| |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
388 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
389 |
f1 := FloatArray withAll:#(1 2 3 4 5). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
390 |
f2 := FloatArray withAll:#(2 2 2 3 3). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
391 |
f1 -= f2. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
392 |
f1 |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
393 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
394 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
395 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
396 |
primSubtractScalar: aScalar |
19921 | 397 |
"low performace fallback: destructively subtract the scalar argument |
398 |
from each element of the receiver. |
|
399 |
May be redefined in subclasses to use vector instructions" |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
400 |
|
19921 | 401 |
|sz "{ Class: SmallInteger }"| |
402 |
||
403 |
sz := self size. |
|
404 |
1 to: sz do:[:i| self at: i put: (self at: i) - aScalar ]. |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
405 |
! ! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
406 |
|
15934
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
407 |
!AbstractNumberVector methodsFor:'queries'! |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
408 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
409 |
absMax |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
410 |
"return the largest absolute value" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
411 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
412 |
|minMax| |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
413 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
414 |
minMax := self minMax. |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
415 |
^ (minMax at:1) abs max:(minMax at:2) abs |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
416 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
417 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
418 |
|f1| |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
419 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
420 |
f1 := (1 to:1000) asFloatArray. |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
421 |
Time millisecondsToRun:[ 1000 timesRepeat:[ f1 absMax ] ] |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
422 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
423 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
424 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
425 |
|f1| |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
426 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
427 |
f1 := FloatArray withAll:#(1 2 3 4 5). |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
428 |
f1 absMax |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
429 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
430 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
431 |
|f1| |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
432 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
433 |
f1 := FloatArray withAll:#(5 4 3 2 1). |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
434 |
f1 absMax |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
435 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
436 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
437 |
|f1| |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
438 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
439 |
f1 := FloatArray withAll:#(5 -4 3 2 1). |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
440 |
f1 absMax |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
441 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
442 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
443 |
|f1| |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
444 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
445 |
f1 := FloatArray withAll:#(5 -5 3 2 1). |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
446 |
f1 absMax |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
447 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
448 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
449 |
|f1| |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
450 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
451 |
f1 := FloatArray withAll:#(5 -6 3 2 1). |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
452 |
f1 absMax |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
453 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
454 |
! ! |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
455 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
456 |
!AbstractNumberVector methodsFor:'vector arithmetic'! |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
457 |
|
17163
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
458 |
length |
19220 | 459 |
<resource: #obsolete> |
17163
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
460 |
"Return the length of the receiver interpreted as vector |
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
461 |
(that is the length of the vector from 0.0 @ 0.0 @ ... @ 0.0 |
19029 | 462 |
to the point in the n-dimensional space represented by the receiver). |
463 |
Obsolete: the name 'length' may lead to confusion. |
|
464 |
therefore renamed to vectorLength" |
|
17163
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
465 |
|
19029 | 466 |
self obsoleteMethodWarning:'use vectorLength'. |
467 |
^ self squaredVectorLength sqrt |
|
17163
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
468 |
|
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
469 |
" |
19029 | 470 |
#(10.0 10.0) asFloatArray vectorLength |
471 |
#(10.0 10.0 10.0) asFloatArray vectorLength |
|
17163
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
472 |
" |
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
473 |
! |
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
474 |
|
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
475 |
squaredLength |
19220 | 476 |
<resource: #obsolete> |
19029 | 477 |
"Return the squared length of the receiver interpreted as vector. |
478 |
Obsolete: the name 'squaredLength' may lead to confusion. |
|
479 |
therefore renamed to squaredVectorLength" |
|
17163
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
480 |
|
19029 | 481 |
self obsoleteMethodWarning:'use squaredVectorLength'. |
17163
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
482 |
^ self dot: self |
15934
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
483 |
! ! |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
484 |
|
13824 | 485 |
!AbstractNumberVector class methodsFor:'documentation'! |
486 |
||
487 |
version |
|
19029 | 488 |
^ '$Header$' |
13824 | 489 |
! |
490 |
||
491 |
version_CVS |
|
19029 | 492 |
^ '$Header$' |
13824 | 493 |
! ! |
15934
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
494 |