!WTvnrBXAWIqKuxyqrR:matrix.org

Julia (lang)

314 Members
General help and discussion about the Julia language36 Servers

Load older messages


SenderMessageTime
22 Dec 2022
@neoabs:matrix.orgneoabsimage.png
Download image.png
07:48:34
@neoabs:matrix.orgneoabsimage.png
Download image.png
07:49:23
@neoabs:matrix.orgneoabsimage.png
Download image.png
07:50:36
@neoabs:matrix.orgneoabsI think you can also modify it within local scope. However as you are running version 1 it will complete even if function definition is modified to version two before end07:51:27
24 Dec 2022
@jasonjckn:matrix.orgNull_AScreenshot 2022-12-23 at 7.19.38 PM.png
Download Screenshot 2022-12-23 at 7.19.38 PM.png
03:19:53
@jasonjckn:matrix.orgNull_A
In reply to @jasonjckn:matrix.org
sent an image.
That's interesting, not exactly what I meant, wanted while true { afn() } , to redefine afn using Revise , I got the solution though ^
03:20:09
@jasonjckn:matrix.orgNull_AThanks for your help no less 03:20:57
@wehandre:matrix.physik.uni-augsburg.deAndreas Weh

Is there a best practice in Julia for views?
I find myself putting a @views in front of almost every line to avoid needles allocations.

It feels like there should be a smarter way for a modern language.

08:20:43
@neoabs:matrix.orgneoabsX = view(array, dims) 10:02:08
@neoabs:matrix.orgneoabs
In reply to @wehandre:matrix.physik.uni-augsburg.de

Is there a best practice in Julia for views?
I find myself putting a @views in front of almost every line to avoid needles allocations.

It feels like there should be a smarter way for a modern language.

does above help?
10:40:12
@wehandre:matrix.physik.uni-augsburg.deAndreas Weh
In reply to @neoabs:matrix.org
X = view(array, dims)
Most of the time, I need begin/end, so I thing I have to use things like
X = @view(array[dims])
12:09:38
@wehandre:matrix.physik.uni-augsburg.deAndreas Weh Typically, I have things like
@views @. x[i:j] = a[k:l] + b[m:n] which is not exactly readable and seems like it produces more complicated lowered code.
12:12:21
@neoabs:matrix.orgneoabsyou can define variable to be view.if you use it later it does not need to have @view in fornt. https://discourse.julialang.org/t/could-you-explain-what-are-views/17535 here is example https://www.juliabloggers.com/the-view-and-views-macros-are-you-sure-you-know-how-they-work/ 12:15:08
@neoabs:matrix.orgneoabs

try:

A = ones(10,10)
a = view(A,1:10,1)
a *= 2
A[1:10,1:2]
12:16:52
@neoabs:matrix.orgneoabs *

try:

A = ones(10,10)
a = view(A,1:10,1)
a *= 2
A[1:10,1:2]
a = view(A,1:10,1)
12:25:53
@neoabs:matrix.orgneoabs *

try:

A = ones(10,10)
a = view(A,1:10,1)
a *= 2
A[1:10,1:2]
a = view(A,1:10,1)
a[:] = a*2
A[1:10,1:2]
12:26:16
@neoabs:matrix.orgneoabsdoes it help?> 12:26:33
@neoabs:matrix.orgneoabs I am not sure if line 3 works as intended but it seems you need to reference view as a[:] or it changes type to array instead of view 12:27:17
@neoabs:matrix.orgneoabs
# after above
a[:] *=2 
print(A[:,1:2])

Wonder if it is a bug or feature

12:29:05
@wehandre:matrix.physik.uni-augsburg.deAndreas WehThanks for the hint, I'll give it a try14:21:32
@neoabs:matrix.orgneoabs Andreas Weh: Merry Christ-Mass 22:21:34
25 Dec 2022
@david_alfred:matrix.orgdavid_alfredMerry Christmas, everyone05:38:06
@wehandre:matrix.physik.uni-augsburg.deAndreas WehThanks, merry Christmas to you, too.10:13:11
4 Jan 2023
@onepointtwentyonegigawatts:matrix.orgonepointtwentyonegigawatts joined the room.14:54:34
@wehandre:matrix.physik.uni-augsburg.deAndreas Weh

Is there a fast way to count over SubArrays?
I had to put @views everywhere to avoid excessive copies, but this slowed count down, becoming my bottleneck (I think due to excessive bound checks).
Consider the following two functions

function test1(x, b, pad)
    _x = @view(x[begin+pad:end-pad])
    return count(>(b), _x)
end

function test2(x, b, pad)
    return sum(x[idx] > b for idx in 1+pad:length(x)-pad)
end

I get the following timings

julia> x = randn(10000);

julia> @btime test1($x, $0.5, $1);
  9.156 μs (0 allocations: 0 bytes)

julia> @btime test2($x, $0.5, $1);
  1.498 μs (0 allocations: 0 bytes)

Avoiding SubArrays gives me a six-fold speedup, but makes my code exceedingly ugly.

22:21:32
@wehandre:matrix.physik.uni-augsburg.deAndreas Weh The example is of course constructed. My main points would be the possibility to just pass the SubArrays, sucht that my numerical functions don't have to care about bounds. 22:23:11
@wehandre:matrix.physik.uni-augsburg.deAndreas Weh *

Is there a fast way to count over SubArrays?
I had to put @views everywhere to avoid excessive copies, but this slowed count down, becoming my bottleneck (I think due to excessive bound checks).
Consider the following two functions

function test1(x, b, pad)
    _x = @view(x[begin+pad:end-pad])
    return count(>(b), _x)
end

function test2(x, b, pad)
    return sum(x[idx] > b for idx in 1+pad:length(x)-pad)
end

I get the following timings

julia> x = randn(10000);

julia> @btime test1($x, $0.5, $1);
  9.156 μs (0 allocations: 0 bytes)

julia> @btime test2($x, $0.5, $1);
  1.498 μs (0 allocations: 0 bytes)

Avoiding SubArrays gives me a six-fold speedup, but makes my code exceedingly ugly.

22:23:18
@wehandre:matrix.physik.uni-augsburg.deAndreas Weh

The following issue seems to contain some hints:
https://github.com/JuliaLang/julia/issues/43295

The following code doesn't perform as bad as count

function test3(a, b, pad)
       _x = @view(x[begin+pad:end-pad])
       return sum(@inbounds _x[idx] > b for idx in eachindex(_x), 0)
end

but it is still slower and contains some allocations:

julia> @btime test3($x, $0.5, $1);
  2.040 μs (9 allocations: 288 bytes)
23:14:07
@wehandre:matrix.physik.uni-augsburg.deAndreas Weh *

The following issue seems to contain some hints:
https://github.com/JuliaLang/julia/issues/43295

The following code doesn't perform as bad as count

function test3(a, b, pad)
       _x = @view(x[begin+pad:end-pad])
       return sum(@inbounds _x[idx] > b for idx in eachindex(_x))
end

but it is still slower and contains some allocations:

julia> @btime test3($x, $0.5, $1);
  2.040 μs (9 allocations: 288 bytes)
23:14:45
5 Jan 2023
@eduardorodrigues:matrix.orgMarco Eduardo Rodrigues da Silva joined the room.09:22:04

Show newer messages


Back to Room ListRoom Version: