Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map method. Should Daru::Vector return an Array? #512

Open
kojix2 opened this issue Apr 28, 2019 · 3 comments
Open

Map method. Should Daru::Vector return an Array? #512

kojix2 opened this issue Apr 28, 2019 · 3 comments

Comments

@kojix2
Copy link
Member

kojix2 commented Apr 28, 2019

Daru's vector returns an array when you call the map method.

v = Daru::Vector[1,2,3,4]
v.map {|i| i}
# => [1, 2, 3, 4]

map returns an array when you include module Enumerable.
But, there is no rule that the map method must return an array in Ruby.
For example,

require 'numo/narray'
a = Numo::SFloat.new(10).seq
a.map{|i| i}
#=> Numo::SFloat#shape=[10]
#[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

In Daru, recode return a Vector.

v = Daru::Vector[1,2,3,4]
v.recode {|i| i}
#=> #<Daru::Vector(4)>
#   0   1
#   1   2
#   2   3
#   3   4

This practice is not so common.
I think map should return Daru :: Vector.

If there is room to change the API from now, please consider.

@kojix2 kojix2 changed the title Map method. Should the Daru::Vector return an Array? Map method. Should Daru::Vector return an Array? Apr 28, 2019
@him666
Copy link

him666 commented May 1, 2019

looking into this

@kojix2
Copy link
Member Author

kojix2 commented May 7, 2019

Thank you for your work. @him666

But what I suggested was to change the behavior of the map method.

Currently, the map method returns an Array, but I suggested changing it to return Daru::Vector.

This is not a technical issue but a user consensus issue.

map_to_vector is similar to recode.
So I don't think we need a new method.

@ncs1
Copy link
Contributor

ncs1 commented Aug 20, 2019

I too, think that map on Daru::Vector should return Daru::Vector and not Array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants