Skip to content

Commit d738a14

Browse files
authored
Merge pull request #8 from Kotlin/dims
Add scalar, iterator returning view and flat iterator
2 parents c1d4fb8 + bd8648b commit d738a14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+3205
-717
lines changed

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,63 @@ When slicing, this is not necessary.
231231
// 6
232232
```
233233

234+
There are three iterators:
235+
236+
##### [NDIterator](src/main/kotlin/org/jetbrains/numkt/core/KtNDArrayIterator.kt).
237+
Calls a standard Python iterator. Always returns an view. If iteration occurs over a flat array, use the `scalar`
238+
property to obtain the element. If the array is not a scalar, the `null` will be returned. To check, use methods
239+
`isScalar` and `isNotScalar`.
240+
```kotlin
241+
val a = linspace<Double>(0, 10).reshape(2, 5, 5)
242+
243+
// Get ten one-dimensional arrays
244+
for (ax1 in a) {
245+
for (ax2 in ax1) {
246+
println(ax2)
247+
}
248+
}
249+
250+
// Sum of all elements
251+
var sum = 0.0
252+
for (ax1 in a) {
253+
for (ax2 in ax1) {
254+
for (el in ax2) {
255+
sum += el.scalar!!
256+
}
257+
}
258+
}
259+
```
260+
261+
##### [KtNDIter](src/main/kotlin/org/jetbrains/numkt/core/KtNDIter.kt).
262+
This iterator is a mapping of the C array iterator API, like in python `np.nditer`.
263+
It also displays items in the order they are in memory.
264+
```kotlin
265+
val a = arange(6).apply { resize(2, 3) }
266+
267+
// Square each element in the array
268+
val iter = KtNDIter(a)
269+
for (i in iter) {
270+
a[iter.multiIndex] = i * i
271+
}
272+
273+
for (x in KtNDIter(a[None..None, 1..None..-1])) {
274+
print("$x ")
275+
}
276+
```
277+
278+
##### [FlatIterator](src/main/kotlin/org/jetbrains/numkt/core/KtNDArrayIterator.kt).
279+
An iterator directly above the buffer. The fastest of all these iterators. Able to display view. Use method `flatIter`.
280+
281+
```kotlin
282+
val a = linspace<Double>(0, 10)
283+
284+
// Displays all items
285+
for (el in a.flatIter()) {
286+
print("$el ")
287+
}
288+
```
289+
290+
234291
#### Stacking
235292

236293
```kotlin

build.gradle

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ plugins {
2121
id 'maven-publish'
2222

2323
id "com.jfrog.bintray" version "1.8.4"
24+
25+
// Documentation
26+
id 'org.jetbrains.dokka' version '0.10.1'
2427
}
2528

2629
group 'org.jetbrains'
@@ -199,3 +202,42 @@ bintray {
199202
}
200203
}
201204
}
205+
206+
dokka {
207+
outputFormat = 'html'
208+
outputDirectory = "$buildDir/dokka"
209+
210+
configuration {
211+
moduleName = 'kotlin-numpy'
212+
213+
// Use to include or exclude non public members.
214+
includeNonPublic = false
215+
216+
// Do not create index pages for empty packages
217+
skipEmptyPackages = true
218+
219+
// Specifies the location of the project source code on the Web.
220+
// If provided, Dokka generates "source" links for each declaration.
221+
// Repeat for multiple mappings
222+
sourceLink {
223+
// Unix based directory relative path to the root of the project (where you execute gradle respectively).
224+
path = "./"
225+
226+
// URL showing where the source code can be accessed through the web browser
227+
url = "https://github.com/kotlin/kotlin-numpy/tree/master"
228+
//remove src/main/kotlin if you use "./" above
229+
230+
// Suffix which is used to append the line number to the URL. Use #L for GitHub
231+
lineSuffix = "#L"
232+
}
233+
234+
// Used for linking to JDK documentation
235+
jdkVersion = 8
236+
237+
// Disable linking to online kotlin-stdlib documentation
238+
noStdlibLink = false
239+
240+
// Disable linking to online JDK documentation
241+
noJdkLink = false
242+
}
243+
}

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
kotlin.code.style=official
2+
dokka_version=0.10.1
23
version=0.1.3

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy