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

implement map for multiple array arguments #174

Closed
zingales opened this issue Aug 14, 2011 · 3 comments
Closed

implement map for multiple array arguments #174

zingales opened this issue Aug 14, 2011 · 3 comments

Comments

@zingales
Copy link
Contributor

i skimmed the other map thread and felt that this was off topic enough and not as important, so i decided to start another thread (even though they talk about the same function)

if the function has 1 argument then its done simply like so

julia> map(char, [1,2,3,4])
['\x01','\x02','\x03','\x04']

however if the requires multiple arguments this has to be done with an array of arrays

julia> map(x->is(x[1],x[2]), {{2,3},{3,4},{4,5}})
{6,12,20}

this is inconsistency could be fixed, by forcing even the 1-dimensional case also require a array of arrays. This however, would seem to make the matters of calling this function worse. But would be entirely consistent

i feel the optimal solution, is that if the function being passed has a predefined number of arguments, that it automatically set picks out that number of arguments from array, and only if the function usess the ... must u pass it an array of arrays

exmaple:

julia> function threenumadd(num1,num2,num3)
    num1+num2+num3
end

julia> map(threenumadd, [1,2,3,4,5,6])
[6,15]

julia> map(+, {{1,2},{3,4},{5,6}})
[3,7,11]
@JeffBezanson
Copy link
Member

It's well-established that to call map on an N-argument function, you pass N lists (or whatever collection) to map:

julia> map(+, (1,2), (3,4))
(4,6)

The N-argument case isn't currently implemented for arrays though.

@JeffBezanson
Copy link
Member

Also, this:

julia> map(x->is(x[1],x[2]), {{2,3},{3,4},{4,5}})
{6,12,20}

is not an inconsistency by any stretch of the imagination. The "problem" here is consistency: map on one array calls a function of one argument on each element of the array, period. x->is(x[1],x[2]) is a perfectly ordinary one-argument function. In fact this case illustrates why you could not have special behavior for an array of arrays: the mapped function might take an array as its argument, so it would be ambiguous whether the function should be called on whole arrays or their elements as N arguments.

@zingales
Copy link
Contributor Author

oooooOOOOOOoOOOOOOOoooo i didn't know you could do that. I completely revoke
my previous statement.

Giuseppe

On Mon, Aug 15, 2011 at 9:06 PM, JeffBezanson <
[email protected]>wrote:

Also, this:

julia> map(x->is(x[1],x[2]), {{2,3},{3,4},{4,5}})
{6,12,20}

is not an inconsistency by any stretch of the imagination. The "problem"
here is consistency: map on one array calls a function of one argument on
each element of the array, period. x->is(x[1],x[2]) is a perfectly
ordinary one-argument function. In fact this case illustrates why you could
not have special behavior for an array of arrays: the mapped function
might take an array as its argument, so it would be ambiguous whether the
function should be called on whole arrays or their elements as N arguments.

Reply to this email directly or view it on GitHub:
#174 (comment)

StefanKarpinski pushed a commit that referenced this issue Feb 8, 2018
README updates for mktemp
LilithHafner pushed a commit to LilithHafner/julia that referenced this issue Oct 11, 2021
Add the v0.5 tests badge to the README
Keno pushed a commit that referenced this issue Oct 9, 2023
* fix what project is used when building builtins

* Update JuliaInterpreter.jl

* Update src/JuliaInterpreter.jl

Co-Authored-By: KristofferC <[email protected]>
ViralBShah pushed a commit that referenced this issue Dec 16, 2024
Stdlib: Statistics
URL: https://github.com/JuliaStats/Statistics.jl.git
Stdlib branch: master
Julia branch: master
Old commit: 68869af
New commit: d49c2bf
Julia version: 1.12.0-DEV
Statistics version: 1.11.2(Does not match)
Bump invoked by: @DilumAluthge
Powered by:
[BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl)

Diff:
JuliaStats/Statistics.jl@68869af...d49c2bf

