Many standard Kotlin libraries will want to accept a FloatArray (or a List or something that can be built from a FloatArray) instead of a FloatTensor (because they won't know about it). In order to let our users take the data they've gotten and visualize it or run it through standard libraries, we'll want to include a .toFloatArray function.
We may want to only have this on FloatTensor because this isn't differentiable.
This shows an example of how it could be used, where x, p, and d are FloatTensors:
The easiest way to write this is probably the way that Todd wrote it by using .at(). We can add other versions for singleton or natural if we really want.
NOTE: do not return the data field from natural. If we do this without copying, we risk allowing unintended mutation on the tensor
Many standard Kotlin libraries will want to accept a FloatArray (or a List or something that can be built from a FloatArray) instead of a FloatTensor (because they won't know about it). In order to let our users take the data they've gotten and visualize it or run it through standard libraries, we'll want to include a
.toFloatArray
function.We may want to only have this on
FloatTensor
because this isn't differentiable.This shows an example of how it could be used, where
x
,p
, andd
are FloatTensors: The easiest way to write this is probably the way that Todd wrote it by using.at()
. We can add other versions for singleton or natural if we really want.NOTE: do not return the data field from natural. If we do this without copying, we risk allowing unintended mutation on the tensor