Skip to content

Commit 2ae081b

Browse files
committed
Renaming methods.
1 parent 88aab41 commit 2ae081b

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

src/Math-Matrix/PMTensor.class.st

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ PMTensor >> first [
5858
^first
5959
]
6060

61+
{ #category : #'primitives - file' }
62+
PMTensor >> flattenedIndexOf: coords [
63+
64+
| position |
65+
position := 1.
66+
coords withIndexDo: [ :elt :i |
67+
position := elt - 1 * (strides at: i) + position ].
68+
^ position
69+
]
70+
6171
{ #category : #'as yet unclassified' }
6272
PMTensor >> flattenedIndexOf: aFlatArray withShape: aShape [
6373

@@ -67,22 +77,21 @@ PMTensor >> flattenedIndexOf: aFlatArray withShape: aShape [
6777
shape ifNotEmpty: [ self updateStrides]
6878
]
6979

70-
{ #category : #public }
71-
PMTensor >> get: coords [
80+
{ #category : #'as yet unclassified' }
81+
PMTensor >> fromNestedArray: aFlatArray withShape: aShape [
7282

73-
| position |
74-
position := self getPosition: coords.
75-
^ array at: position
83+
array := aFlatArray.
84+
shape := aShape copy.
85+
self updateFirst.
86+
shape ifNotEmpty: [ self updateStrides]
7687
]
7788

78-
{ #category : #'primitives - file' }
79-
PMTensor >> getPosition: coords [
89+
{ #category : #public }
90+
PMTensor >> get: coords [
8091

8192
| position |
82-
position := 1.
83-
coords withIndexDo: [ :elt :i |
84-
position := elt - 1 * (strides at: i) + position ].
85-
^ position
93+
position := self flattenedIndexOf: coords.
94+
^ array at: position
8695
]
8796

8897
{ #category : #accessing }
@@ -100,7 +109,7 @@ PMTensor >> reshape: aNewShape [
100109
{ #category : #initialization }
101110
PMTensor >> set: coords value: aValue [
102111

103-
array at: (self getPosition: coords) put: aValue
112+
array at: (self flattenedIndexOf: coords) put: aValue
104113
]
105114

106115
{ #category : #accessing }
@@ -112,10 +121,8 @@ PMTensor >> shape [
112121
{ #category : #accessing }
113122
PMTensor >> size [
114123

115-
| product |
116-
product := 1.
117-
shape do: [ :each | product := each * product ].
118-
^ product
124+
^ shape inject: 1 into: [ :each :product | each * product].
125+
119126
]
120127

121128
{ #category : #accessing }

0 commit comments

Comments
 (0)