author | Claus Gittinger <cg@exept.de> |
Thu, 02 Jun 2016 11:26:05 +0200 | |
changeset 19921 | a8c0dde1075e |
parent 19220 | b2b3ad682045 |
child 19948 | be658f466bca |
child 20627 | 47ed4d83bc81 |
permissions | -rw-r--r-- |
19921 | 1 |
"{ Encoding: utf8 }" |
2 |
||
13824 | 3 |
" |
4 |
COPYRIGHT (c) 2011 by Claus Gittinger |
|
5 |
All Rights Reserved |
|
6 |
||
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
14 |
"{ Package: 'stx:libbasic' }" |
|
15 |
||
19029 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
14026 | 18 |
UninterpretedBytes subclass:#AbstractNumberVector |
13824 | 19 |
instanceVariableNames:'' |
20 |
classVariableNames:'' |
|
21 |
poolDictionaries:'' |
|
22 |
category:'Collections-Arrayed' |
|
23 |
! |
|
24 |
||
25 |
!AbstractNumberVector class methodsFor:'documentation'! |
|
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 2011 by Claus Gittinger |
|
30 |
All Rights Reserved |
|
31 |
||
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
40 |
||
41 |
documentation |
|
42 |
" |
|
43 |
abstract superclass for all direct storing number vector classes |
|
44 |
(float, double, integer arrays) |
|
45 |
||
46 |
Mostly to share double dispatch code. |
|
47 |
" |
|
48 |
! ! |
|
49 |
||
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
50 |
!AbstractNumberVector methodsFor:'arithmetic'! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
51 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
52 |
* anObject |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
53 |
"return the product of the receiver and the argument. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
54 |
The argument may either be a scalar or another vector" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
55 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
56 |
^ self clone *= anObject |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
57 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
58 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
59 |
#(1 2 3 4) asFloatArray * 3 |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
60 |
#(1 2 3 4) asFloatArray * #(1 2 3 4) asFloatArray |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
61 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
62 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
63 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
64 |
+ anObject |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
65 |
"return the sum of the receiver and the argument. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
66 |
The argument may either be a scalar or another vector" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
67 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
68 |
^ self clone += anObject |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
69 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
70 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
71 |
#(1 2 3 4) asFloatArray + 3 |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
72 |
#(1 2 3 4) asFloatArray + #(1 2 3 4) asFloatArray |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
73 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
74 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
75 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
76 |
- anObject |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
77 |
"return the difference of the receiver and the argument. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
78 |
The argument may either be a scalar or another vector" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
79 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
80 |
^ self clone -= anObject |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
81 |
|
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 |
#(1 2 3 4) asFloatArray - 3 |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
84 |
#(1 2 3 4) asFloatArray - #(1 2 3 4) asFloatArray |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
85 |
" |
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 |
"Created: / 30-05-2007 / 17:41:46 / cg" |
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 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
90 |
/ anObject |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
91 |
"return the division of the receiver and the argument. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
92 |
The argument may either be a scalar or another vector" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
93 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
94 |
^ self clone /= anObject |
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 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
97 |
#(1 2 3 4) asFloatArray / 3 |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
98 |
#(1 2 3 4) asFloatArray / #(1 2 3 4) asFloatArray |
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 |
"Created: / 30-05-2007 / 17:46:05 / cg" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
102 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
103 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
104 |
abs |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
105 |
"return a new vector containing absolute values. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
106 |
The receiver is unchanged" |
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 |
^ self clone primAbs |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
109 |
|
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 |
#( -1 2 -3 4 -5 6 -7 8) abs. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
112 |
#( -1 2 -3 4 -5 6 -7 8) asFloatArray abs. |
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 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
116 |
negated |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
117 |
"return a new vector containing negated values. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
118 |
The receiver is unchanged" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
119 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
120 |
^ self clone primNegated |
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 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
123 |
#( -1 2 -3 4 -5 6 -7 8) negated. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
124 |
#( -1 2 -3 4 -5 6 -7 8) asFloatArray negated. |
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 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
127 |
"Modified: / 30-05-2007 / 17:51:47 / cg" |
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 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
130 |
!AbstractNumberVector methodsFor:'arithmetic destructive'! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
131 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
132 |
*= anObject |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
133 |
"multiply the argument into the receiver (destructive). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
134 |
The argument may either be a scalar or another vector" |
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 |
^ anObject isNumber |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
137 |
ifTrue:[self primMulScalar: anObject asFloat] |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
138 |
ifFalse:[self primMulArray: anObject] |
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 |
|f| |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
142 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
143 |
f := #(1 2 3 4) asFloatArray. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
144 |
f *= 3. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
145 |
f |
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 |
|f| |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
149 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
150 |
f := #(1 2 3 4) asFloatArray. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
151 |
f *= #(1 2 3 4) asFloatArray. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
152 |
f |
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 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
156 |
+= anObject |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
157 |
"add the argument into the receiver (destructive). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
158 |
The argument may either be a scalar or another vector" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
159 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
160 |
^ anObject isNumber |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
161 |
ifTrue:[self primAddScalar: anObject asFloat] |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
162 |
ifFalse:[self primAddArray: anObject] |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
163 |
|
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 |
|f| |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
166 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
167 |
f := #(1 2 3 4) asFloatArray. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
168 |
f += 3. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
169 |
f |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
170 |
" |
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 |
|f| |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
173 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
174 |
f := #(1 2 3 4) asFloatArray. |
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 |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
177 |
" |
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 |
-= anObject |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
181 |
"subtract the argument from the receiver (destructive). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
182 |
The argument may either be a scalar or another vector" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
183 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
184 |
^ anObject isNumber |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
185 |
ifTrue:[self primSubtractScalar: anObject asFloat] |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
186 |
ifFalse:[self primSubtractArray: anObject] |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
187 |
|
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 |
|f| |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
190 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
191 |
f := #(1 2 3 4) asFloatArray. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
192 |
f -= 3. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
193 |
f |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
194 |
" |
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 |
|f| |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
197 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
198 |
f := #(1 2 3 4) asFloatArray. |
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 |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
201 |
" |
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 |
"Created: / 30-05-2007 / 17:42:13 / cg" |
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 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
206 |
/= anObject |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
207 |
"divide the argument into the receiver (destructive). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
208 |
The argument may either be a scalar or another vector" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
209 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
210 |
^ anObject isNumber |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
211 |
ifTrue:[self primDivScalar: anObject asFloat] |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
212 |
ifFalse:[self primDivArray: anObject] |
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 |
"Modified: / 30-05-2007 / 17:45:46 / cg" |
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 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
217 |
!AbstractNumberVector methodsFor:'destructive arithmetic support'! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
218 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
219 |
primAbs |
19921 | 220 |
"low performance fall back: destructive replace each element by its absolute value. |
221 |
May be redefined in subclasses to use vector instructions" |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
222 |
|
19921 | 223 |
|sz "{ Class: SmallInteger }"| |
224 |
||
225 |
sz := self size. |
|
226 |
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
|
227 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
228 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
229 |
|f| |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
230 |
f := FloatArray withAll:#(-1 2 -3 4 -5). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
231 |
Transcript showCR:f. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
232 |
Transcript showCR:f abs. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
233 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
234 |
|i| |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
235 |
i := SignedIntegerArray withAll:#(-1 2 -3 4 -5). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
236 |
Transcript showCR:i. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
237 |
Transcript showCR:i abs. |
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 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
240 |
|
19921 | 241 |
primAddArray:anArray |
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
242 |
"low performance fallback: destructively add the vector argument into the receiver. |
19921 | 243 |
The argument must be another vector. |
244 |
May be redefined in subclasses to use vector instructions" |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
245 |
|
19921 | 246 |
|sz "{ Class: SmallInteger }"| |
247 |
||
248 |
sz := self size. |
|
249 |
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
|
250 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
251 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
252 |
|f1 f2| |
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 |
f1 := FloatArray withAll:#(1 2 3 4 5). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
255 |
f2 := FloatArray withAll:#(2 2 2 3 3). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
256 |
f1 += f2. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
257 |
f1 |
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 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
260 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
261 |
primAddScalar: aScalar |
19921 | 262 |
"low performance fallback: destructively add the scalar argument into the receiver. |
263 |
May be redefined in subclasses to use vector instructions" |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
264 |
|
19921 | 265 |
|sz "{ Class: SmallInteger }"| |
266 |
||
267 |
sz := self size. |
|
268 |
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
|
269 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
270 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
271 |
primDivArray: floatArray |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
272 |
"low performance fallback: destructively divide the vector argument into the receiver. |
19921 | 273 |
The argument must be another vector. |
274 |
May be redefined in subclasses to use vector instructions" |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
275 |
|
19921 | 276 |
|sz "{ Class: SmallInteger }"| |
277 |
||
278 |
sz := self size. |
|
279 |
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
|
280 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
281 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
282 |
|f1 f2| |
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 |
f1 := FloatArray withAll:#(1 2 3 4 5). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
285 |
f2 := FloatArray withAll:#(2 2 2 3 3). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
286 |
f1 /= f2. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
287 |
f1 |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
288 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
289 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
290 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
291 |
primDivScalar: aScalar |
19921 | 292 |
"low performace fallback: destructively divide each element of the receiver |
293 |
by the scalar argument. |
|
294 |
May be redefined in subclasses to use vector instructions" |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
295 |
|
19921 | 296 |
|sz "{ Class: SmallInteger }"| |
297 |
||
298 |
sz := self size. |
|
299 |
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
|
300 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
301 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
302 |
primMulArray: floatArray |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
303 |
"low performance fallback: destructively multiply the vector argument into the receiver. |
19921 | 304 |
The argument must be another vector. |
305 |
May be redefined in subclasses to use vector instructions" |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
306 |
|
19921 | 307 |
|sz "{ Class: SmallInteger }"| |
308 |
||
309 |
sz := self size. |
|
310 |
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
|
311 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
312 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
313 |
|f1 f2| |
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 |
f1 := FloatArray withAll:#(1 2 3 4 5). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
316 |
f2 := FloatArray withAll:#(2 2 2 3 3). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
317 |
f1 *= f2. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
318 |
f1 |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
319 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
320 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
321 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
322 |
primMulScalar: aScalar |
19921 | 323 |
"low performace fallback: destructively multiply each element of the receiver |
324 |
by the scalar argument. |
|
325 |
May be redefined in subclasses to use vector instructions" |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
326 |
|
19921 | 327 |
|sz "{ Class: SmallInteger }"| |
328 |
||
329 |
sz := self size. |
|
330 |
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
|
331 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
332 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
333 |
primNegated |
19921 | 334 |
"low performance fallback: destructively negative value of each element. |
335 |
May be redefined in subclasses to use vector instructions" |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
336 |
|
19921 | 337 |
|sz "{ Class: SmallInteger }"| |
338 |
||
339 |
sz := self size. |
|
340 |
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
|
341 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
342 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
343 |
|f| |
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 |
f := FloatArray withAll:#(-1 2 -3 4 -5). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
346 |
f negated. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
347 |
f |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
348 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
349 |
! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
350 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
351 |
primSubtractArray: floatArray |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
352 |
"low performance fallback: destructively subtract the vector argument into the receiver. |
19921 | 353 |
The argument must be another vector. |
354 |
May be redefined in subclasses to use vector instructions" |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
355 |
|
19921 | 356 |
|sz "{ Class: SmallInteger }"| |
357 |
||
358 |
sz := self size. |
|
359 |
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
|
360 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
361 |
" |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
362 |
|f1 f2| |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
363 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
364 |
f1 := FloatArray withAll:#(1 2 3 4 5). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
365 |
f2 := FloatArray withAll:#(2 2 2 3 3). |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
366 |
f1 -= f2. |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
367 |
f1 |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
368 |
" |
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 |
|
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
371 |
primSubtractScalar: aScalar |
19921 | 372 |
"low performace fallback: destructively subtract the scalar argument |
373 |
from each element of the receiver. |
|
374 |
May be redefined in subclasses to use vector instructions" |
|
17197
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
375 |
|
19921 | 376 |
|sz "{ Class: SmallInteger }"| |
377 |
||
378 |
sz := self size. |
|
379 |
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
|
380 |
! ! |
ef67b8f2437e
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
17163
diff
changeset
|
381 |
|
15934
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
382 |
!AbstractNumberVector methodsFor:'queries'! |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
383 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
384 |
absMax |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
385 |
"return the largest absolute value" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
386 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
387 |
|minMax| |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
388 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
389 |
minMax := self minMax. |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
390 |
^ (minMax at:1) abs max:(minMax at:2) abs |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
391 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
392 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
393 |
|f1| |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
394 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
395 |
f1 := (1 to:1000) asFloatArray. |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
396 |
Time millisecondsToRun:[ 1000 timesRepeat:[ f1 absMax ] ] |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
397 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
398 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
399 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
400 |
|f1| |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
401 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
402 |
f1 := FloatArray withAll:#(1 2 3 4 5). |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
403 |
f1 absMax |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
404 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
405 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
406 |
|f1| |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
407 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
408 |
f1 := FloatArray withAll:#(5 4 3 2 1). |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
409 |
f1 absMax |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
410 |
" |
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 |
|f1| |
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 |
f1 := FloatArray withAll:#(5 -4 3 2 1). |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
415 |
f1 absMax |
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 := FloatArray withAll:#(5 -5 3 2 1). |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
421 |
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 |
|f1| |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
425 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
426 |
f1 := FloatArray withAll:#(5 -6 3 2 1). |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
427 |
f1 absMax |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
428 |
" |
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 |
!AbstractNumberVector methodsFor:'vector arithmetic'! |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
432 |
|
17163
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
433 |
length |
19220 | 434 |
<resource: #obsolete> |
17163
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
435 |
"Return the length of the receiver interpreted as vector |
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
436 |
(that is the length of the vector from 0.0 @ 0.0 @ ... @ 0.0 |
19029 | 437 |
to the point in the n-dimensional space represented by the receiver). |
438 |
Obsolete: the name 'length' may lead to confusion. |
|
439 |
therefore renamed to vectorLength" |
|
17163
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
440 |
|
19029 | 441 |
self obsoleteMethodWarning:'use vectorLength'. |
442 |
^ self squaredVectorLength sqrt |
|
17163
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
443 |
|
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
444 |
" |
19029 | 445 |
#(10.0 10.0) asFloatArray vectorLength |
446 |
#(10.0 10.0 10.0) asFloatArray vectorLength |
|
17163
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
447 |
" |
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
448 |
! |
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
449 |
|
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
450 |
squaredLength |
19220 | 451 |
<resource: #obsolete> |
19029 | 452 |
"Return the squared length of the receiver interpreted as vector. |
453 |
Obsolete: the name 'squaredLength' may lead to confusion. |
|
454 |
therefore renamed to squaredVectorLength" |
|
17163
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
455 |
|
19029 | 456 |
self obsoleteMethodWarning:'use squaredVectorLength'. |
17163
506b7f2ef014
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
15934
diff
changeset
|
457 |
^ self dot: self |
15934
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
458 |
! ! |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
459 |
|
13824 | 460 |
!AbstractNumberVector class methodsFor:'documentation'! |
461 |
||
462 |
version |
|
19029 | 463 |
^ '$Header$' |
13824 | 464 |
! |
465 |
||
466 |
version_CVS |
|
19029 | 467 |
^ '$Header$' |
13824 | 468 |
! ! |
15934
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
469 |