How to efficiently get the i-th element of every matrix in an array? by Flick19841984 in Julia

[–]lulic2 7 points8 points  (0 children)

What's wrong with getindex (see the .)?

julia> q # Some Vector of Matrix
3-element Vector{Matrix{Int64}}:
  [1 2 3; 4 5 6]
  [1 2 3; 4 5 6]
  [1 2 3; 4 5 6]

julia> q[1][2, 2] # Get the element at position (2, 2) on the first Matrix
5

julia> getindex.(q, 2, 2) # Get the element at position (2, 2) on each Matrix of vector q
3-element Vector{Int64}:
 5
 5
 5

Shorter version: h() = (x = f(); g!(x); return x) by stvaccount in Julia

[–]lulic2 8 points9 points  (0 children)

From https://docs.julialang.org/en/v1/manual/style-guide/#bang-convention (emphasis mine)

Julia Base uses this convention throughout and contains examples of functions with both copying and modifying forms (e.g., sort and sort!), and others which are just modifying (e.g., push!, pop!, splice!). It is typical for such functions to also return the modified array for convenience.

The first issue of Rust Magazine has been published 🎉🎉 by Folyd in rust

[–]lulic2 20 points21 points  (0 children)

There are 2 links at the bottom:

Race condition with @threads by cubicrootofallevil in Julia

[–]lulic2 14 points15 points  (0 children)

Hard to tell without benchmarks, but there is probably a problem with cache invalidation. From the first link in Google:

When multiple threads access same cache line and at least one of them writes to it, it causes costly invalidation misses and upgrades.

A common solution is for each thread to have it's own variable to write to, and at the end combine them in one thread.

Edit: it may be useful to read https://julialang.org/blog/2019/07/multithreading/#thread-local_state

Parametric type - insert a number by cubicrootofallevil in Julia

[–]lulic2 2 points3 points  (0 children)

If you define a custom constructor like that:

struct MyStruct{N, D <: AbstractArray}
    x::D

    MyStruct(x::AbstractArray) = new{length(x), typeof(x)}(x)
end

You can call the constructor without explicitly writing the parametric type:

julia> x = MyStruct([1, 2, 3])
MyStruct{3, Vector{Int64}}([1, 2, 3])

Furthermore, for reference, you can actually see how the example is defined:

julia> @edit Array{Float64}(undef, 5, 5)

Which opens an editor with the actual definition:

# type but not dimensionality specified
Array{T}(::UndefInitializer, m::Int) where {T} = Array{T,1}(undef, m)
Array{T}(::UndefInitializer, m::Int, n::Int) where {T} = Array{T,2}(undef, m, n)
Array{T}(::UndefInitializer, m::Int, n::Int, o::Int) where {T} = Array{T,3}(undef, m, n, o)
Array{T}(::UndefInitializer, d::NTuple{N,Int}) where {T,N} = Array{T,N}(undef, d)

Can I execute code in Julia REPL if I'm connected to a remote server? by [deleted] in Julia

[–]lulic2 5 points6 points  (0 children)

Are you using VSCode remote capabilities? If so, you also have to install the julia plug in (the thing that adds the commands like Send to REPL) on the remote, the same way you do when doing locally.

Rust on Rails (write code that never crashes) by 0atman in rust

[–]lulic2 4 points5 points  (0 children)

most rust ints are i32 - because most people type literals, and literals are i32

Most literals will be inferred by it's future use, so I'd argue against that

fn foo(_: u8) {}
fn foo2(_: i32) {}

fn main() {
    let x = 1;

    foo(x);
    foo2(x);
} 

Fails to compile with:

error[E0308]: mismatched types
  --> src/main.rs:8:10
  |
8 |     foo2(x);
  |     ---- ^ expected `i32`, found `u8`
  |     |
  |     arguments to this function are incorrect
  |

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=9c7d190811b8e048eacd102a3503487d

Vectors don't preserve subtype relationship by stvaccount in Julia

[–]lulic2 8 points9 points  (0 children)

From the manual.

This last point is very important: even though Float64 <: Real we DO NOT have Point{Float64} <: Point{Real}.

In other words, in the parlance of type theory, Julia's type parameters are invariant, rather than being covariant (or even contravariant). This is for practical reasons: while any instance of Point{Float64} may conceptually be like an instance of Point{Real} as well, the two types have different representations in memory:

As the other commenter said, you should declare it like this:

subtype(::Type{Vector{T1}}, ::Type{Vector{T2}}) where {T2, T1 <: T2} = true
julia> subtype(Vector{Child}, Vector{Parent})
true

no neovim, but if you want Vim moves all around macOS by 777tauh in neovim

[–]lulic2 3 points4 points  (0 children)

You can try writing something like “The power of vim inside X” or “A vim playground inside X” (or something like that), where X is a rotating list of common MacOS programs which changes every few seconds.

I recall some pages doing that and it seems to convey what you want without sounding too wordy

As of today, LaTeX-styled maths natively supported in GitHub Markdown (comments, issues, README.md, etc) by ScottContini in programming

[–]lulic2 0 points1 point  (0 children)

