Skip to content

Commit 8e75013

Browse files
committed
Add initial implementation of refactoring to composable tensors.
Related-To: #126
1 parent d88e812 commit 8e75013

28 files changed

Lines changed: 3262 additions & 656 deletions

File tree

docs/divio-explanation.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# How to write “Explanation” (discussion) docs
2+
3+
Below is a procedural guideline / checklist that an AI (or human writer) should follow when asked to write an “explanation” style document in a larger documentation system.
4+
5+
1. Decide the topic boundary / scope
6+
7+
Choose a topic that merits a deeper dive — something that benefits from understanding rationale, trade-offs, alternatives, history, or context.
8+
9+
Avoid topics that are already covered well in “how-to” or “reference” docs, unless you are elaborating the “why behind them.”
10+
11+
Define the intended audience: users who already know the basics and want more insight.
12+
13+
Limit the scope: don’t try to explain everything, just pick one coherent theme or area (e.g. “caching strategies for the platform,” or “why environment variables are handled this way”).
14+
15+
2. Provide context and motivation
16+
17+
Start with why this topic matters: what problem, challenge or question it addresses.
18+
19+
Give background: prior states, constraints, historical evolution — how did we arrive here?
20+
21+
Define key concepts or terminology as needed (briefly, without turning into a reference).
22+
23+
3. Explore alternatives (and trade-offs)
24+
25+
Describe possible different approaches or designs, even those not chosen.
26+
27+
Compare and contrast: pros, cons, when one might be more suitable than another.
28+
29+
If opinions or community debates exist, mention them, present reasoning for different sides.
30+
31+
4. Explain rationale and design decisions
32+
33+
For each major choice, explain why it was made (constraints, priorities, trade-offs).
34+
35+
If there are technical constraints (performance, security, backwards compatibility, user expectations), surface them.
36+
37+
Where appropriate, show consequences (positive and negative) of choices.
38+
39+
5. Include illustrative examples or metaphors
40+
41+
Use analogies, metaphors, or stories to help understanding (as Divio uses “cooking” as an analogy)
42+
docs.divio.com
43+
44+
Use diagrams or conceptual visuals if helpful (to illustrate relationships, flows, architecture).
45+
46+
6. Maintain a discursive style (not instructional)
47+
48+
Do not give explicit “step 1, do this; step 2, do that” instructions.
49+
50+
Do not list API syntax, method signatures, or detailed parameters (those belong in reference).
51+
52+
Use more narrative style: “we think about …”, “alternatively …”, “one could consider …”.
53+
54+
7. Structure the document logically
55+
56+
Use headings/subheadings (e.g. “Motivation / Background”, “Alternatives”, “Rationale”, “Examples / Illustrations”, “Implications”).
57+
58+
Progress from general → specific: first big picture, then deeper dives.
59+
60+
You might end with “When this is useful / implications / further reading”.
61+
62+
8. Link to related docs
63+
64+
Provide references (links) to corresponding how-to guides, reference pages, or deeper technical specs.
65+
66+
Encourage the reader to “see also” for performing actions, APIs, or tutorials.
67+
68+
9. Be neutral, clear, and well-reasoned
69+
70+
If you present multiple opinions, try to balance them fairly; if you prefer one, explain why.
71+
72+
Avoid jargon without explanation.
73+
74+
Keep paragraphs reasonably sized; use examples to break up abstract discussion.
75+
76+
10. Review for scope creep and redundancy
77+
78+
Check that you didn’t slip back into instructional or reference mode — if there is instruction, consider moving it to a how-to.
79+
80+
Ensure you didn’t duplicate content from tutorials or reference; if overlap, prefer referencing instead of rehashing.

settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ rootProject.name = "SKaiNET"
1717

1818
include("skainet-core:skainet-tensors-api")
1919
include("skainet-core:skainet-tensors")
20+
include("skainet-core:skainet-tensor-data")
21+
include("skainet-core:skainet-tensor-ops")
2022
include("skainet-core:skainet-performance")
2123
include("skainet-core:skainet-core-reflection")
2224
include("skainet-nn:skainet-nn-api")
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
2+
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
3+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
4+
5+
plugins {
6+
alias(libs.plugins.kotlinMultiplatform)
7+
alias(libs.plugins.androidLibrary)
8+
alias(libs.plugins.vanniktech.mavenPublish)
9+
alias(libs.plugins.kover)
10+
}
11+
12+
kotlin {
13+
explicitApi()
14+
15+
androidTarget {
16+
@OptIn(ExperimentalKotlinGradlePluginApi::class)
17+
compilerOptions {
18+
jvmTarget.set(JvmTarget.JVM_11)
19+
}
20+
}
21+
22+
iosArm64()
23+
iosSimulatorArm64()
24+
macosArm64 ()
25+
linuxX64 ()
26+
linuxArm64 ()
27+
28+
jvm()
29+
30+
@OptIn(ExperimentalWasmDsl::class)
31+
wasmJs {
32+
browser()
33+
binaries.executable()
34+
}
35+
36+
sourceSets {
37+
commonTest.dependencies {
38+
implementation(libs.kotlin.test)
39+
}
40+
}
41+
}
42+
43+
android {
44+
namespace = "sk.ai.net.core.tensor.data"
45+
compileSdk = libs.versions.android.compileSdk.get().toInt()
46+
47+
defaultConfig {
48+
minSdk = libs.versions.android.minSdk.get().toInt()
49+
}
50+
compileOptions {
51+
sourceCompatibility = JavaVersion.VERSION_11
52+
targetCompatibility = JavaVersion.VERSION_11
53+
}
54+
}

