kmath icon indicating copy to clipboard operation
kmath copied to clipboard

Choice of Buffer/NDStructure realization in function producing new object

Open Zelenyy opened this issue 6 years ago • 2 comments

For example, we have some function:

fun <T> someFunction1(input1: Buffer<T>, input2 : Buffer<T>) : Buffer<T>

How choice output Buffer sub-class for function? If always return a generic buffer, this could be slow, but creating specific realization of someFunction request more boilerplate code.

Zelenyy avatar Feb 22 '19 22:02 Zelenyy

Sorry for the late reply. Missed the issue.

That is what contexts are for. For optimized operations you need to use dedicated context. Specifically if you use more than one operations. On first operation context will reinterpret or transform the buffer into the form it likes, but on subsequent operations it will use optimized buffer form. Operations could be added as extensions for existing contexts.

If you use a single buffer operation on numbers, you can always use Buffer.auto factory. It does not guarantee optimal performance for custom classes, but for simple elements it should work just fine.

altavir avatar Mar 03 '19 06:03 altavir

Should be part of #61

altavir avatar Jun 07 '19 12:06 altavir