Skip to content

Commit

Permalink
Reduce maximum dimensions to 50 since roborio was getting angry
Browse files Browse the repository at this point in the history
  • Loading branch information
Redrield committed May 27, 2019
1 parent 0f8e71d commit 3475af5
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 66 deletions.
13 changes: 13 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.3.31"
maven
`maven-publish`
}

group = "frc.team4069"
Expand All @@ -19,6 +20,18 @@ dependencies {
testCompile("junit:junit:4.12")
}

publishing {
publications {
create<MavenPublication>("mavenLocal") {
groupId = "frc.team4069"
artifactId = "Keigen"
version = "1.2.0"

from(components["java"])
}
}
}

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
56 changes: 3 additions & 53 deletions src/main/kotlin/frc/team4069/keigen/Dim.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,61 +54,11 @@ open class `46`(override val i: Int = 46): `47`(i) { companion object: `46`(), N
open class `47`(override val i: Int = 47): `48`(i) { companion object: `47`(), Nat<`47`> }
open class `48`(override val i: Int = 48): `49`(i) { companion object: `48`(), Nat<`48`> }
open class `49`(override val i: Int = 49): `50`(i) { companion object: `49`(), Nat<`49`> }
open class `50`(override val i: Int = 50): `51`(i) { companion object: `50`(), Nat<`50`> }
open class `51`(override val i: Int = 51): `52`(i) { companion object: `51`(), Nat<`51`> }
open class `52`(override val i: Int = 52): `53`(i) { companion object: `52`(), Nat<`52`> }
open class `53`(override val i: Int = 53): `54`(i) { companion object: `53`(), Nat<`53`> }
open class `54`(override val i: Int = 54): `55`(i) { companion object: `54`(), Nat<`54`> }
open class `55`(override val i: Int = 55): `56`(i) { companion object: `55`(), Nat<`55`> }
open class `56`(override val i: Int = 56): `57`(i) { companion object: `56`(), Nat<`56`> }
open class `57`(override val i: Int = 57): `58`(i) { companion object: `57`(), Nat<`57`> }
open class `58`(override val i: Int = 58): `59`(i) { companion object: `58`(), Nat<`58`> }
open class `59`(override val i: Int = 59): `60`(i) { companion object: `59`(), Nat<`59`> }
open class `60`(override val i: Int = 60): `61`(i) { companion object: `60`(), Nat<`60`> }
open class `61`(override val i: Int = 61): `62`(i) { companion object: `61`(), Nat<`61`> }
open class `62`(override val i: Int = 62): `63`(i) { companion object: `62`(), Nat<`62`> }
open class `63`(override val i: Int = 63): `64`(i) { companion object: `63`(), Nat<`63`> }
open class `64`(override val i: Int = 64): `65`(i) { companion object: `64`(), Nat<`64`> }
open class `65`(override val i: Int = 65): `66`(i) { companion object: `65`(), Nat<`65`> }
open class `66`(override val i: Int = 66): `67`(i) { companion object: `66`(), Nat<`66`> }
open class `67`(override val i: Int = 67): `68`(i) { companion object: `67`(), Nat<`67`> }
open class `68`(override val i: Int = 68): `69`(i) { companion object: `68`(), Nat<`68`> }
open class `69`(override val i: Int = 69): `70`(i) { companion object: `69`(), Nat<`69`> }
open class `70`(override val i: Int = 70): `71`(i) { companion object: `70`(), Nat<`70`> }
open class `71`(override val i: Int = 71): `72`(i) { companion object: `71`(), Nat<`71`> }
open class `72`(override val i: Int = 72): `73`(i) { companion object: `72`(), Nat<`72`> }
open class `73`(override val i: Int = 73): `74`(i) { companion object: `73`(), Nat<`73`> }
open class `74`(override val i: Int = 74): `75`(i) { companion object: `74`(), Nat<`74`> }
open class `75`(override val i: Int = 75): `76`(i) { companion object: `75`(), Nat<`75`> }
open class `76`(override val i: Int = 76): `77`(i) { companion object: `76`(), Nat<`76`> }
open class `77`(override val i: Int = 77): `78`(i) { companion object: `77`(), Nat<`77`> }
open class `78`(override val i: Int = 78): `79`(i) { companion object: `78`(), Nat<`78`> }
open class `79`(override val i: Int = 79): `80`(i) { companion object: `79`(), Nat<`79`> }
open class `80`(override val i: Int = 80): `81`(i) { companion object: `80`(), Nat<`80`> }
open class `81`(override val i: Int = 81): `82`(i) { companion object: `81`(), Nat<`81`> }
open class `82`(override val i: Int = 82): `83`(i) { companion object: `82`(), Nat<`82`> }
open class `83`(override val i: Int = 83): `84`(i) { companion object: `83`(), Nat<`83`> }
open class `84`(override val i: Int = 84): `85`(i) { companion object: `84`(), Nat<`84`> }
open class `85`(override val i: Int = 85): `86`(i) { companion object: `85`(), Nat<`85`> }
open class `86`(override val i: Int = 86): `87`(i) { companion object: `86`(), Nat<`86`> }
open class `87`(override val i: Int = 87): `88`(i) { companion object: `87`(), Nat<`87`> }
open class `88`(override val i: Int = 88): `89`(i) { companion object: `88`(), Nat<`88`> }
open class `89`(override val i: Int = 89): `90`(i) { companion object: `89`(), Nat<`89`> }
open class `90`(override val i: Int = 90): `91`(i) { companion object: `90`(), Nat<`90`> }
open class `91`(override val i: Int = 91): `92`(i) { companion object: `91`(), Nat<`91`> }
open class `92`(override val i: Int = 92): `93`(i) { companion object: `92`(), Nat<`92`> }
open class `93`(override val i: Int = 93): `94`(i) { companion object: `93`(), Nat<`93`> }
open class `94`(override val i: Int = 94): `95`(i) { companion object: `94`(), Nat<`94`> }
open class `95`(override val i: Int = 95): `96`(i) { companion object: `95`(), Nat<`95`> }
open class `96`(override val i: Int = 96): `97`(i) { companion object: `96`(), Nat<`96`> }
open class `97`(override val i: Int = 97): `98`(i) { companion object: `97`(), Nat<`97`> }
open class `98`(override val i: Int = 98): `99`(i) { companion object: `98`(), Nat<`98`> }
open class `99`(override val i: Int = 99): `100`(i) { companion object: `99`(), Nat<`99`> }

sealed class `100`(open val i: Int = 100) {
companion object: `100`(), Nat<`100`>
sealed class `50`(open val i: Int = 50) {
companion object: `50`(), Nat<`50`>

override fun toString() = "$i"
}

interface Nat<T: `100`> { val i: Int }
interface Nat<T: `50`> { val i: Int }
4 changes: 2 additions & 2 deletions src/main/kotlin/frc/team4069/keigen/Matrix.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.ejml.dense.row.CommonOps_DDRM
import org.ejml.dense.row.NormOps_DDRM
import org.ejml.simple.SimpleMatrix

open class Matrix<R: `100`, C: `100`>(private val rows: Nat<R>, private val cols: Nat<C>, internal val storage: SimpleMatrix) {
open class Matrix<R: `50`, C: `50`>(private val rows: Nat<R>, private val cols: Nat<C>, internal val storage: SimpleMatrix) {
val numCols get() = cols.i

val numRows get() = rows.i
Expand All @@ -20,7 +20,7 @@ open class Matrix<R: `100`, C: `100`>(private val rows: Nat<R>, private val cols
fun minInternal() = CommonOps_DDRM.elementMin(this.storage.ddrm)
fun mean() = elementSum() / storage.numElements.toDouble()

operator fun <C2: `100`> times(other: Matrix<C, C2>): Matrix<R, C2>
operator fun <C2: `50`> times(other: Matrix<C, C2>): Matrix<R, C2>
= Matrix(rows, other.cols, this.storage.mult(other.storage))

operator fun times(value: Double): Matrix<R, C>
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/frc/team4069/keigen/creatorDsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package frc.team4069.keigen

import org.ejml.simple.SimpleMatrix

fun <R : `100`, C : `100`> mat(rows: Nat<R>, cols: Nat<C>) = MatBuilder(rows, cols)
fun <R : `50`, C : `50`> mat(rows: Nat<R>, cols: Nat<C>) = MatBuilder(rows, cols)

fun <D : `100`> vec(dim: Nat<D>) = VecBuilder(dim)
fun <D : `50`> vec(dim: Nat<D>) = VecBuilder(dim)

class MatBuilder<R : `100`, C : `100`>(val rows: Nat<R>, val cols: Nat<C>) {
class MatBuilder<R : `50`, C : `50`>(val rows: Nat<R>, val cols: Nat<C>) {
fun fill(vararg data: Double): Matrix<R, C> {
if (data.size != rows.i * cols.i) {
throw IllegalArgumentException("Invalid matrix data provided. Wanted ${rows.i} x ${cols.i} matrix, but got ${data.size} elements")
Expand All @@ -26,7 +26,7 @@ class MatBuilder<R : `100`, C : `100`>(val rows: Nat<R>, val cols: Nat<C>) {
}
}

class VecBuilder<D : `100`>(val dim: Nat<D>) {
class VecBuilder<D : `50`>(val dim: Nat<D>) {
fun fill(vararg data: Double): Vector<D> {
if (data.size != dim.i) {
throw IllegalArgumentException("Invalid number of elements for ${dim.i}-dimensional vector. got ${data.size} elements")
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/frc/team4069/keigen/creators.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ package frc.team4069.keigen
import org.ejml.dense.row.CommonOps_DDRM
import org.ejml.simple.SimpleMatrix

fun <R: `100`, C: `100`> zeros(rows: Nat<R>, cols: Nat<C>) = Matrix(rows, cols, SimpleMatrix(rows.i, cols.i))
fun <D: `100`> zeros(size: Nat<D>) = Matrix(size, `1`, SimpleMatrix(size.i, 1))
fun <R: `50`, C: `50`> zeros(rows: Nat<R>, cols: Nat<C>) = Matrix(rows, cols, SimpleMatrix(rows.i, cols.i))
fun <D: `50`> zeros(size: Nat<D>) = Matrix(size, `1`, SimpleMatrix(size.i, 1))

fun <D: `100`> eye(size: Nat<D>) = Matrix(size, size, SimpleMatrix.identity(size.i))
fun <D: `50`> eye(size: Nat<D>) = Matrix(size, size, SimpleMatrix.identity(size.i))

fun <R: `100`, C: `100`> ones(rows: Nat<R>, cols: Nat<C>): Matrix<R, C> {
fun <R: `50`, C: `50`> ones(rows: Nat<R>, cols: Nat<C>): Matrix<R, C> {
val out = SimpleMatrix(rows.i, cols.i)
CommonOps_DDRM.fill(out.ddrm, 1.0)
return Matrix(rows, cols, out)
}
fun <D: `100`> ones(size: Nat<D>): Matrix<D, `1`> {
fun <D: `50`> ones(size: Nat<D>): Matrix<D, `1`> {
val out = SimpleMatrix(size.i, 1)
CommonOps_DDRM.fill(out.ddrm, 1.0)

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/frc/team4069/keigen/vector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package frc.team4069.keigen

typealias Vector<D> = Matrix<D, `1`>

operator fun <D: `100`> Matrix<D, `1`>.get(i: Int) = storage[i, 0]
operator fun <D: `100`> Matrix<D, `1`>.set(i: Int, j: Double) {
operator fun <D: `50`> Matrix<D, `1`>.get(i: Int) = storage[i, 0]
operator fun <D: `50`> Matrix<D, `1`>.set(i: Int, j: Double) {
storage[i, 0] = j
}

1 comment on commit 3475af5

@prateekma
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

angery

Please sign in to comment.