skainet-core/skainet-tensors-api/src/commonMain/kotlin/sk/ainet/core/tensor/BroadcastTensorData.kt renamed to skainet-core/skainet-tensor-data/src/commonMain/kotlin/sk/ainet/core/tensor/BroadcastTensorData.kt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -194,22 +194,6 @@ public class BroadcastTensorData<T : DType, V>(
194194
return indices
195195
}
196196

197-
/**
198-
* Computes standard row-major strides for the given shape.
199-
*/
200-
private fun Shape.computeStrides(): IntArray {
201-
if (dimensions.isEmpty()) return intArrayOf()
202-
203-
val strides = IntArray(dimensions.size)
204-
strides[dimensions.size - 1] = 1
205-
206-
for (i in dimensions.size - 2 downTo 0) {
207-
strides[i] = strides[i + 1] * dimensions[i + 1]
208-
}
209-
210-
return strides
211-
}
212-
213197
/**
214198
* Checks if sourceShape can be broadcast to targetShape.
215199
*/

skainet-core/skainet-tensors-api/src/commonMain/kotlin/sk/ainet/core/tensor/ContiguousTensorData.kt renamed to skainet-core/skainet-tensor-data/src/commonMain/kotlin/sk/ainet/core/tensor/ContiguousTensorData.kt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,3 @@ public class ContiguousTensorData<T : DType, V>(
7979
return this
8080
}
8181
}
82-
83-
/**
84-
* Computes standard row-major strides for the given shape.
85-
*/
86-
private fun Shape.computeStrides(): IntArray {
87-
if (dimensions.isEmpty()) return intArrayOf()
88-
89-
val strides = IntArray(dimensions.size)
90-
strides[dimensions.size - 1] = 1
91-
92-
for (i in dimensions.size - 2 downTo 0) {
93-
strides[i] = strides[i + 1] * dimensions[i + 1]
94-
}
95-
96-
return strides
97-
}

skainet-core/skainet-tensors-api/src/commonMain/kotlin/sk/ainet/core/tensor/DType.kt renamed to skainet-core/skainet-tensor-data/src/commonMain/kotlin/sk/ainet/core/tensor/DType.kt

File renamed without changes.

skainet-core/skainet-tensors-api/src/commonMain/kotlin/sk/ainet/core/tensor/DenseTensorData.kt renamed to skainet-core/skainet-tensor-data/src/commonMain/kotlin/sk/ainet/core/tensor/DenseTensorData.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public class DenseTensorData<T : DType, V>(
9999
/**
100100
* Computes standard row-major strides for the given shape.
101101
*/
102-
private fun Shape.computeStrides(): IntArray {
102+
internal fun Shape.computeStrides(): IntArray {
103103
if (dimensions.isEmpty()) return intArrayOf()
104104

105105
val strides = IntArray(dimensions.size)

skainet-core/skainet-tensors-api/src/commonMain/kotlin/sk/ainet/core/tensor/Shape.kt renamed to skainet-core/skainet-tensor-data/src/commonMain/kotlin/sk/ainet/core/tensor/Shape.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ internal inline fun assert(value: () -> Boolean, lazyMessage: () -> Any) {
5959
val message = lazyMessage()
6060
throw AssertionError(message)
6161
}
62-
}
62+
}

skainet-core/skainet-tensors-api/src/commonMain/kotlin/sk/ainet/core/tensor/TensorData.kt renamed to skainet-core/skainet-tensor-data/src/commonMain/kotlin/sk/ainet/core/tensor/TensorData.kt

File renamed without changes.

skainet-core/skainet-tensors-api/src/commonMain/kotlin/sk/ainet/core/tensor/TransposeTensorData.kt renamed to skainet-core/skainet-tensor-data/src/commonMain/kotlin/sk/ainet/core/tensor/TransposeTensorData.kt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -153,22 +153,6 @@ public class TransposeTensorData<T : DType, V>(
153153
return indices
154154
}
155155

156-
/**
157-
* Computes standard row-major strides for the given shape.
158-
*/
159-
private fun Shape.computeStrides(): IntArray {
160-
if (dimensions.isEmpty()) return intArrayOf()
161-
162-
val strides = IntArray(dimensions.size)
163-
strides[dimensions.size - 1] = 1
164-
165-
for (i in dimensions.size - 2 downTo 0) {
166-
strides[i] = strides[i + 1] * dimensions[i + 1]
167-
}
168-
169-
return strides
170-
}
171-
172156
public companion object {
173157
/**
174158
* Creates a transpose that swaps the last two dimensions (common matrix transpose).

0 commit comments

Comments
 (0)