# Memory usage problem when using findmax/min

**URL:** https://discourse.julialang.org/t/memory-usage-problem-when-using-findmax-min/92241
**Category:** GPU
**Created:** [December 28, 2022, 7:34pm UTC](https://discourse.julialang.org/t/memory-usage-problem-when-using-findmax-min/92241 "2022-12-28T19:34:30Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)
#### Post date: [December 28, 2022, 9:37pm UTC](https://discourse.julialang.org/t/memory-usage-problem-when-using-findmax-min/92241/6 "2022-12-28T21:37:57Z")

</div>

This is probably only tangentially related but using `findmax` (instead of `maximum`) is related to a problem in [https://discourse.julialang.org/t/findmin-max-and-generators/88473/1](https://discourse.julialang.org/t/findmin-max-and-generators/88473/1)  
it was fixed/hacked there using:

```julia
Base.pairs(itr::Base.Iterators.Zip) = 
  Iterators.map(((i,v),) -> i=>v, enumerate(itr))

```

and then:

```julia
julia> a = rand(1_000); b = rand(1_000);

julia> @btime first(findmax(((x,y),)-> x+√y,zip($a,$b)))
  2.795 μs (0 allocations: 0 bytes)
1.9773820790088965

```

works.

PS If Cuda vectors don’t like `zip` maybe they can `map`:

```julia
first(findmax(Iterators.map(((x, y),)-> x+√y, a, b)))

```

will work.

---

_[View the full topic](https://discourse.julialang.org/t/memory-usage-problem-when-using-findmax-min/92241)._
