Skip to content

Commit

Permalink
Added sanity check for vector types.
Browse files Browse the repository at this point in the history
  • Loading branch information
ppanopticon committed Nov 30, 2023
1 parent 711a029 commit 0b5c141
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ sealed class Types<T : Value> {
@Serializable
@SerialName("INTEGER_VECTOR")
class IntVector(override val logicalSize: kotlin.Int): Vector<IntVectorValue, IntValue>() {
init {
require(this.logicalSize > 0) { "Logical size of a vector must be greater than zero." }
}

override val name = "INTEGER_VECTOR"
override val ordinal: kotlin.Int = 12
override val physicalSize = this.logicalSize * kotlin.Int.SIZE_BYTES
Expand All @@ -247,6 +251,10 @@ sealed class Types<T : Value> {
@Serializable
@SerialName("LONG_VECTOR")
class LongVector(override val logicalSize: kotlin.Int): Vector<LongVectorValue, LongValue>() {
init {
require(this.logicalSize > 0) { "Logical size of a vector must be greater than zero." }
}

override val name = "LONG_VECTOR"
override val ordinal: kotlin.Int = 13
override val physicalSize = this.logicalSize * kotlin.Long.SIZE_BYTES
Expand All @@ -256,6 +264,10 @@ sealed class Types<T : Value> {
@Serializable
@SerialName("FLOAT_VECTOR")
class FloatVector(override val logicalSize: kotlin.Int): Vector<FloatVectorValue, FloatValue>() {
init {
require(this.logicalSize > 0) { "Logical size of a vector must be greater than zero." }
}

override val name = "FLOAT_VECTOR"
override val ordinal: kotlin.Int = 14
override val physicalSize = this.logicalSize * kotlin.Int.SIZE_BYTES
Expand All @@ -265,6 +277,10 @@ sealed class Types<T : Value> {
@Serializable
@SerialName("DOUBLE_VECTOR")
class DoubleVector(override val logicalSize: kotlin.Int): Vector<DoubleVectorValue, DoubleValue>() {
init {
require(this.logicalSize > 0) { "Logical size of a vector must be greater than zero." }
}

override val name = "DOUBLE_VECTOR"
override val ordinal: kotlin.Int = 15
override val physicalSize = this.logicalSize * kotlin.Long.SIZE_BYTES
Expand All @@ -274,6 +290,10 @@ sealed class Types<T : Value> {
@Serializable
@SerialName("BOOLEAN_VECTOR")
class BooleanVector(override val logicalSize: kotlin.Int): Vector<BooleanVectorValue, BooleanValue>() {
init {
require(this.logicalSize > 0) { "Logical size of a vector must be greater than zero." }
}

override val name = "BOOLEAN_VECTOR"
override val ordinal: kotlin.Int = 16
override val physicalSize = this.logicalSize * kotlin.Byte.SIZE_BYTES
Expand All @@ -283,6 +303,10 @@ sealed class Types<T : Value> {
@Serializable
@SerialName("COMPLEX32_VECTOR")
class Complex32Vector(override val logicalSize: kotlin.Int): Vector<Complex32VectorValue, Complex32Value>() {
init {
require(this.logicalSize > 0) { "Logical size of a vector must be greater than zero." }
}

override val name = "COMPLEX32_VECTOR"
override val ordinal: kotlin.Int = 17
override val physicalSize = this.logicalSize * 2 * kotlin.Int.SIZE_BYTES
Expand All @@ -292,6 +316,10 @@ sealed class Types<T : Value> {
@Serializable
@SerialName("COMPLEX64_VECTOR")
class Complex64Vector(override val logicalSize: kotlin.Int): Vector<Complex64VectorValue, Complex32Value>() {
init {
require(this.logicalSize > 0) { "Logical size of a vector must be greater than zero." }
}

override val name = "COMPLEX64_VECTOR"
override val ordinal: kotlin.Int = 18
override val elementType = Complex32
Expand All @@ -310,6 +338,10 @@ sealed class Types<T : Value> {
@Serializable
@SerialName("SHORT_VECTOR")
class ShortVector(override val logicalSize: kotlin.Int): Vector<ShortVectorValue, ShortValue>() {
init {
require(this.logicalSize > 0) { "Logical size of a vector must be greater than zero." }
}

override val name = "SHORT_VECTOR"
override val ordinal: kotlin.Int = 20
override val physicalSize = this.logicalSize * kotlin.Short.SIZE_BYTES
Expand All @@ -319,6 +351,10 @@ sealed class Types<T : Value> {
@Serializable
@SerialName("HALF_VECTOR")
class HalfVector(override val logicalSize: kotlin.Int): Vector<FloatVectorValue, FloatValue>() {
init {
require(this.logicalSize > 0) { "Logical size of a vector must be greater than zero." }
}

override val name = "HALF_VECTOR"
override val ordinal: kotlin.Int = 21
override val physicalSize = this.logicalSize * kotlin.Short.SIZE_BYTES
Expand Down

0 comments on commit 0b5c141

Please sign in to comment.