Adams和Mullapudi自动调度程序都支持特化。其中Adams的特化方法需要使用@specialize注释,Mullapudi的特化方法则需要使用spec_block操作。以下是两个示例代码:
Adams特化示例代码:
def my_function[T](x: T, y: T) = {
println(x + " " + y)
}
@specialized(Int, Double)
def my_specialized_function[T](x: T, y: T) = {
println(x + " " + y)
}
my_function(1, 2) // prints "1 2"
my_specialized_function(1, 2) // prints "1 2"
my_specialized_function(1.0, 2.0) // prints "1.0 2.0"
Mullapudi特化示例代码:
def my_function[T](x: T, y: T) = {
println(x + " " + y)
}
spec_block {
my_specialized_function = specialized[Int, Double] { (x, y) =>
println(x + " " + y)
}
}
my_function(1, 2) // prints "1 2"
my_specialized_function(1, 2) // prints "1 2"
my_specialized_function(1.0, 2.0) // prints "1.0 2.0"