```
$ git log --oneline 68869af..d49c2bf
d49c2bf Merge pull request #178 from JuliaStats/dw/ci
d10d6a3 Update Project.toml
1b67c17 Merge pull request #168 from JuliaStats/andreasnoack-patch-2
c3721ed Add a coverage badge
8086523 Test earliest supported Julia version and prereleases
12a1976 Update codecov in ci.yml
2caf0eb Merge pull request #177 from JuliaStats/ViralBShah-patch-1
33e6e8b Update ci.yml to use julia-actions/cache
a399c19 Merge pull request #176 from JuliaStats/dependabot/github_actions/julia-actions/setup-julia-2
6b8d58a Merge branch 'master' into dependabot/github_actions/julia-actions/setup-julia-2
c2fb201 Merge pull request #175 from JuliaStats/dependabot/github_actions/actions/cache-4
8f808e4 Merge pull request #174 from JuliaStats/dependabot/github_actions/codecov/codecov-action-4
7f82133 Merge pull request #173 from JuliaStats/dependabot/github_actions/actions/checkout-4
046fb6f Update ci.yml
c0fc336 Bump julia-actions/setup-julia from 1 to 2
a95a57a Bump actions/cache from 1 to 4
b675501 Bump codecov/codecov-action from 1 to 4
0088c49 Bump actions/checkout from 2 to 4
ad95c08 Create dependabot.yml
40275e2 Merge pull request #167 from JuliaStats/andreasnoack-patch-1
fa5592a Merge pull request #170 from mbauman/patch-1
cf57562 Add more tests of mean and median of ranges
128dc11 Merge pull request #169 from stevengj/patch-1
48d7a02 docfix: abs2, not ^2
2ac5bec correct std docs: sqrt is elementwise
39f6332 Merge pull request #96 from josemanuel22/mean_may_return_incorrect_results
db3682b Merge branch 'master' into mean_may_return_incorrect_results
9e96507 Update src/Statistics.jl
58e5986 Test prereleases
6e76739 Implement one-argument cov2cor!
b8fee00 Stop testing on nightly
9addbb8 Merge pull request #162 from caleb-allen/patch-1
6e3d223 Merge pull request #164 from aplavin/patch-1
71ebe28 Merge pull request #166 from JuliaStats/dw/cov_cor_optimization
517afa6 add tests
aa0f549 Optimize `cov` and `cor` with identical arguments
cc11ea9 propagate NaN value in median
cf7040f Use non-mobile Wikipedia urls
547bf4d adding docu to mean! explain target should not alias with the source
296650a adding docu to mean! explain target should not alias with the source
```

Co-authored-by: Dilum Aluthge <[email protected]>
stevengj pushed a commit that referenced this issue Jan 2, 2025
Stdlib: Statistics
URL: https://github.com/JuliaStats/Statistics.jl.git
Stdlib branch: master
Julia branch: master
Old commit: 68869af
New commit: d49c2bf
Julia version: 1.12.0-DEV
Statistics version: 1.11.2(Does not match)
Bump invoked by: @DilumAluthge
Powered by:
[BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl)

Diff:
JuliaStats/Statistics.jl@68869af...d49c2bf

```
$ git log --oneline 68869af..d49c2bf
d49c2bf Merge pull request #178 from JuliaStats/dw/ci
d10d6a3 Update Project.toml
1b67c17 Merge pull request #168 from JuliaStats/andreasnoack-patch-2
c3721ed Add a coverage badge
8086523 Test earliest supported Julia version and prereleases
12a1976 Update codecov in ci.yml
2caf0eb Merge pull request #177 from JuliaStats/ViralBShah-patch-1
33e6e8b Update ci.yml to use julia-actions/cache
a399c19 Merge pull request #176 from JuliaStats/dependabot/github_actions/julia-actions/setup-julia-2
6b8d58a Merge branch 'master' into dependabot/github_actions/julia-actions/setup-julia-2
c2fb201 Merge pull request #175 from JuliaStats/dependabot/github_actions/actions/cache-4
8f808e4 Merge pull request #174 from JuliaStats/dependabot/github_actions/codecov/codecov-action-4
7f82133 Merge pull request #173 from JuliaStats/dependabot/github_actions/actions/checkout-4
046fb6f Update ci.yml
c0fc336 Bump julia-actions/setup-julia from 1 to 2
a95a57a Bump actions/cache from 1 to 4
b675501 Bump codecov/codecov-action from 1 to 4
0088c49 Bump actions/checkout from 2 to 4
ad95c08 Create dependabot.yml
40275e2 Merge pull request #167 from JuliaStats/andreasnoack-patch-1
fa5592a Merge pull request #170 from mbauman/patch-1
cf57562 Add more tests of mean and median of ranges
128dc11 Merge pull request #169 from stevengj/patch-1
48d7a02 docfix: abs2, not ^2
2ac5bec correct std docs: sqrt is elementwise
39f6332 Merge pull request #96 from josemanuel22/mean_may_return_incorrect_results
db3682b Merge branch 'master' into mean_may_return_incorrect_results
9e96507 Update src/Statistics.jl
58e5986 Test prereleases
6e76739 Implement one-argument cov2cor!
b8fee00 Stop testing on nightly
9addbb8 Merge pull request #162 from caleb-allen/patch-1
6e3d223 Merge pull request #164 from aplavin/patch-1
71ebe28 Merge pull request #166 from JuliaStats/dw/cov_cor_optimization
517afa6 add tests
aa0f549 Optimize `cov` and `cor` with identical arguments
cc11ea9 propagate NaN value in median
cf7040f Use non-mobile Wikipedia urls
547bf4d adding docu to mean! explain target should not alias with the source
296650a adding docu to mean! explain target should not alias with the source
```

Co-authored-by: Dilum Aluthge <[email protected]>
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

2 participants