author | Stefan Vogel <sv@exept.de> |
Mon, 22 Jun 2015 11:33:37 +0200 | |
branch | expecco_2_7_5_branch |
changeset 18499 | b132ac7c9d6a |
parent 15934 | 2ac38e84aab5 |
child 17163 | 506b7f2ef014 |
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 |
||
14026 | 14 |
UninterpretedBytes subclass:#AbstractNumberVector |
13824 | 15 |
instanceVariableNames:'' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Collections-Arrayed' |
|
19 |
! |
|
20 |
||
21 |
!AbstractNumberVector class methodsFor:'documentation'! |
|
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 2011 by Claus Gittinger |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
37 |
documentation |
|
38 |
" |
|
39 |
abstract superclass for all direct storing number vector classes |
|
40 |
(float, double, integer arrays) |
|
41 |
||
42 |
Mostly to share double dispatch code. |
|
43 |
" |
|
44 |
! ! |
|
45 |
||
15934
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
46 |
!AbstractNumberVector methodsFor:'queries'! |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
47 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
48 |
absMax |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
49 |
"return the largest absolute value" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
50 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
51 |
|minMax| |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
52 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
53 |
minMax := self minMax. |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
54 |
^ (minMax at:1) abs max:(minMax at:2) abs |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
55 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
56 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
57 |
|f1| |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
58 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
59 |
f1 := (1 to:1000) asFloatArray. |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
60 |
Time millisecondsToRun:[ 1000 timesRepeat:[ f1 absMax ] ] |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
61 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
62 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
63 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
64 |
|f1| |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
65 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
66 |
f1 := FloatArray withAll:#(1 2 3 4 5). |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
67 |
f1 absMax |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
68 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
69 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
70 |
|f1| |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
71 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
72 |
f1 := FloatArray withAll:#(5 4 3 2 1). |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
73 |
f1 absMax |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
74 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
75 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
76 |
|f1| |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
77 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
78 |
f1 := FloatArray withAll:#(5 -4 3 2 1). |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
79 |
f1 absMax |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
80 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
81 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
82 |
|f1| |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
83 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
84 |
f1 := FloatArray withAll:#(5 -5 3 2 1). |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
85 |
f1 absMax |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
86 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
87 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
88 |
|f1| |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
89 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
90 |
f1 := FloatArray withAll:#(5 -6 3 2 1). |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
91 |
f1 absMax |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
92 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
93 |
! |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
94 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
95 |
length |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
96 |
"Return the length of the receiver interpreted as vector |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
97 |
(that is the length of the vector from 0.0 @ 0.0 @ ... @ 0.0 |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
98 |
to the point in the n-dimensional space represented by the receiver)" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
99 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
100 |
^ self squaredLength sqrt |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
101 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
102 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
103 |
#(10.0 10.0) asFloatArray length |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
104 |
#(10.0 10.0 10.0) asFloatArray length |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
105 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
106 |
! |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
107 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
108 |
squaredLength |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
109 |
"Return the squared length of the receiver interpreted as vector" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
110 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
111 |
^ self dot: self |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
112 |
! ! |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
113 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
114 |
!AbstractNumberVector methodsFor:'vector arithmetic'! |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
115 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
116 |
dot:aFloatVector |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
117 |
"Return the dot product of the receiver and the argument. |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
118 |
Fail if the argument is not of the same size as the receiver." |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
119 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
120 |
|mySize result| |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
121 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
122 |
mySize := self size. |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
123 |
mySize = aFloatVector size ifFalse:[^self error:'Must be of equal size']. |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
124 |
result := 0.0. |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
125 |
1 to: mySize do:[:i| |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
126 |
result := result + ((self at: i) * (aFloatVector at: i)). |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
127 |
]. |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
128 |
^result |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
129 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
130 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
131 |
|v| |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
132 |
|
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
133 |
v := #(2.0 2.0 1.0) asDoubleArray. |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
134 |
v dot:v. |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
135 |
" |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
136 |
! ! |
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
137 |
|
13824 | 138 |
!AbstractNumberVector class methodsFor:'documentation'! |
139 |
||
140 |
version |
|
15934
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
141 |
^ '$Header: /cvs/stx/stx/libbasic/AbstractNumberVector.st,v 1.3 2014-02-04 16:40:25 cg Exp $' |
13824 | 142 |
! |
143 |
||
144 |
version_CVS |
|
15934
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
145 |
^ '$Header: /cvs/stx/stx/libbasic/AbstractNumberVector.st,v 1.3 2014-02-04 16:40:25 cg Exp $' |
13824 | 146 |
! ! |
15934
2ac38e84aab5
class: AbstractNumberVector
Claus Gittinger <cg@exept.de>
parents:
14026
diff
changeset
|
147 |