Skip to content

Commit 4e84b0b

Browse files
committed
add some kdocs
1 parent cea077d commit 4e84b0b

File tree

14 files changed

+199
-7
lines changed

14 files changed

+199
-7
lines changed

multik-api/src/main/kotlin/org/jetbrains/kotlinx/multik/api/CreateNDArray.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public fun <T, D : Dimension> Multik.empty(dims: IntArray, dtype: DataType): NDA
4747
return NDArray(data, shape = dims, dim = dim)
4848
}
4949

50+
/**
51+
* Returns a new zero array of type [T] with the specified shape.
52+
*/
5053
public inline fun <reified T : Any> Multik.zeros(dim1: Int): D1Array<T> =
5154
zeros(intArrayOf(dim1), DataType.ofKClass(T::class))
5255

@@ -72,6 +75,9 @@ public fun <T, D : Dimension> Multik.zeros(dims: IntArray, dtype: DataType): NDA
7275
return NDArray(data, shape = dims, dim = dim)
7376
}
7477

78+
/**
79+
* Returns a new ones array of type [T] with the specified shape.
80+
*/
7581
public inline fun <reified T : Any> Multik.ones(dim1: Int): D1Array<T> =
7682
zeros(intArrayOf(dim1), DataType.ofKClass(T::class))
7783

@@ -1518,21 +1524,39 @@ public fun <T : Number> Iterable<T>.toNDArray(): D1Array<T> = this.toCommonNDArr
15181524
@JvmName("toComplexNDArray")
15191525
public fun <T : Complex> Iterable<T>.toNDArray(): D1Array<T> = this.toCommonNDArray()
15201526

1527+
/**
1528+
* Returns [D2Array] containing all elements.
1529+
*/
15211530
@JvmName("List2DToNDArrayNumber")
15221531
public inline fun <reified T : Number> List<List<T>>.toNDArray(): D2Array<T> = Multik.ndarray(this)
15231532

1533+
/**
1534+
* Returns [D2Array] containing all elements.
1535+
*/
15241536
@JvmName("List2DToNDArrayComplex")
15251537
public inline fun <reified T : Complex> List<List<T>>.toNDArray(): D2Array<T> = Multik.ndarray(this)
15261538

1539+
/**
1540+
* Returns [D3Array] containing all elements.
1541+
*/
15271542
@JvmName("List3DToNDArrayNumber")
15281543
public inline fun <reified T : Number> List<List<List<T>>>.toNDArray(): D3Array<T> = Multik.ndarray(this)
15291544

1545+
/**
1546+
* Returns [D3Array] containing all elements.
1547+
*/
15301548
@JvmName("List3DToNDArrayComplex")
15311549
public inline fun <reified T : Complex> List<List<List<T>>>.toNDArray(): D3Array<T> = Multik.ndarray(this)
15321550

1551+
/**
1552+
* Returns [D4Array] containing all elements.
1553+
*/
15331554
@JvmName("List4DToNDArrayNumber")
15341555
public inline fun <reified T : Number> List<List<List<List<T>>>>.toNDArray(): D4Array<T> = Multik.ndarray(this)
15351556

1557+
/**
1558+
* Returns [D4Array] containing all elements.
1559+
*/
15361560
@JvmName("List4DToNDArrayComplex")
15371561
public inline fun <reified T : Complex> List<List<List<List<T>>>>.toNDArray(): D4Array<T> = Multik.ndarray(this)
15381562

multik-api/src/main/kotlin/org/jetbrains/kotlinx/multik/api/io/csv.kt

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,27 @@ import java.io.*
1414
import java.nio.charset.Charset
1515
import java.util.zip.GZIPInputStream
1616

17+
/**
18+
* Returns an NDArray of type [T] and [D] dimension read from csv file.
19+
* @param T NDArray element type
20+
* @param D dimension of NDArray. It can be 1 or 2
21+
* @param fileName file path including file name and extensions
22+
* @param delimiter separator between elements
23+
* @param charset character encoding, by default is UTF_8
24+
*/
1725
public inline fun <reified T : Any, reified D : Dim2> Multik.read(
1826
fileName: String, delimiter: Char = ',', charset: Charset = Charsets.UTF_8
1927
): NDArray<T, D> = read(fileName, DataType.ofKClass(T::class), dimensionClassOf<D>(), delimiter, charset)
2028

