Skip to content

Commit 68adc3c

Browse files
authored
Remove narr (#61)
* remove arr. * . * . * fmt * .
1 parent e3a5732 commit 68adc3c

74 files changed

Lines changed: 1179 additions & 1270 deletions

Some content is hidden

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

build.mill

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ object V:
3535
val scalaTags: Dep = mvn"com.lihaoyi::scalatags::0.13.1"
3636
val scalaVersion = "3.7.2"
3737
val munitVersion = "1.1.1"
38-
val narr: Dep = mvn"ai.dragonfly::narr::1.0"
3938
val blas: Dep = mvn"dev.ludovic.netlib:blas:3.0.4"
4039
val lapack: Dep = mvn"dev.ludovic.netlib:lapack:3.0.4"
4140
end V

experiments/src/cheatsheet.scala

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import vecxt.all.*
55
import vecxt.BoundsCheck.DoBoundsCheck.no
6-
import narr.*
76

87
object CheatsheetTest:
98

@@ -12,19 +11,19 @@ object CheatsheetTest:
1211

1312
// Array/Vector Creation and Basic Operations
1413
println("--- Array/Vector Creation ---")
15-
val vec = NArray(1.0, 2.0, 3.0)
14+
val vec = Array(1.0, 2.0, 3.0)
1615
println(s"1D array: ${vec.mkString(", ")}")
1716

1817
println((vec ** 2.0).printArr)
1918

20-
val mat = Matrix(NArray(1.0, 2.0, 3.0, 4.0, 5.0, 6.0), 2, 3)
19+
val mat = Matrix(Array(1.0, 2.0, 3.0, 4.0, 5.0, 6.0), 2, 3)
2120
println(s"2D matrix shape: ${mat.shape}")
2221

2322
println(svd(mat))
2423
println(rank(mat))
2524

2625
// QR decomposition
27-
val matSquare = Matrix(NArray(1.0, 2.0, 3.0, 4.0), 2, 2)
26+
val matSquare = Matrix(Array(1.0, 2.0, 3.0, 4.0), 2, 2)
2827
val (q, r) = qr(matSquare)
2928
println(s"Q matrix shape: ${q.shape}")
3029
println(s"R matrix shape: ${r.shape}")
@@ -43,7 +42,7 @@ object CheatsheetTest:
4342

4443
// Indexing and Slicing
4544
println("\n--- Indexing and Slicing ---")
46-
val m = Matrix(NArray(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0), 3, 3)
45+
val m = Matrix(Array(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0), 3, 3)
4746
val mBig = Matrix.rand(10, 10)
4847
m.mean
4948
println("==== m =====")
@@ -65,8 +64,8 @@ object CheatsheetTest:
6564

6665
// Element-wise Operations
6766
println("\n--- Element-wise Operations ---")
68-
val a = NArray(1.0, 2.0, 3.0, 4.0)
69-
val b = NArray(2.0, 3.0, 4.0, 5.0)
67+
val a = Array(1.0, 2.0, 3.0, 4.0)
68+
val b = Array(2.0, 3.0, 4.0, 5.0)
7069

7170
val sum = a + b
7271
println(s"Element-wise addition: ${sum.mkString(", ")}")
@@ -75,8 +74,8 @@ object CheatsheetTest:
7574
println(s"Element-wise subtraction: ${diff.mkString(", ")}")
7675

7776
// Element-wise multiply/divide for matrices
78-
val mA = Matrix(NArray(1.0, 2.0, 3.0, 4.0), 2, 2)
79-
val mB = Matrix(NArray(2.0, 3.0, 4.0, 5.0), 2, 2)
77+
val mA = Matrix(Array(1.0, 2.0, 3.0, 4.0), 2, 2)
78+
val mB = Matrix(Array(2.0, 3.0, 4.0, 5.0), 2, 2)
8079
val mProd = mA.hadamard(mB)
8180
println(s"Element-wise multiply (matrix): shape ${mProd.shape}")
8281

@@ -100,8 +99,8 @@ object CheatsheetTest:
10099

101100
// Matrix Operations
102101
println("\n--- Matrix Operations ---")
103-
val m1 = Matrix(NArray(1.0, 2.0, 3.0, 4.0), 2, 2)
104-
val m2 = Matrix(NArray(5.0, 6.0, 7.0, 8.0), 2, 2)
102+
val m1 = Matrix(Array(1.0, 2.0, 3.0, 4.0), 2, 2)
103+
val m2 = Matrix(Array(5.0, 6.0, 7.0, 8.0), 2, 2)
105104

106105
val mneg = -m1
107106

@@ -115,7 +114,7 @@ object CheatsheetTest:
115114
println(s"Determinant: $det")
116115

117116
// Test matrix with scalar operations
118-
val m3 = Matrix(NArray(1.0, 2.0, 3.0, 4.0, 5.0, 6.0), 2, 3)
117+
val m3 = Matrix(Array(1.0, 2.0, 3.0, 4.0, 5.0, 6.0), 2, 3)
119118
val m3Scaled = m3 * 2.0
120119
println(s"Matrix scaled by 2: shape ${m3Scaled.shape}")
121120

@@ -167,8 +166,8 @@ object CheatsheetTest:
167166

168167
// Norms and Distances
169168
println("\n--- Norms and Distances ---")
170-
val v1 = NArray(1.0, 2.0, 3.0)
171-
val v2 = NArray(4.0, 5.0, 6.0)
169+
val v1 = Array(1.0, 2.0, 3.0)
170+
val v2 = Array(4.0, 5.0, 6.0)
172171
val negv2 = -v2
173172
val cosSim = cosineSimilarity(v1, v2)
174173
println(s"Cosine similarity: $cosSim")
@@ -193,10 +192,10 @@ object CheatsheetTest:
193192
val cosResult = a.cos
194193
println(s"Cosine: ${cosResult.mkString(", ")}")
195194

196-
val asinResult = NArray(0.5, 0.7, 0.9).asin
195+
val asinResult = Array(0.5, 0.7, 0.9).asin
197196
println(s"Arcsine: ${asinResult.mkString(", ")}")
198197

199-
val acosResult = NArray(0.5, 0.7, 0.9).acos
198+
val acosResult = Array(0.5, 0.7, 0.9).acos
200199
println(s"Arccosine: ${acosResult.mkString(", ")}")
201200

202201
val atanResult = a.atan
@@ -228,8 +227,8 @@ object CheatsheetTest:
228227

229228
// Logical Operations
230229
println("\n--- Logical Operations ---")
231-
val intArr1 = NArray(1, 2, 3, 4, 5)
232-
val intArr2 = NArray(3, 2, 3, 1, 6)
230+
val intArr1 = Array(1, 2, 3, 4, 5)
231+
val intArr2 = Array(3, 2, 3, 1, 6)
233232

234233
val gtResult = intArr1 > intArr2
235234
println(s"Greater than: ${gtResult.mkString(", ")}")
@@ -249,8 +248,8 @@ object CheatsheetTest:
249248
val neqResult = intArr1 !:= intArr2
250249
println(s"Inequality: ${neqResult.mkString(", ")}")
251250

252-
val boolArr = NArray(true, false, true, false, true)
253-
val boolArr2 = NArray(false, false, true, true, false)
251+
val boolArr = Array(true, false, true, false, true)
252+
val boolArr2 = Array(false, false, true, true, false)
254253

255254
not(boolArr2)
256255

@@ -266,17 +265,17 @@ object CheatsheetTest:
266265
val diagVals = m.diag
267266
println(s"Diagonal: ${diagVals.mkString(", ")}")
268267

269-
val uniqueVals = NArray(1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 4.0).unique
268+
val uniqueVals = Array(1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 4.0).unique
270269
println(s"Unique values: ${uniqueVals.mkString(", ")}")
271270

272-
val toSort = NArray(3.0, 1.0, 4.0, 1.0, 5.0)
273-
val sorted = narr.copy(toSort)
274-
narr.sort(sorted)()
271+
val toSort = Array(3.0, 1.0, 4.0, 1.0, 5.0)
272+
val sorted = toSort.clone()
273+
scala.util.Sorting.quickSort(sorted)
275274
println(s"Sorted: ${sorted.mkString(", ")}")
276275

277276
// Special Operations
278277
println("\n--- Special Operations ---")
279-
val copied = narr.copy(a)
278+
val copied = a.clone()
280279
println(s"Copied array: ${copied.mkString(", ")}")
281280

282281
val increments = intArr1.increments

experiments/src/mnist.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import vecxt.all.*
99
import vecxt.BoundsCheck.DoBoundsCheck.yes
1010
import vecxt.BoundsCheck
1111
import scala.reflect.ClassTag
12-
import narr.*
1312

1413
// File can be dowloaded from Kaggle at:
1514
// https://www.kaggle.com/datasets/quangphota/mnist-csv/data?select=train.csv
@@ -187,7 +186,7 @@ def back_prop(
187186
end back_prop
188187

189188
inline def oneHot[T](int: Int, numClasses: Int)(using ct: ClassTag[T], f: Numeric[T]): Array[T] =
190-
val arr = NArray.fill[T](numClasses)(f.zero)
189+
val arr = Array.fill[T](numClasses)(f.zero)
191190
if int >= 0 && int < numClasses then arr(int) = f.one
192191
end if
193192
arr

readme.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,10 @@ Freeing you from the tyranny of having to choose which platform you write your c
66

77
## What is it?
88

9-
Aims to provide convienent and intuitive syntax for vector computations with best-in-class inline-shim-to-BLAS performance.
9+
Aims to provide convienent and intuitive syntax for vector computations with best-in-class inline-shim-to-BLAS performance on native and JVM. JS... is waiting for WebAssembly BLAS.
1010

1111
||JVM|JS|Native|
1212
----|----|----|----|
13-
Data structure| `Array[Double]` | `Float64Array` | `Array[Double]` |
13+
Data structure| `Array[Double]` | `Array[Double]` | `Array[Double]` |
1414
Shims to | https://github.com/luhenry/netlib | https://github.com/stdlib-js/blas | [CBLAS](https://github.com/ekrich/sblas) |
1515

16-
## Didn't you say "cross platform"?
17-
18-
This is a very neat piece of work.
19-
https://github.com/dragonfly-ai/narr
20-
21-

site/TODO/benchmarks/performance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ In general cross platform performance is a hard problem. We sidestep where possi
1111

1212
||JVM|JS|Native|Cross|
1313
----|----|----|----|---|
14-
Data structure| `Array[Double]` | `Float64Array` | `Array[Double]` |`NArray[Double]` |
14+
Data structure| `Array[Double]` | `Float64Array` | `Array[Double]` |`Array[Double]` |
1515
Shims to | https://github.com/luhenry/netlib | https://github.com/stdlib-js/blas | [CBLAS](https://github.com/ekrich/sblas) | Best available |
1616

1717
Consider browsing the [[vecxt]] api, and particulaly the extensions object. You'll see that most definitions are `@inline` anotated - i.e. there is zero runtime overhead calling this library, and checkout the [benchmarks](benchmarks/sum.md)

site/docs/blog/2024-08-01-Motivation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ For example if your data acquisition is serverside, but do parts of a calculatio
2222
```scala mdoc
2323

2424
import vecxt.all.*
25-
import narr.*
25+
2626
import vecxt.BoundsCheck.DoBoundsCheck.yes
2727

28-
def algo(a: NArray[Double], b :NArray[Double], c: Double ) = (a + b) / c
28+
def algo(a: Array[Double], b :Array[Double], c: Double ) = (a + b) / c
2929

3030
val a = Array[Double](1, 2, 3)
3131
val b = Array[Double](4, 5, 6)

site/docs/blog/2025-06-23-Linear_Algebra_On_the_JVM.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ So okay... I'm totally a sucker for punishment. We need zero copy transpose - ho
7272

7373
```scala sc:nocompile
7474
class Matrix[A] (
75-
val raw: NArray[A],
75+
val raw: Array[A],
7676
val rows: Row,
7777
val cols: Col,
7878
val rowStride: Int,

site/docs/cheatsheet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This cheatsheet compares common linear algebra operations across vecxt (Scala 3)
77
```scala
88
//> using scala 3.7.3 // or greater
99
import vecxt.all.{*, given}
10-
import narr.*
10+
1111

1212
```
1313

site/docs/examples.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ And Ints. Note that the API here is more limited at the moment.
103103

104104
```scala mdoc:reset
105105
import vecxt.all.{*, given}
106-
import narr.*
107106

108-
val v1 = NArray(1, 2, 3)
109-
val v2 = NArray(4, 5, 6)
107+
108+
val v1 = Array(1, 2, 3)
109+
val v2 = Array(4, 5, 6)
110110

111111

112112
v1.dot(v2)
@@ -131,11 +131,11 @@ The library includes methods for calculating Tail Value at Risk (TVaR) and Value
131131

132132
```scala mdoc:reset
133133
import vecxt.all.{*, given}
134-
import narr.*
134+
135135
import vecxt.reinsurance.*
136136

137137
// Create a sample loss distribution
138-
val losses = NArray[Double](10.0, 25.0, 15.0, 50.0, 5.0, 30.0, 20.0, 8.0, 45.0, 12.0)
138+
val losses = Array[Double](10.0, 25.0, 15.0, 50.0, 5.0, 30.0, 20.0, 8.0, 45.0, 12.0)
139139

140140
// Calculate Value at Risk (VaR) at 90% confidence level
141141
// VaR represents the threshold value - 90% of losses are above this value
@@ -152,7 +152,7 @@ val varValue = result.VaR
152152
val tvarValue = result.TVaR
153153

154154
// Calculate multiple confidence levels at once (most efficient for batch analysis)
155-
val alphas = NArray[Double](0.85, 0.90, 0.95, 0.99)
155+
val alphas = Array[Double](0.85, 0.90, 0.95, 0.99)
156156
val results = losses.tVarWithVaRBatch(alphas)
157157
// Each result contains (cl, VaR, TVaR)
158158
results(0).cl // Confidence level for first alpha
@@ -165,8 +165,8 @@ val tailMask = losses.tVarIdx(0.90)
165165

166166
// Calculate tail dependence between two distributions
167167
// Measures how often extreme values occur together
168-
val losses1 = NArray[Double](5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0)
169-
val losses2 = NArray[Double](8.0, 12.0, 18.0, 22.0, 28.0, 32.0, 38.0, 42.0, 48.0, 52.0)
168+
val losses1 = Array[Double](5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0)
169+
val losses2 = Array[Double](8.0, 12.0, 18.0, 22.0, 28.0, 32.0, 38.0, 42.0, 48.0, 52.0)
170170
val tailDep = losses1.qdep(0.90, losses2)
171171
// Returns proportion of tail observations that are shared (0.0 to 1.0)
172172

site/docs/higherkinded.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import scala.reflect.ClassTag
1717
import vecxt.*
1818
import vecxt.all.*
1919
import vecxt.BoundsCheck.BoundsCheck
20-
import narr.*
20+
2121
import BoundsCheck.DoBoundsCheck.yes
2222

2323
// A very naive matrix multiplication implementation...
@@ -31,7 +31,7 @@ object SpireExt:
3131
val (r1, c1) = m1.shape
3232
val (r2, c2) = m2.shape
3333

34-
val nar = NArray.ofSize[A](r1 * c2)
34+
val nar = Array.ofDim[A](r1 * c2)
3535
val res = Matrix(nar, (r1, c2))
3636

3737
for i <- 0 until r1 do
@@ -66,14 +66,14 @@ import SpireExt.*
6666

6767
// That would work with complex numbers
6868
val mat1 = Matrix.fromRows[Complex[Double]](
69-
NArray[Complex[Double]](Complex(1.0, -1.0), Complex(0.0, 2.0), Complex(-2.0, 1.0)),
70-
NArray[Complex[Double]](Complex(0.0, -3.0), Complex(3.0, -2.0), Complex(-1.0, -1.0))
69+
Array[Complex[Double]](Complex(1.0, -1.0), Complex(0.0, 2.0), Complex(-2.0, 1.0)),
70+
Array[Complex[Double]](Complex(0.0, -3.0), Complex(3.0, -2.0), Complex(-1.0, -1.0))
7171
)
7272

7373
val mat2 = Matrix.fromRows[Complex[Double]](
74-
NArray[Complex[Double]](Complex(0.0, -2.0), Complex(1.0, -4.0)),
75-
NArray[Complex[Double]](Complex(-1.0, 3.0), Complex(2.0, -3.0)),
76-
NArray[Complex[Double]](Complex(-2.0, 1.0), Complex(-4.0, 1.0))
74+
Array[Complex[Double]](Complex(0.0, -2.0), Complex(1.0, -4.0)),
75+
Array[Complex[Double]](Complex(-1.0, 3.0), Complex(2.0, -3.0)),
76+
Array[Complex[Double]](Complex(-2.0, 1.0), Complex(-4.0, 1.0))
7777
)
7878

7979
println(mat1.showMat)

0 commit comments

Comments
 (0)