# Lazy logspace object

**URL:** <https://discourse.julialang.org/t/lazy-logspace-object/70091>\
**Category:** General Usage\
**Tags:** lazy-evaluation\
**Created:** [October 20, 2021, 12:39pm UTC](https://discourse.julialang.org/t/lazy-logspace-object/70091 "2021-10-20T12:39:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [October 20, 2021, 12:39pm UTC](https://discourse.julialang.org/t/lazy-logspace-object/70091/1 "2021-10-20T12:39:49Z")

</div>

We still miss a lazy version as a range. The broadcast solution above is greedy and breaks code that expects range objects.

---

<div class="post-metadata">

**Author:** ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)\
**Post date:** [October 20, 2021, 12:55pm UTC](https://discourse.julialang.org/t/lazy-logspace-object/70091/2 "2021-10-20T12:55:23Z")

</div>

I tried to make one [here](https://github.com/JuliaLang/julia/pull/39071) but, well, maybe it was a bad time.

That proposal would write the case above as `logrange(0.01, 100, length=50)` i.e. specifying start and end points, exactly like `range`, not powers of some base. (To be clear, there is no need to specify a base. The geometric mean does not depend on such a thing; this just generalises to many intermediate points.)

Edit: by “above” I meant an earlier thread, whose example was `10 .^ range(-2, 2, length=50)`. In ancient versions of Julia, this was written `logspace(-2, 2, 50, base=10)` , but this was removed since `10 .^ range` is clearer if you want to specify the powers.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 20, 2021, 12:57pm UTC](https://discourse.julialang.org/t/lazy-logspace-object/70091/3 "2021-10-20T12:57:50Z")

</div>

> [@juliohm](#):
>
> breaks code that expects range objects.

If a function expects a range object, it is probably because it requires a constant stepsize, which is not true for log-scaled ranges. If it doesn’t require a `step`, why wouldn’t it accept any `AbstractArray` subtype?

Note that a lazy O(1)-storage log-scaled array is possible with [GitHub - JuliaArrays/MappedArrays.jl: Lazy in-place transformations of arrays](https://github.com/JuliaArrays/MappedArrays.jl), via `mappedarray(exp10, range(-2, 10, length=10^6))` or similar.

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [October 20, 2021, 7:40pm UTC](https://discourse.julialang.org/t/lazy-logspace-object/70091/4 "2021-10-20T19:40:03Z")

</div>

If all you want is a lazy iterator (i.e. you don’t need it to act like an `AbstractArray`, there is `Iterators.map`:

```julia
julia> for i in Iterators.map(exp10, -3:3)
           @show i
       end
i = 0.001
i = 0.01
i = 0.1
i = 1.0
i = 10.0
i = 100.0
i = 1000.0

```