29+
/**
30+
* Returns an NDArray of type [T] and [D] dimension read from csv file.
31+
* @param T NDArray element type
32+
* @param D dimension of NDArray. It can be 1 or 2
33+
* @param fileName file path including file name and extensions
34+
* @param dtype NDArray element type
35+
* @param delimiter separator between elements
36+
* @param charset character encoding, by default is UTF_8
37+
*/
2138
public fun <T, D : Dim2> Multik.read(
2239
fileName: String, dtype: DataType, dim: Dim2,
2340
delimiter: Char = ',', charset: Charset = Charsets.UTF_8
@@ -27,6 +44,14 @@ public fun <T, D : Dim2> Multik.read(
2744
return read(file, dtype, dim, delimiter, charset)
2845
}
2946

47+
/**
48+
* Returns a raw array of dimension 2. The type casts to either [Double] or [ComplexDouble].
49+
* @param fileName file path including file name and extensions
50+
* @param dtype NDArray element type
51+
* @param dim dimension of NDArray
52+
* @param delimiter separator between elements
53+
* @param charset character encoding, by default is UTF_8
54+
*/
3055
public fun Multik.readRaw(
3156
fileName: String, dtype: DataType? = null, dim: Dim2? = null,
3257
delimiter: Char = ',', charset: Charset = Charsets.UTF_8
@@ -36,23 +61,57 @@ public fun Multik.readRaw(
3661
return readRaw(file, dtype, dim, delimiter, charset)
3762
}
3863

64+
/**
65+
* Returns an NDArray of type [T] and [D] dimension read from csv file.
66+
* @param T NDArray element type
67+
* @param D dimension of NDArray. It can be 1 or 2
68+
* @param file csv file
69+
* @param delimiter separator between elements
70+
* @param charset character encoding, by default is UTF_8
71+
*/
3972
public inline fun <reified T : Any, reified D : Dim2> Multik.read(
4073
file: File, delimiter: Char = ',', charset: Charset = Charsets.UTF_8
4174
): NDArray<T, D> = read(file, DataType.ofKClass(T::class), dimensionClassOf<D>(), delimiter, charset)
4275

76+
/**
77+
* Returns an NDArray of type [T] and [D] dimension read from csv file.
78+
* @param T NDArray element type
79+
* @param D dimension of NDArray. It can be 1 or 2
80+
* @param dtype NDArray element type
81+
* @param file csv file
82+
* @param delimiter separator between elements
83+
* @param charset character encoding, by default is UTF_8
84+
*/
4385
public fun <T, D : Dim2> Multik.read(
4486
file: File, dtype: DataType, dim: Dim2,
4587
delimiter: Char = ',', charset: Charset = Charsets.UTF_8
4688
): NDArray<T, D> =
4789
readDelim(FileInputStream(file), dtype, dim, delimiter, charset, isCompressed(file))
4890

91+
/**
92+
* Returns a raw array of dimension 2. The type casts to either [Double] or [ComplexDouble].
93+
* @param file csv file
94+
* @param dtype NDArray element type
95+
* @param dim dimension of NDArray
96+
* @param delimiter separator between elements
97+
* @param charset character encoding, by default is UTF_8
98+
*/
4999
public fun Multik.readRaw(
50100
file: File, dtype: DataType? = null, dim: Dim2? = null,
51101
delimiter: Char = ',', charset: Charset = Charsets.UTF_8
52102
): NDArray<*, D2> =
53103
readDelim<Any, D2>(FileInputStream(file), dtype, dim, delimiter, charset, isCompressed(file))
54104

55-
105+
/**
106+
* Returns an NDArray of type [T] and [D] dimension read from csv file.
107+
* @param T NDArray element type
108+
* @param D dimension of NDArray. It can be 1 or 2
109+
* @param inStream data input stream from file
110+
* @param dtype NDArray element type
111+
* @param dim dimension of NDArray
112+
* @param delimiter separator between elements
113+
* @param isCompressed shows whether the data is compressed, by default is false
114+
*/
56115
public fun <T, D : Dim2> Multik.readDelim(
57116
inStream: InputStream, dtype: DataType?, dim: Dim2?,
58117
delimiter: Char = ',', charset: Charset, isCompressed: Boolean = false
@@ -65,6 +124,15 @@ public fun <T, D : Dim2> Multik.readDelim(
65124
readDelim(this, CSVFormat.Builder.create(CSVFormat.DEFAULT).setDelimiter(delimiter).build(), dtype, dim)
66125
}
67126

127+
/**
128+
* Returns an NDArray of type [T] and [D] dimension read from csv file.
129+
* @param T NDArray element type
130+
* @param D dimension of NDArray. It can be 1 or 2
131+
* @param reader reading character-input streams
132+
* @param format csv format from apache
133+
* @param dtype NDArray element type
134+
* @param dim dimension of NDArray
135+
*/
68136
public fun <T, D : Dim2> Multik.readDelim(
69137
reader: Reader, format: CSVFormat = CSVFormat.DEFAULT,
70138
dtype: DataType?, dim: Dim2?
@@ -134,12 +202,34 @@ private fun String.toComplexFloat(): ComplexFloat {
134202

135203
private fun isCompressed(file: File) = listOf("gz", "zip").contains(file.extension)
136204

205+
/**
206+
* Writes an NDArray to csv file. The NDArray must be up to the second dimension.
207+
* @param T NDArray element type
208+
* @param D dimension of NDArray. It can be 1 or 2
209+
* @param file file where the data will be written, if the file does not exist, it will be created
210+
* @param delimiter separator between elements
211+
*/
137212
public fun <T, D : Dim2> Multik.write(file: File, ndarray: NDArray<T, D>, delimiter: Char = ','): Unit =
138213
writeCSV(FileWriter(file), ndarray, CSVFormat.Builder.create(CSVFormat.DEFAULT).setDelimiter(delimiter).build())
139214

215+
/**
216+
* Writes an NDArray to csv file. The NDArray must be up to the second dimension.
217+
* @param T NDArray element type
218+
* @param D dimension of NDArray. It can be 1 or 2
219+
* @param path file path where the data will be written
220+
* @param delimiter separator between elements
221+
*/
140222
public fun <T, D : Dim2> Multik.write(path: String, ndarray: NDArray<T, D>, delimiter: Char = ','): Unit =
141223
writeCSV(FileWriter(path), ndarray, CSVFormat.Builder.create(CSVFormat.DEFAULT).setDelimiter(delimiter).build())
142224

225+
/**
226+
* Returns an NDArray of type [T] and [D] dimension read from csv file.
227+
* @param T NDArray element type
228+
* @param D dimension of NDArray. It can be 1 or 2
229+
* @param writer
230+
* @param ndarray array of data
231+
* @param format csv format from apache
232+
*/
143233
public fun <T, D : Dim2> Multik.writeCSV(
144234
writer: Appendable,
145235
ndarray: NDArray<T, D>,

multik-api/src/main/kotlin/org/jetbrains/kotlinx/multik/api/linalg/LinAlgEx.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import org.jetbrains.kotlinx.multik.ndarray.complex.ComplexDouble
99
import org.jetbrains.kotlinx.multik.ndarray.complex.ComplexFloat
1010
import org.jetbrains.kotlinx.multik.ndarray.data.*
1111

12+
/**
13+
* Extension interface for [LinAlg] for improved type support.
14+
*/
1215
public interface LinAlgEx {
1316
public fun <T : Number> inv(mat: MultiArray<T, D2>): NDArray<Double, D2>
1417
public fun invF(mat: MultiArray<Float, D2>): NDArray<Float, D2>

multik-api/src/main/kotlin/org/jetbrains/kotlinx/multik/api/linalg/dot.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,37 @@ import org.jetbrains.kotlinx.multik.ndarray.data.MultiArray
1111
import org.jetbrains.kotlinx.multik.ndarray.data.NDArray
1212

1313
/**
14-
* Dot products of two arrays. Matrix product.
14+
* Dot products of two number matrices.
1515
*/
1616
@JvmName("dotMMNumber")
1717
public fun <T : Number> LinAlg.dot(a: MultiArray<T, D2>, b: MultiArray<T, D2>): NDArray<T, D2> = this.linAlgEx.dotMM(a, b)
1818

19+
/**
20+
* Dot products of two complex matrices.
21+
*/
1922
@JvmName("dotMMComplex")
2023
public fun <T : Complex> LinAlg.dot(a: MultiArray<T, D2>, b: MultiArray<T, D2>): NDArray<T, D2> = this.linAlgEx.dotMMComplex(a, b)
2124

2225
/**
23-
* Dot products of two arrays. Matrix product.
26+
* Dot products of number matrix and number vector.
2427
*/
2528
@JvmName("dotMVNumber")
2629
public fun <T : Number> LinAlg.dot(a: MultiArray<T, D2>, b: MultiArray<T, D1>): NDArray<T, D1> = this.linAlgEx.dotMV(a, b)
2730

31+
/**
32+
* Dot products of complex matrix and complex vector.
33+
*/
2834
@JvmName("dotMVComplex")
2935
public fun <T : Complex> LinAlg.dot(a: MultiArray<T, D2>, b: MultiArray<T, D1>): NDArray<T, D1> = this.linAlgEx.dotMVComplex(a, b)
3036

3137
/**
32-
* Dot products of two one-dimensional arrays. Scalar product.
38+
* Dot products of two number vectors. Scalar product.
3339
*/
3440
@JvmName("dotVVNumber")
3541
public fun <T : Number> LinAlg.dot(a: MultiArray<T, D1>, b: MultiArray<T, D1>): T = this.linAlgEx.dotVV(a, b)
3642

43+
/**
44+
* Dot products of two complex vectors. Scalar product.
45+
*/
3746
@JvmName("dotVVComplex")
3847
public fun <T : Complex> LinAlg.dot(a: MultiArray<T, D1>, b: MultiArray<T, D1>): T = this.linAlgEx.dotVVComplex(a, b)

multik-api/src/main/kotlin/org/jetbrains/kotlinx/multik/api/linalg/eigvals.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,47 @@ import org.jetbrains.kotlinx.multik.ndarray.data.D2
1212
import org.jetbrains.kotlinx.multik.ndarray.data.D2Array
1313
import org.jetbrains.kotlinx.multik.ndarray.data.MultiArray
1414

15+
/**
16+
* Calculates the eigenvalues and eigenvectors of a float matrix
17+
* @return a pair of a vector of eigenvalues and a matrix of eigenvectors
18+
*/
1519
@JvmName("eigF")
1620
public fun LinAlg.eig(mat: MultiArray<Float, D2>): Pair<D1Array<ComplexFloat>, D2Array<ComplexFloat>> =
1721
this.linAlgEx.eigF(mat)
1822

23+
/**
24+
* Calculates the eigenvalues and eigenvectors of a numeric matrix
25+
* @return a pair of a vector of eigenvalues and a matrix of eigenvectors
26+
*/
1927
@JvmName("eig")
2028
public fun <T : Number> LinAlg.eig(mat: MultiArray<T, D2>): Pair<D1Array<ComplexDouble>, D2Array<ComplexDouble>> =
2129
this.linAlgEx.eig(mat)
2230

31+
/**
32+
* Calculates the eigenvalues and eigenvectors of a complex matrix
33+
* @return a pair of a vector of eigenvalues and a matrix of eigenvectors
34+
*/
2335
@JvmName("eigC")
2436
public fun <T : Complex> LinAlg.eig(mat: MultiArray<T, D2>): Pair<D1Array<T>, D2Array<T>> =
2537
this.linAlgEx.eigC(mat)
2638

39+
/**
40+
* Calculates the eigenvalues of a float matrix
41+
* @return [ComplexFloat] vector
42+
*/
2743
@JvmName("eigValsF")
2844
public fun LinAlg.eigVals(mat: MultiArray<Float, D2>): D1Array<ComplexFloat> = this.linAlgEx.eigValsF(mat)
2945

46+
/**
47+
* Calculates the eigenvalues of a numeric matrix.
48+
* @return [ComplexDouble] vector
49+
*/
3050
@JvmName("eigVals")
3151
public fun <T : Number> LinAlg.eigVals(mat: MultiArray<T, D2>): D1Array<ComplexDouble> = this.linAlgEx.eigVals(mat)
3252

53+
/**
54+
* Calculates the eigenvalues of a float matrix
55+
* @return complex vector
56+
*/
3357
@JvmName("eigValsC")
3458
public fun <T : Complex> LinAlg.eigVals(mat: MultiArray<T, D2>): D1Array<T> = this.linAlgEx.eigValsC(mat)

multik-api/src/main/kotlin/org/jetbrains/kotlinx/multik/api/linalg/inverse.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,20 @@ import org.jetbrains.kotlinx.multik.ndarray.data.D2
99
import org.jetbrains.kotlinx.multik.ndarray.data.MultiArray
1010
import org.jetbrains.kotlinx.multik.ndarray.data.NDArray
1111

12+
/**
13+
* Returns inverse float matrix
14+
*/
1215
@JvmName("invF")
1316
public fun LinAlg.inv(mat: MultiArray<Float, D2>): NDArray<Float, D2> = this.linAlgEx.invF(mat)
1417

18+
/**
19+
* Returns inverse of a double matrix from numeric matrix
20+
*/
1521
@JvmName("invD")
1622
public fun <T : Number> LinAlg.inv(mat: MultiArray<T, D2>): NDArray<Double, D2> = this.linAlgEx.inv(mat)
1723

24+
/**
25+
* Returns inverse complex matrix
26+
*/
1827
@JvmName("invC")
1928
public fun <T : Complex> LinAlg.inv(mat: MultiArray<T, D2>): NDArray<T, D2> = this.linAlgEx.invC(mat)

multik-api/src/main/kotlin/org/jetbrains/kotlinx/multik/api/linalg/plu.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,20 @@ import org.jetbrains.kotlinx.multik.ndarray.data.D2
99
import org.jetbrains.kotlinx.multik.ndarray.data.D2Array
1010
import org.jetbrains.kotlinx.multik.ndarray.data.MultiArray
1111

12+
/**
13+
* Returns PLU decomposition of the float matrix
14+
*/
1215
@JvmName("pluF")
1316
public fun LinAlg.plu(mat: MultiArray<Float, D2>): Triple<D2Array<Float>, D2Array<Float>, D2Array<Float>> = this.linAlgEx.pluF(mat)
1417

18+
/**
19+
* Returns PLU decomposition of the numeric matrix
20+
*/
1521
@JvmName("pluD")
1622
public fun <T : Number> LinAlg.plu(mat: MultiArray<T, D2>): Triple<D2Array<Double>, D2Array<Double>, D2Array<Double>> = this.linAlgEx.plu(mat)
1723

24+
/**
25+
* Returns PLU decomposition of the complex matrix
26+
*/
1827
@JvmName("pluC")
1928
public fun <T : Complex> LinAlg.plu(mat: MultiArray<T, D2>): Triple<D2Array<T>, D2Array<T>, D2Array<T>> = this.linAlgEx.pluC(mat)

multik-api/src/main/kotlin/org/jetbrains/kotlinx/multik/api/linalg/qr.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,20 @@ import org.jetbrains.kotlinx.multik.ndarray.data.D2
99
import org.jetbrains.kotlinx.multik.ndarray.data.D2Array
1010
import org.jetbrains.kotlinx.multik.ndarray.data.MultiArray
1111

12+
/**
13+
* Returns QR decomposition of the float matrix
14+
*/
1215
@JvmName("qrF")
1316
public fun LinAlg.qr(mat: MultiArray<Float, D2>): Pair<D2Array<Float>, D2Array<Float>> = this.linAlgEx.qrF(mat)
1417

18+
/**
19+
* Returns QR decomposition of the numeric matrix
20+
*/
1521
@JvmName("qrD")
1622
public fun <T : Number> LinAlg.qr(mat: MultiArray<T, D2>): Pair<D2Array<Double>, D2Array<Double>> = this.linAlgEx.qr(mat)
1723

24+
/**
25+
* Returns QR decomposition of the complex matrix
26+
*/
1827
@JvmName("qrC")
1928
public fun <T : Complex> LinAlg.qr(mat: MultiArray<T, D2>): Pair<D2Array<T>, D2Array<T>> = this.linAlgEx.qrC(mat)

multik-api/src/main/kotlin/org/jetbrains/kotlinx/multik/api/linalg/solve.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import org.jetbrains.kotlinx.multik.ndarray.data.Dim2
1010
import org.jetbrains.kotlinx.multik.ndarray.data.MultiArray
1111
import org.jetbrains.kotlinx.multik.ndarray.data.NDArray
1212

13+
/**
14+
* Returns the solution to a system of linear equations
15+
*/
1316
@JvmName("solveF")
1417
public fun <D : Dim2> LinAlg.solve(a: MultiArray<Float, D2>, b: MultiArray<Float, D>): NDArray<Float, D> = this.linAlgEx.solveF(a, b)
1518

multik-api/src/main/kotlin/org/jetbrains/kotlinx/multik/api/math/MathEx.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import org.jetbrains.kotlinx.multik.ndarray.data.Dimension
1010
import org.jetbrains.kotlinx.multik.ndarray.data.MultiArray
1111
import org.jetbrains.kotlinx.multik.ndarray.data.NDArray
1212

13+
/**
14+
* Extension interface for [Math] for improved type support.
15+
*/
1316
public interface MathEx {
1417
public fun <T : Number, D : Dimension> exp(a: MultiArray<T, D>): NDArray<Double, D>
1518
public fun <D : Dimension> expF(a: MultiArray<Float, D>): NDArray<Float, D>

0 commit comments

Comments
 (0)