Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
BridgingBot
@GitterIRCbot
[zulip] <Andrés Riedemann> The performance degradation comes with the type of the input, if it's a normal Vector{Int64}, it would be fine
[zulip] <Andrés Riedemann> If you start pass a vector of mixed elements, there is a performance cost because that vector cannot be stored efficiently in memory
BridgingBot
@GitterIRCbot
[irc] <lunik1> Is f(x::AbstractVector{<:Integer}) equivalent?
BridgingBot
@GitterIRCbot
[irc] <oddp> Hi, everyone! Say, what's the julia equivalent of this ruby snippet here? [1,2,3].fetch(4, 0)
[irc] <oddp> Essentially an array lookup that returns a default value, 0 in this case, whenever the given idx is out-of-bounds for the provided array.
BridgingBot
@GitterIRCbot
[irc] <oddp> Is this how I would do it in julia? isassigned(a, i) && a[i]
BridgingBot
@GitterIRCbot
[irc] <oddp> Ah no, can't do something like isassigned(a, i) && a[i] || 0
[irc] <oddp> Guess I'll go with the verbose if else variant then.
[irc] <oddp> Ah, julia has a ternary operator! That should do, good enough.
BridgingBot
@GitterIRCbot
[irc] <lunik1> you can do what you describe with dicts but not arrays afaik
BridgingBot
@GitterIRCbot
[irc] <oddp> Alright, thanks!
[irc] <lunik1> but you can just check the length rather than use isassigned
BridgingBot
@GitterIRCbot
[irc] <Andriamanitra> i believe you can do get([1,2,3], 4, 0)
[irc] <Andriamanitra> and for checking if something is within bounds there is checkbounds(Bool, [1,2,3], 0)
Benedikt Allendorf
@BenediktAllendorf
Are there any Best Practices on how to handle multiple Julia-Versions on Windows (e.g. trying the new beta while keeping a working v1.5)? I found JILL.py but it feels a bit weird to use Python to handle my Julia installations ;)
bhagwan
@bhagwan_:matrix.org
[m]
@BenediktAllendorf docker containers?
Benedikt Allendorf
@BenediktAllendorf
worth a try, but I'm using GUI stuff sometimes (like InteractiveChaos.jl) and I guess that's not working then
q3anbpfeik
@q3anbpfeik:matrix.org
[m]
hello, is this a place to also ask coding questions? I’m coming from JavaScript and I’m wondering how to get the current index value for the reduce function.
I’ve been looking at the docs but is just says to pass op, but that only seems to have to parameters.
So, let’s say I have reduce((x, y) -> string(x, y), ["A", "B", "C"]), but would like to have the output to be "1A2B3C".
I tried reduce((x, y, i) -> string(x, y), ["A", "B", "C"]) but I get no method matching (::getfield(Main, Symbol("##51#52")))(::String, ::String). (Which I don’t understand)
q3anbpfeik
@q3anbpfeik:matrix.org
[m]
Is there no better way than this: reduce((acc, (n, item)) -> string(acc, n, item), enumerate(["A", "B", "C"]); init = "")?
BridgingBot
@GitterIRCbot
[irc] <lunik1> Is it possible to use PackageCompiler.jl to create binaries which are suitable for distribution by e.g. a linux distro's package manager?
BridgingBot
@GitterIRCbot
[irc] <[exa]> Hi everyone! Is there some good reading/recommendations/best practices about bundling C/C++ code (various ugly library wrappers in this particular case) in Julia packages?
[zulip] <Mason Protter> Yeah, I think the recommended strategy is to use the artifact system
BridgingBot
@GitterIRCbot
[irc] <linux_dream> hi juliaers. I have used python in the past (not a programmer), im self taught with lots of bad practices ,etc. and after looking at some julia code I noticed the arobase symbol @ here and there. what does this do exactly? for instance println() vs @println() ?
[irc] <lunik1> the @ symbol is used for macros
[irc] <linux_dream> thanks a lot lunik1
BridgingBot
@GitterIRCbot
[irc] <mefistofeles> linux_dream: trying Julia now?
BridgingBot
@GitterIRCbot
[irc] <linux_dream> just interested in it mefistofeles , possibly in part because you once told me you had tried it (I now use Matplotlib thanks to you, and that went as far as being in my thesis and 1 paper I copublished)
[irc] <mefistofeles> oh, thanks I guess haha
[irc] <mefistofeles> linux_dream: yeah, I tried once back in the early days, it wasn't that impressive back then but it has improved a lot lately, so don't take my word on it
[irc] <mefistofeles> I haven really tried it lately, just saw demos and such, it looks nice
[irc] <linux_dream> ok :)
BridgingBot
@GitterIRCbot
[irc] <amr> Does Julia have an equivalent of numpy's -1 in resizing?
[irc] <Andriamanitra> what is numpy's -1 in resizing?
[zulip] <Mason Protter> From the reshape docs:
help?> reshape
search: reshape promote_shape

  reshape(A, dims...) -> AbstractArray
  reshape(A, dims) -> AbstractArray

  Return an array with the same data as A, but with different dimension sizes or number of dimensions. The two arrays share the
  same underlying data, so that the result is mutable if and only if A is mutable, and setting elements of one alters the
  values of the other.

  The new dimensions may be specified either as a list of arguments or as a shape tuple. At most one dimension may be specified
  with a :, in which case its length is computed such that its product with all the specified dimensions is equal to the length
  of the original array A. The total number of elements must not change.

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  julia> A = Vector(1:16)
  16-element Vector{Int64}:
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16

  julia> reshape(A, (4, 4))
  4×4 Matrix{Int64}:
   1  5   9  13
   2  6  10  14
   3  7  11  15
   4  8  12  16

  julia> reshape(A, 2, :)
  2×8 Matrix{Int64}:
   1  3  5  7   9  11  13  15
   2  4  6  8  10  12  14  16

  julia> reshape(1:6, 2, 3)
  2×3 reshape(::UnitRange{Int64}, 2, 3) with eltype Int64:
   1  3  5
   2  4  6
[irc] <Andriamanitra> pasting walls of text doesn't work that great over the bridge
[zulip] <Mason Protter> Ah sorry. The moral is that : is for not specifying a dimension's size
[zulip] <Mason Protter> This is assuming that when you say "resize", you mean "reshape"
BridgingBot
@GitterIRCbot
[irc] <amr> Thanks. Yes. I have been programming in something else recently, where resize is common :)
[irc] <amr> I feel like last time I looked for it, I read the reshape help.. don't know how I missed it.
[irc] <amr> Thanks again!
1 reply
Mason Protter
@mprotter:matrix.org
[m]
For what it’s worth, I just checked on Element and the wall of text showed up fine. Maybe it’s no good on IRC though?
Christopher Smyth
@RossSmyth
Hi I have question on type checking. Specifically I am attempting to validate that the type of a function argument is an array of named tuples. I have Array{NamedTuple} but that produces an error because it seems check for the symbols that are part of the named tuple. I also tried Array{NamedTuple{Any}} but a similar thing happened.
Mason Protter
@mprotter:matrix.org
[m]
You likely want an Array{<:NamedTuple}
Julia’s parametric types are invariant by default
Christopher Smyth
@RossSmyth
Yup that's it! Thanks!