File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -217,6 +217,21 @@ PMVectorTest >> testVectorCumulativeSum [
217
217
self assert: (w at: 3 ) equals: 6
218
218
]
219
219
220
+ { #category : #tests }
221
+ PMVectorTest >> testVectorFirstNorm [
222
+
223
+ | v1 v2 v3 |
224
+ v1 := #( 1 0 ) asPMVector.
225
+ self assert: v1 firstNorm equals: 1 .
226
+ v2 := #( 1 1 ) asPMVector.
227
+ self assert: v2 firstNorm equals: 2 .
228
+ v3 := #( -1 1 ) asPMVector.
229
+ self assert: v3 firstNorm equals: 2 .
230
+
231
+ self assert: (v1 + v2) firstNorm equals: 3 .
232
+ self assert: (v2 + v3) firstNorm equals: 2
233
+ ]
234
+
220
235
{ #category : #tests }
221
236
PMVectorTest >> testVectorGreater [
222
237
Original file line number Diff line number Diff line change @@ -181,6 +181,13 @@ PMVector >> cumsum [
181
181
182
182
]
183
183
184
+ { #category : #operation }
185
+ PMVector >> firstNorm [
186
+ " Answer the first norm of the receiver."
187
+
188
+ ^ self inject: 0 into: [ :accu :e | accu + e abs ]
189
+ ]
190
+
184
191
{ #category : #operation }
185
192
PMVector >> hadamardProduct: aVector [
186
193
" Answers the elementwise product of the receiver with aVector."
@@ -252,10 +259,12 @@ PMVector >> normalized [
252
259
{ #category : #operation }
253
260
PMVector >> productWithVector: aVector [
254
261
" Answers the scalar product of aVector with the receiver."
262
+
255
263
| n |
256
264
n := 0 .
257
- ^ self inject: 0
258
- into: [ :sum :each | n := n + 1 . (aVector at: n) * each + sum]
265
+ ^ self inject: 0 into: [ :sum :each |
266
+ n := n + 1 .
267
+ (aVector at: n) * each + sum ]
259
268
]
260
269
261
270
{ #category : #operation }
You can’t perform that action at this time.
0 commit comments