Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4620-Simplify-FloatArray-handling #4621

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Collections-Abstract/SequenceableCollection.class.st
Expand Up @@ -228,7 +228,7 @@ SequenceableCollection >> asFloatArray [

| floatArray |
floatArray := FloatArray new: self size.
1 to: self size do:[:i| floatArray at: i put: (self at: i) asFloat ].
self withIndexDo: [:el :i| floatArray at: i put: el asFloat ].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this change because using #to:do: is faster. So it might be used for performance reasons.

^floatArray
]

Expand Down
3 changes: 1 addition & 2 deletions src/Collections-Native/FloatArray.class.st
Expand Up @@ -54,8 +54,7 @@ FloatArray >> dot: aFloatVector [
<primitive: 'primitiveDotProduct' module: 'FloatArrayPlugin'>
self size = aFloatVector size ifFalse:[^self error:'Must be equal size'].
result := 0.0.
1 to: self size do:[:i|
result := result + ((self at: i) * (aFloatVector at: i))].
self withIndexDo: [:el :i| result := result + (el * (aFloatVector at: i))].
^result
]

Expand Down
17 changes: 13 additions & 4 deletions src/Collections-Tests/FloatArrayTest.class.st
Expand Up @@ -359,10 +359,19 @@ FloatArrayTest >> subCollectionNotIn [
FloatArrayTest >> testArithmeticCoercion [
"This test is related to http://bugs.squeak.org/view.php?id=6782"

self should: [3.0 / (FloatArray with: 2.0) = (FloatArray with: 1.5)].
self should: [3.0 * (FloatArray with: 2.0) = (FloatArray with: 6.0)].
self should: [3.0 + (FloatArray with: 2.0) = (FloatArray with: 5.0)].
self should: [3.0 - (FloatArray with: 2.0) = (FloatArray with: 1.0)].
self assert: 3.0 / (FloatArray with: 2.0) equals: (FloatArray with: 1.5).
self assert: 3.0 * (FloatArray with: 2.0) equals: (FloatArray with: 6.0).
self assert: 3.0 + (FloatArray with: 2.0) equals: (FloatArray with: 5.0).
self assert: 3.0 - (FloatArray with: 2.0) equals: (FloatArray with: 1.0)
]

{ #category : #'tests - arithmetic' }
FloatArrayTest >> testDotProduct [
|a b|
a := #(2.0 3.0 4.0 5.0) asFloatArray.
b := #(2.0 3.0 4.0 5.0) asFloatArray.
self assert: (a dot: b) equals: 54

]

{ #category : #testing }
Expand Down