Replies: 4 comments 3 replies
-
I consider only conv2d case but the other are similiar.
public data class Size1D(val v: Long)
public data class Size2D(val w: Long, val h: Long) {
public constructor(b: Long) : this(b, b)
}
public fun Int.both(): Size2D = Size2D(this.toLong())
public val Int.D1: Size1D get() = Size1D(this.toLong())
public val Int.D2: Size2D get() = Size2D(this.toLong())
public infix fun Int.x(o: Int): Size2D = Size2D(this.toLong(), o.toLong())
public infix fun Size1D.x(o: Size1D): Size2D = Size2D(this.v, o.v) and then use it as follows val someKernel1D = 3.D1
val smallKernel2D = 1 x 1 // this is my love from the first sight :D
val mediumKernel2D = 2.both()
val largeKernel2D = 3.D2
val fromKernel1D2D = someKernel1D x someKernel1D
|
Beta Was this translation helpful? Give feedback.
-
I don't see any situation where you couldn't reduce it to two, you just have to expand it according to the channel format. You could maybe have a situation where some wants all 4 values for dilation but I've never seen anything like it. When I've had to do this in the past, I've done something like (w/ better names): sealed interface Expandable4{
fun all(): Data4
}
data class Data4(val a: Long, val b: Long, val c: Long, val d: Long): Expandable4{
override fun all() = this
}
data class Data2(val a: Long, val b: Long): Expandable4{
override fun all() = Data4(a, b, a, b)
}
data class Data1(val a: Long): Expandable4{
override fun all() = Data4(a, a, a, a)
}
fun Conv2d(kernelSize: Expandable4 = Data1(3), ...)
It makes more sense in some cases to turn Data4 into 2 Data2s. It's more wrapping than I would like, especially for single int literals (which is usually what I see most), but I don't see a way around that besides concise object literals or collection literals. |
Beta Was this translation helpful? Give feedback.
-
Thanks for creating this discussion thread for this issue. Well, as I have mentioned earlier, personally I prefer:
A word of caution: all of the above points is coming from a person who is mostly new to Kotlin/Java (but knows a relatively fair amount about ML and TF/Keras). So I may not be the best person to comment on the API design issues. :) |
Beta Was this translation helpful? Give feedback.
-
@rnett @mkaze @avan1235 thanks for your active participation in the discussion. I suppose no new opinion will be added here. Looks like we need to start from small steps like
I'd prefer an array of primitives instead of Lists here, due to the generic nature of lists instead of strong type in IntArray, for example. As the second step, we could play in the experimental branch with the small hierarchy of data classes as @avan1235 proposed and ask some potential users about it. I'm going to make an issue about that and make this refactoring (regarding the first step). |
Beta Was this translation helpful? Give feedback.
-
Firstly, it was made in many cases like just wrappers for underlying TF Java API, which is full of these long arrays, as you see.
But it looks like nobody wants to use these 4d arrays in real life.
Let's try to answer here, in this thread on a few questions:
Hi @avan1235 @mkaze you both asked me about that, it's time to discuss
Beta Was this translation helpful? Give feedback.
All reactions