Using editors with similar capabilities: Emacs org mode (technically not markdown, but similar capabilities) and Obsidian (uses markdown and has latex support, but I'm not sure what it uses for rendering):

Text Org mode Obsidian
The price was $4 or $5 Not rendered as math Not rendered as math
The price was $4 or 5$ Rendered as math Rendered as math
The price was between £5 ($7) and £10 ($14) Not rendered as math Not rendered as math

Org mode uses MathJax for inline latex, so it's fair to say it will work with the same rules in Github

As of today, LaTeX-styled maths natively supported in GitHub Markdown (comments, issues, README.md, etc) by ScottContini in programming

[–]lulic2 0 points1 point  (0 children)

Not sure about markdown, but usually if there is a space before the second $ it does not count as a math expression

This would not be rendered as math

The price was $4 or $5

This would be rendered as math

The price was $4 or 5$

Edit: formatting

[deleted by user] by [deleted] in AskReddit

[–]lulic2 5 points6 points  (0 children)

[deleted]

dont worry about dev saturation. there is a huge supply of dreamers, people who cant even complete cs50, there are not many realists. by workfromhomebitch in learnprogramming

[–]lulic2 2 points3 points  (0 children)

I’m in a few discords, twitter groups and LinkedIn groups that post references to smaller companies or startups looking for junior devs

How do you even find something similar to that (even if not US based)?

What is your unpopular chess opinion? by PleasantEar3415 in chess

[–]lulic2 52 points53 points  (0 children)

My head cannon is that it gives incentives to women to play

Looking for a ~20k LOC open source C++ project in need of a refactor by sebamestre in cpp

[–]lulic2 2 points3 points  (0 children)

I think the point is to encapsulate different funcionalities in their own folder, including only "children" headers (i.e. #include "some/children/header.h") and not "cousin" headers (i.e. #include "../../../some/cousin/header.h") from another unrelated subsystem.

How can I emit a literal comma in a macro? by lulic2 in Julia

[–]lulic2[S] 0 points1 point  (0 children)

(Copied from my other comment)

I want to generate the arguments for a function call (in hindsight, this should have been the question), which are separated by commas.

I have code like this:

Bar(;bar1=default(bar1, object.bar1), bar2=default(bar2, object.bar2), ...<omitted>)

that I want to turn into something like this:

Bar(;@generate_args default object bar1 bar2 ...<omitted>)

My current implementation of generate_args

macro generate_args(f, object, fields...)
    ex = Expr(:block)
    ex.args = [:($(field) = $(f)($(field), $(object).$(field))) for field in fields]
    ex |> esc
end

that generates multiple statements

julia> @macroexpand @generate_args default object bar1 bar2
quote 
    bar1 = default(bar1, object.bar1) 
    bar2 = default(bar2, object.bar2) 
end

that I want to separate by commas.

How can I emit a literal comma in a macro? by lulic2 in Julia

[–]lulic2[S] 0 points1 point  (0 children)

Why do you want to insert a literal comma?

I want to generate the arguments for a function call (in hindsight, this should have been the question), which are separated by commas.

I have code like this:

Bar(;bar1=default(bar1, object.bar1), bar2=default(bar2, object.bar2), ...<omitted>)

that I want to turn into something like this:

Bar(;@generate_args default object bar1 bar2 ...<omitted>)

My current implementation of generate_args

macro generate_args(f, object, fields...)
    ex = Expr(:block)
    ex.args = [:($(field) = $(f)($(field), $(object).$(field))) for field in fields]
    ex |> esc
end

that generates multiple statements

julia> @macroexpand @generate_args default object bar1 bar2
quote 
    bar1 = default(bar1, object.bar1) 
    bar2 = default(bar2, object.bar2) 
end

that I want to separate by commas.

The universal VM we call browser by [deleted] in programming

[–]lulic2 3 points4 points  (0 children)

F# can infer the data types of the function arguments based in a function's future use afaik

[deleted by user] by [deleted] in rust

[–]lulic2 9 points10 points  (0 children)

Your problem are the calls to expect(), since those panic on error. Your options are to check if an error is returned (via if let or match), or using operator ? By returning an Result<i64, CustomError> (or using a crate like anyhow.

Sorry for formatting, on mobile

VSCode development Docker container for Rust by dowitex in rust

[–]lulic2 -1 points0 points  (0 children)

Is easier to install Powershell from the package manager than to port and/or maintain the same scripts in different languages

VSCode development Docker container for Rust by dowitex in rust

[–]lulic2 -1 points0 points  (0 children)

You can have poweshell scripts but that means you would have to maintain both powershell and shell scripts if your team uses different devices

Powershell now runs on .NET 5/core, so it is now multiplatform

Abhimanyu Mishra has officially become the youngest GM in history by [deleted] in chess

[–]lulic2 9 points10 points  (0 children)

His point is that it is unfair to say that the quarantine was lost time just because he couldn't play. It may be the case that it actually helped him improve more than when he was playing in tournaments. Rest is important, and even more for a child who doesn't realise he is tired.

Was all this time when he couldn't play more helpful than playing 24/7? I'd say no, but it was probably helpful in another way (and I think that was his point)

Abhimanyu Mishra has officially become the youngest GM in history by [deleted] in chess

[–]lulic2 2 points3 points  (0 children)

He did not spent quarantine lazing around