crystal-data / num.cr

Scientific computing in pure Crystal
MIT License
151 stars 12 forks source link

.to_tensor method for arrays? #20

Closed Iainmon closed 4 years ago

Iainmon commented 4 years ago

Would it be a good idea to add in a [1, 2, 3].to_tensor method for arrays? Maybe .to_vector and .to_matrix similar to this repository? It would be a lot easier and prettier than Tensor.from_array [1, 2, 3]. https://github.com/ruivieira/crystal-gsl/blob/fa8ea796f06c77add4bb092be7bbdd93794027d6/src/gsl/base/array.cr

christopherzimmerman commented 4 years ago

Yes, this would be a great addition. I already override default crystal behavior for numbers, so I don't see a reason not to have it for arrays. This should be a very easy add, since I already have a from_array method, so it would just be something like:

class Array(T)
    def to_tensor
        Tensor.from_array(self)
    end
end

A PR would be welcome here!

christopherzimmerman commented 4 years ago

Closed by #21