@@ -16,6 +16,12 @@ PMNDArray class >> fromNestedArray: anArray [
1616 ^ self new array: anArray flattened withShape: (self shape: anArray)
1717]
1818
19+ { #category : #' instance creation' }
20+ PMNDArray class >> fromScalar: anInteger [
21+
22+ ^ self new array: {anInteger} withShape: #( )
23+ ]
24+
1925{ #category : #' instance creation' }
2026PMNDArray class >> newWith: anInteger [
2127
@@ -39,11 +45,6 @@ PMNDArray >> = anArray [
3945 & (strides = anArray strides) & (shape = anArray shape)
4046]
4147
42- { #category : #accessing }
43- PMNDArray >> array [
44- ^ array
45- ]
46-
4748{ #category : #' as yet unclassified' }
4849PMNDArray >> array: aFlatArray withShape: aShape [
4950
@@ -53,6 +54,25 @@ PMNDArray >> array: aFlatArray withShape: aShape [
5354 shape ifNotEmpty: [ self updateStrides]
5455]
5556
57+ { #category : #private }
58+ PMNDArray >> asArray [
59+ ^ array
60+ ]
61+
62+ { #category : #public }
63+ PMNDArray >> at: coords [
64+
65+ | position |
66+ position := self flattenedIndexOf: coords.
67+ ^ array at: position
68+ ]
69+
70+ { #category : #initialization }
71+ PMNDArray >> at: coords put: aValue [
72+
73+ array at: (self flattenedIndexOf: coords) put: aValue
74+ ]
75+
5676{ #category : #accessing }
5777PMNDArray >> first [
5878^ first
@@ -77,14 +97,6 @@ PMNDArray >> fromNestedArray: aFlatArray withShape: aShape [
7797 shape ifNotEmpty: [ self updateStrides]
7898]
7999
80- { #category : #public }
81- PMNDArray >> get: coords [
82-
83- | position |
84- position := self flattenedIndexOf: coords.
85- ^ array at: position
86- ]
87-
88100{ #category : #accessing }
89101PMNDArray >> rank [
90102 ^ shape size
@@ -97,12 +109,6 @@ PMNDArray >> reshape: aNewShape [
97109
98110]
99111
100- { #category : #initialization }
101- PMNDArray >> set: coords value: aValue [
102-
103- array at: (self flattenedIndexOf: coords) put: aValue
104- ]
105-
106112{ #category : #accessing }
107113PMNDArray >> shape [
108114
@@ -147,6 +153,6 @@ PMNDArray >> view [
147153{ #category : #' as yet unclassified' }
148154PMNDArray >> viewWithShape: aNewShape [
149155
150- ^ PMNDArray new array: self array withShape: aNewShape
156+ ^ PMNDArray new array: self asArray withShape: aNewShape
151157
152158]
0 commit comments