facebookresearch / diffkt

A framework for automatic differentiation in Kotlin
MIT License
60 stars 6 forks source link

Allow users to get a FloatArray from a FloatTensor #7

Open samdow opened 3 years ago

samdow commented 3 years ago

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: jupyter copy 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