-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc112cf
commit 1a4cf8c
Showing
34 changed files
with
1,611 additions
and
510 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import com.martmists.ndarray.simd.F64Array | ||
import com.martmists.ndarray.simd.impl.F64LargeDenseFlatArrayImpl | ||
import com.martmists.ndarray.simd.pow | ||
import kotlin.math.* | ||
import kotlin.test.Test | ||
import kotlin.test.assertContentEquals | ||
|
||
class MathTest { | ||
// FIXME: disabled until we can test within certain precision | ||
// @Test | ||
// fun `Test Array sqrt`() { | ||
// val arr1 = F64LargeDenseFlatArrayImpl(DoubleArray(F64Array.simdSize) { it.toDouble() }, 0, F64Array.simdSize) | ||
// val arr2 = arr1.sqrt() | ||
// assertContentEquals(arr2.toDoubleArray(), DoubleArray(F64Array.simdSize) { sqrt(it.toDouble()) }) | ||
// } | ||
// | ||
// @Test | ||
// fun `Test Array pow`() { | ||
// val arr1 = F64LargeDenseFlatArrayImpl(DoubleArray(F64Array.simdSize) { it.toDouble() }, 0, F64Array.simdSize) | ||
// val arr2 = arr1.pow(2.0) | ||
// assertContentEquals(arr2.toDoubleArray(), DoubleArray(F64Array.simdSize) { it.toDouble().pow(2.0) }) | ||
// } | ||
// | ||
// @Test | ||
// fun `Test Array ipow`() { | ||
// val arr1 = F64LargeDenseFlatArrayImpl(DoubleArray(F64Array.simdSize) { it.toDouble() }, 0, F64Array.simdSize) | ||
// val arr2 = (2.0).pow(arr1) | ||
// assertContentEquals(arr2.toDoubleArray(), DoubleArray(F64Array.simdSize) { (2.0).pow(it) }) | ||
// } | ||
// | ||
// @Test | ||
// fun `Test Array log`() { | ||
// val arr1 = F64LargeDenseFlatArrayImpl(DoubleArray(F64Array.simdSize) { it.toDouble() }, 0, F64Array.simdSize) | ||
// val arr2 = arr1.ln() | ||
// assertContentEquals(arr2.toDoubleArray(), DoubleArray(F64Array.simdSize) { ln(it.toDouble()) }) | ||
// } | ||
// | ||
// @Test | ||
// fun `Test Array logbase`() { | ||
// val arr1 = F64LargeDenseFlatArrayImpl(DoubleArray(F64Array.simdSize) { it.toDouble() }, 0, F64Array.simdSize) | ||
// val arr2 = arr1.logBase(5.0) | ||
// assertContentEquals(arr2.toDoubleArray(), DoubleArray(F64Array.simdSize) { log(it.toDouble(), 5.0) }) | ||
// } | ||
// | ||
// @Test | ||
// fun `Test Array exp`() { | ||
// val arr1 = F64LargeDenseFlatArrayImpl(DoubleArray(F64Array.simdSize) { it.toDouble() }, 0, F64Array.simdSize) | ||
// val arr2 = arr1.exp() | ||
// assertContentEquals(arr2.toDoubleArray(), DoubleArray(F64Array.simdSize) { exp(it.toDouble()) }) | ||
// } | ||
// | ||
// @Test | ||
// fun `Test Array expm1`() { | ||
// val arr1 = F64LargeDenseFlatArrayImpl(DoubleArray(F64Array.simdSize) { it.toDouble() }, 0, F64Array.simdSize) | ||
// val arr2 = arr1.expm1() | ||
// assertContentEquals(arr2.toDoubleArray(), DoubleArray(F64Array.simdSize) { expm1(it.toDouble()) }) | ||
// } | ||
// | ||
// @Test | ||
// fun `Test Array log1p`() { | ||
// val arr1 = F64LargeDenseFlatArrayImpl(DoubleArray(F64Array.simdSize) { it.toDouble() }, 0, F64Array.simdSize) | ||
// val arr2 = arr1.log1p() | ||
// assertContentEquals(arr2.toDoubleArray(), DoubleArray(F64Array.simdSize) { ln(1.0 + it) }) | ||
// } | ||
// | ||
// @Test | ||
// fun `Test Array log2`() { | ||
// val arr1 = F64LargeDenseFlatArrayImpl(DoubleArray(F64Array.simdSize) { it.toDouble() }, 0, F64Array.simdSize) | ||
// val arr2 = arr1.log2() | ||
// assertContentEquals(arr2.toDoubleArray(), DoubleArray(F64Array.simdSize) { log2(it.toDouble()) }) | ||
// } | ||
// | ||
// @Test | ||
// fun `Test Array log10`() { | ||
// val arr1 = F64LargeDenseFlatArrayImpl(DoubleArray(F64Array.simdSize) { it.toDouble() }, 0, F64Array.simdSize) | ||
// val arr2 = arr1.log10() | ||
// assertContentEquals(arr2.toDoubleArray(), DoubleArray(F64Array.simdSize) { log10(it.toDouble()) }) | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import com.martmists.ndarray.simd.F64Array | ||
import com.martmists.ndarray.simd.impl.F64LargeDenseFlatArrayImpl | ||
import com.martmists.ndarray.simd.pow | ||
import kotlin.math.* | ||
import kotlin.test.Test | ||
import kotlin.test.assertContentEquals | ||
import kotlin.test.assertEquals | ||
|
||
class ProcedureTest { | ||
@Test | ||
fun `Test Array sum`() { | ||
val arr = F64LargeDenseFlatArrayImpl(DoubleArray(F64Array.simdSize) { 1.0 }, 0, F64Array.simdSize) | ||
val res = arr.sum() | ||
assertEquals(F64Array.simdSize.toDouble(), res) | ||
} | ||
|
||
@Test | ||
fun `Test Array min`() { | ||
val arr = F64LargeDenseFlatArrayImpl(DoubleArray(F64Array.simdSize) { it * 2.0 }, 0, F64Array.simdSize) | ||
val res = arr.min() | ||
assertEquals(0.0, res) | ||
} | ||
|
||
@Test | ||
fun `Test Array max`() { | ||
val arr = F64LargeDenseFlatArrayImpl(DoubleArray(F64Array.simdSize) { it * 5.0 }, 0, F64Array.simdSize) | ||
val res = arr.max() | ||
assertEquals((F64Array.simdSize * 5 - 5).toDouble(), res) | ||
} | ||
|
||
@Test | ||
fun `Test Array prod`() { | ||
val arr = F64LargeDenseFlatArrayImpl(DoubleArray(F64Array.simdSize) { it + 1.0 }, 0, F64Array.simdSize) | ||
val res = arr.product() | ||
|
||
fun factorial(n: Double): Double { | ||
if (n == 1.0) return n | ||
return n * factorial(n - 1) | ||
} | ||
|
||
assertEquals(factorial(F64Array.simdSize.toDouble()), res) | ||
} | ||
|
||
@Test | ||
fun `Test Array mean`() { | ||
val arr = F64LargeDenseFlatArrayImpl(DoubleArray(F64Array.simdSize) { it.toDouble() }, 0, F64Array.simdSize) | ||
val res = arr.mean() | ||
assertEquals((F64Array.simdSize.toDouble() - 1) / 2, res) | ||
} | ||
|
||
@Test | ||
fun `Test Array coerce`() { | ||
val arr1 = F64LargeDenseFlatArrayImpl(DoubleArray(F64Array.simdSize) { it * 5.0 }, 0, F64Array.simdSize) | ||
val arr2 = arr1.coerce(2.5, 17.0) | ||
assertEquals(2.5, arr2.min()) | ||
assertEquals(17.0, arr2.max()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import com.martmists.ndarray.simd.F64Array | ||
import com.martmists.ndarray.simd.impl.F64LargeDenseFlatArrayImpl | ||
import com.martmists.ndarray.simd.pow | ||
import kotlin.math.* | ||
import kotlin.test.Test | ||
import kotlin.test.assertContentEquals | ||
import kotlin.test.assertEquals | ||
|
||
class RoundingTest { | ||
@Test | ||
fun `Test Array floor`() { | ||
val arr1 = F64LargeDenseFlatArrayImpl(DoubleArray(F64Array.simdSize) { 0.1 * it }, 0, F64Array.simdSize) | ||
val arr2 = arr1.floor() | ||
assertContentEquals(arr2.toDoubleArray(), DoubleArray(F64Array.simdSize) { floor(0.1 * it) }) | ||
} | ||
|
||
@Test | ||
fun `Test Array ceil`() { | ||
val arr1 = F64LargeDenseFlatArrayImpl(DoubleArray(F64Array.simdSize) { 0.1 * it }, 0, F64Array.simdSize) | ||
val arr2 = arr1.ceil() | ||
assertContentEquals(arr2.toDoubleArray(), DoubleArray(F64Array.simdSize) { ceil(0.1 * it) }) | ||
} | ||
|
||
@Test | ||
fun `Test Array trunc`() { | ||
val arr1 = F64LargeDenseFlatArrayImpl(DoubleArray(F64Array.simdSize) { 0.1 * it }, 0, F64Array.simdSize) | ||
val arr2 = arr1.trunc() | ||
assertContentEquals(arr2.toDoubleArray(), DoubleArray(F64Array.simdSize) { truncate(0.1 * it) }) | ||
} | ||
|
||
@Test | ||
fun `Test Array round`() { | ||
val arr1 = F64LargeDenseFlatArrayImpl(DoubleArray(F64Array.simdSize) { 0.2 * it }, 0, F64Array.simdSize) | ||
val arr2 = arr1.round() | ||
assertContentEquals(arr2.toDoubleArray(), DoubleArray(F64Array.simdSize) { round(0.2 * it) }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import com.martmists.ndarray.simd.F64Array | ||
import com.martmists.ndarray.simd.impl.F64LargeDenseFlatArrayImpl | ||
import com.martmists.ndarray.simd.pow | ||
import kotlin.math.* | ||
import kotlin.test.Test | ||
import kotlin.test.assertContentEquals | ||
import kotlin.test.assertEquals | ||
|
||
class TrigonometryTest { | ||
// TODO | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import com.martmists.ndarray.simd.F64Array | ||
import com.martmists.ndarray.simd.impl.F64LargeDenseFlatArrayImpl | ||
import com.martmists.ndarray.simd.pow | ||
import kotlin.math.* | ||
import kotlin.test.Test | ||
import kotlin.test.assertContentEquals | ||
import kotlin.test.assertEquals | ||
|
||
class VectorTest { | ||
@Test | ||
fun `Test Array dot Array`() { | ||
val arr1 = F64LargeDenseFlatArrayImpl(DoubleArray(F64Array.simdSize) { it.toDouble() }, 0, F64Array.simdSize) | ||
val arr2 = F64LargeDenseFlatArrayImpl(DoubleArray(F64Array.simdSize) { it - 1.0 }, 0, F64Array.simdSize) | ||
val res = arr1 dot arr2 | ||
assertEquals(res, (0 until F64Array.simdSize).sumOf { it * (it - 1.0) }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.