9 other person. No title to or ownership of the software is |
9 other person. No title to or ownership of the software is |
10 hereby transferred. |
10 hereby transferred. |
11 " |
11 " |
12 "{ Package: 'stx:libbasic' }" |
12 "{ Package: 'stx:libbasic' }" |
13 |
13 |
|
14 "{ NameSpace: Smalltalk }" |
|
15 |
14 UninterpretedBytes subclass:#AbstractNumberVector |
16 UninterpretedBytes subclass:#AbstractNumberVector |
15 instanceVariableNames:'' |
17 instanceVariableNames:'' |
16 classVariableNames:'' |
18 classVariableNames:'' |
17 poolDictionaries:'' |
19 poolDictionaries:'' |
18 category:'Collections-Arrayed' |
20 category:'Collections-Arrayed' |
381 " |
383 " |
382 ! ! |
384 ! ! |
383 |
385 |
384 !AbstractNumberVector methodsFor:'vector arithmetic'! |
386 !AbstractNumberVector methodsFor:'vector arithmetic'! |
385 |
387 |
386 dot:aFloatVector |
|
387 "Return the dot product of the receiver and the argument. |
|
388 Fail if the argument is not of the same size as the receiver." |
|
389 |
|
390 |mySize result| |
|
391 |
|
392 mySize := self size. |
|
393 mySize = aFloatVector size ifFalse:[^self error:'Must be of equal size']. |
|
394 result := 0.0. |
|
395 1 to: mySize do:[:i| |
|
396 result := result + ((self at: i) * (aFloatVector at: i)). |
|
397 ]. |
|
398 ^result |
|
399 |
|
400 " |
|
401 |v| |
|
402 |
|
403 v := #(2.0 2.0 1.0) asDoubleArray. |
|
404 v dot:v. |
|
405 " |
|
406 ! |
|
407 |
|
408 length |
388 length |
409 "Return the length of the receiver interpreted as vector |
389 "Return the length of the receiver interpreted as vector |
410 (that is the length of the vector from 0.0 @ 0.0 @ ... @ 0.0 |
390 (that is the length of the vector from 0.0 @ 0.0 @ ... @ 0.0 |
411 to the point in the n-dimensional space represented by the receiver)" |
391 to the point in the n-dimensional space represented by the receiver). |
412 |
392 Obsolete: the name 'length' may lead to confusion. |
413 ^ self squaredLength sqrt |
393 therefore renamed to vectorLength" |
414 |
394 |
415 " |
395 self obsoleteMethodWarning:'use vectorLength'. |
416 #(10.0 10.0) asFloatArray length |
396 ^ self squaredVectorLength sqrt |
417 #(10.0 10.0 10.0) asFloatArray length |
397 |
|
398 " |
|
399 #(10.0 10.0) asFloatArray vectorLength |
|
400 #(10.0 10.0 10.0) asFloatArray vectorLength |
418 " |
401 " |
419 ! |
402 ! |
420 |
403 |
421 squaredLength |
404 squaredLength |
422 "Return the squared length of the receiver interpreted as vector" |
405 "Return the squared length of the receiver interpreted as vector. |
423 |
406 Obsolete: the name 'squaredLength' may lead to confusion. |
|
407 therefore renamed to squaredVectorLength" |
|
408 |
|
409 self obsoleteMethodWarning:'use squaredVectorLength'. |
424 ^ self dot: self |
410 ^ self dot: self |
425 ! ! |
411 ! ! |
426 |
412 |
427 !AbstractNumberVector class methodsFor:'documentation'! |
413 !AbstractNumberVector class methodsFor:'documentation'! |
428 |
414 |
429 version |
415 version |
430 ^ '$Header: /cvs/stx/stx/libbasic/AbstractNumberVector.st,v 1.5 2014-12-08 17:29:27 cg Exp $' |
416 ^ '$Header$' |
431 ! |
417 ! |
432 |
418 |
433 version_CVS |
419 version_CVS |
434 ^ '$Header: /cvs/stx/stx/libbasic/AbstractNumberVector.st,v 1.5 2014-12-08 17:29:27 cg Exp $' |
420 ^ '$Header$' |
435 ! ! |
421 ! ! |
436 |
422 |