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 [
217217 self assert: (w at: 3 ) equals: 6
218218]
219219
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+
220235{ #category : #tests }
221236PMVectorTest >> testVectorGreater [
222237
Original file line number Diff line number Diff line change @@ -181,6 +181,13 @@ PMVector >> cumsum [
181181
182182]
183183
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+
184191{ #category : #operation }
185192PMVector >> hadamardProduct: aVector [
186193 " Answers the elementwise product of the receiver with aVector."
@@ -252,10 +259,12 @@ PMVector >> normalized [
252259{ #category : #operation }
253260PMVector >> productWithVector: aVector [
254261 " Answers the scalar product of aVector with the receiver."
262+
255263 | n |
256264 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 ]
259268]
260269
261270{ #category : #operation }
You can’t perform that action at this time.
0 commit comments