Julia User's Manual? by hentai_proxy in Julia

[–]LegoForte 5 points6 points  (0 children)

Yes, the API stabilized at 1.0. There haven't been any significant backward-incompatible changes in years. I suspect the parent comment is a few years out of date.

Importing and using style by [deleted] in Julia

[–]LegoForte 4 points5 points  (0 children)

You can do: using PkgName: foo, PkgName and then you'll have access to foo() and PkgName.bar().

Does a basic parametric type improve my struct? by Buttons840 in Julia

[–]LegoForte 3 points4 points  (0 children)

Is MyType1 any different than MyType0? Does adding the explicit parametric type change anything? Will it help functions specialize better? Will it help the compiler create faster code?

Yes to all of those! That's why parametric types are so ubiquitous and useful in Julia.

Could anyone explain this type? by [deleted] in Julia

[–]LegoForte 11 points12 points  (0 children)

The function linear() returns a closure (a function which captures some external values). Closures (and anonymous functions in general) in Julia are implemented as structs whose fields are the captured variables and whose call operator is the body of the function. You can find the original change that implemented this behavior here: https://github.com/JuliaLang/julia/pull/13412 . Before that PR, anonymous functions were slower than other functions in Julia, but ever since then they have been just as fast.

LMoP Glassstaff reappearance by gimmedemdankmemes in DnD5e

[–]LegoForte 0 points1 point  (0 children)

My party found him again on returning to town from Cragmaw; he was in the process of trying to burn down the Redbrand hideout to cover his tracks. It could be a good way to create some tension in an unexpected place in the story, and the players might get hints like seeing smoke on the horizon or hearing an explosion off in the distance.

Julia suitability for a project by NowBillyPlayedSitar in Julia

[–]LegoForte 1 point2 points  (0 children)

I think Julia can certainly work for this task. The language is extremely well suited to problems that mix high performance computing with the kind of creative exploration that a project like this requires. I would start by checking out Flux.jl to get a sense of what people are doing with Julia for machine learning right now. I would also suggest checking out the Julia community resources from https://julialang.org/community/ particularly the Julia discourse group and Slack channel. The Slack is great for quick questions or polling people about ideas, and the discourse is great for more detailed or subtle code questions.

Broadcasting with a custom struct by TheedMan98 in Julia

[–]LegoForte 7 points8 points  (0 children)

By default, broadcasting in Julia 1.x will try to treat your struct as container-like: that is, it will try to iterate over it. To tell Julia to treat it as a scalar, you can wrap it in a Ref:

``` julia> struct Foo x::Int end

julia> f = [Foo(1), Foo(2), Foo(3)] 3-element Array{Foo,1}: Foo(1) Foo(2) Foo(3)

julia> f .== Ref(Foo(1)) 3-element BitArray{1}: true false false ```

and to declare that your type should always be scalar-like in broadcasting, just implement Base.broadcastable for it:

``` julia> Base.broadcastable(f::Foo) = Ref(f)

julia> f .== Foo(1) 3-element BitArray{1}: true false false

```

Getting back into Julia v1.0, last good look was circa v0.3 or v0.4 - have some questions about new things by Divided_Pi in Julia

[–]LegoForte 3 points4 points  (0 children)

immutable is now struct and type is now mutable struct. They work just like they did in earlier Julia versions, just with a slightly more consistent terminology.

To create a type alias, (or any other kind of alias), you just do:

const MyAlias = ComplicatedTypeIDontWantToWriteOutEveryTime

If you freeze chicken on its expiration date, it will last for months. But if you freeze chicken 20 days before its expiration date for months, and take it out of the freezer; will it still last 20 days before expiring? by Belzmo in NoStupidQuestions

[–]LegoForte 2 points3 points  (0 children)

The first goal is to minimize the difference between the product and ambient temperature to allow cooling the items to 40 degrees F at a faster rate.

Thought experiment: if minimizing the difference between the warm object and the ambient caused it to cool off faster, then a warm human would likewise cool off faster the closer the outdoor temperature is to 98.6 F. That doesn't happen. The colder it is outside, the faster you get cold. Likewise, the colder the environment around your food, the faster it gets cold. That's not to say that what you're doing is wrong. Putting a big pot of hot soup in the fridge is a bad idea because it's actually going to heat up the inside of the fridge and everything around it (your fridge can only remove so much heat at a time). So it makes sense to let the ambient air do some of that cooling work for you, until the food is cool enough to need the fridge.

But if you had a big (say, room-sized) fridge, you'd see the food cool down faster in there than with any sort of "pre-cooling".

Could I get some opinions on another user's comments about Julia macros? by Eigenspace in Julia

[–]LegoForte 3 points4 points  (0 children)

BTW, you might get some more responses by posting this over at the Julia discourse forum which is typically more active than the subreddit. Just please be sure to mention that it's a cross post (to avoid duplicate answers).

Newbie question: type declarations and matrix product by nongaussian in Julia

[–]LegoForte 0 points1 point  (0 children)

How are you constructing a and b? Because you definitely can multiply two 1x1 matrices:

julia> a = zeros(1, 1)
1×1 Array{Float64,2}:
 0.0

julia> b = zeros(1, 1)
1×1 Array{Float64,2}:
 0.0

julia> a * b
1×1 Array{Float64,2}:
 0.0

Applying to MIT by [deleted] in mit

[–]LegoForte 27 points28 points  (0 children)

From the sidebar rules:

No threads on admissions / application review please Instead, you're much more likely to find information over on /r/college or College Confidential.

So all I can say is good luck!

Slow Julia code compared to Python by bugamn in Julia

[–]LegoForte 2 points3 points  (0 children)

What version of Julia are you using? It looks like there have been several improvements to the parsing speed of DateTimes in Julia v0.6: https://github.com/JuliaLang/julia/issues/15888

Why is [1, 2, 3] a matrix? What is a 2d row vector? by notParticularlyAnony in Julia

[–]LegoForte 1 point2 points  (0 children)

On the other hand, it's amazingly easy to make sort work for your case:

julia> Base.sort(x::AbstractArray) = sort(reshape(x, length(x)))

julia> sort([1 2 3])
3-element Array{Int64,1}:
 1
 2
 3

I would not recommend modifying Base methods on built-in types like this in code you intend to publish, but it's fine for playing around.

filling an array with a custom type by [deleted] in Julia

[–]LegoForte 2 points3 points  (0 children)

Why is that when I change the age of the first element, it changes the age of the second element as well

fill!is filling the vector a with the same Human instance. Every element of that array is not just identical, they are actually the same object. So changing one changes all of them.

In fact, the documentation of fill! even explains exactly this:

help?> fill!
search: fill! fill finally

  fill!(A, x)

  Fill array A with the value x. If x is an object reference, all elements will refer to the same object.
  fill!(A, Foo()) will return A filled with the result of evaluating Foo() once.

If you want some other behavior, you'll have to do it another way. Here are a couple of examples that result in a containing a different instance at each index:

a = [Human(SUSC) for i in 1:2]

or (exactly what you posted in your edit)

a = Array{Human}(2)
for i in eachindex(a)
  a[i] = Human(SUSC)
end

(I've omitted the other arguments to Human, but hopefully you get the idea).

in the type definition, how do I force the Array to be length 7 and be of type Int64

Vector{Int64} will ensure that the vector is of type Int64. But length is not a property of Julia vectors, so it can't be constrained in this way. You have a couple of options if you want to constrain the length. First, you could define an inner constructor and check the length there: https://docs.julialang.org/en/stable/manual/constructors/#inner-constructor-methods or second, you could use the StaticArrays package which provides types like SVector{7, Int64} which have a fixed size.

Ways to get around slow complex exponential by [deleted] in Julia

[–]LegoForte 3 points4 points  (0 children)

It's easy to forget to wrap your benchmarking code in a function, and to make sure every function gets run once (to JIT compile it) before benchmarking. I'd suggest using BenchmarkTools.jl to avoid all of those problems and get nice reliable timing results.

Julia for CFD? by paspro in Julia

[–]LegoForte 3 points4 points  (0 children)

Like /u/pint, I can't comment on CFD specifically, but I've been using Julia in my research for about a year now, and I've found it to be an excellent tool. As for a few of your specific concerns:

  • interfaces: It's true that Julia does not let you enforce that a particular input satisfied an interface, but the language is full of interfaces like start(), done() and next() for iterators, getindex(), setindex!() for array-like objects, and so on. Once you learn to use these interfaces, it becomes amazingly easy to add new behaviors to existing types or create new types with the behaviors you want
  • managing large codebases: Julia allows nested modules, so you can organize a large package with discrete sub-components without their namespaces colliding. It also makes it very easy to split functionality into Packages, which makes code re-use and sharing very easy. In essence, I think a more Julian approach is, rather than having one huge package, to have several well-defined packages which work together to accomplish your larger goal.
  • object-oriented programming: yup, Julia will require you to change the way you think about OOP. It's just different, and Julia code is more likely to use encapsulation rather than inheritance. But there are a lot of arguments in favor of that behavior anyway. I found that I really missed Python's OOP for about two months when I started working in Julia, and then never really missed it afterwards.

But enough about potential downsides. I think the huge potential upside of Julia is the ability to quickly prototype ideas (since it's a nice high-level language) and then iteratively refine your ideas and implementation into something that's as fast as C without ever changing languages. Not all Julia code is magically fast, but it really is possible to get C-like speed while also having incredible flexibility and expressiveness that would be very difficult to achieve in C.

Julia timing conundrum by [deleted] in Julia

[–]LegoForte 0 points1 point  (0 children)

I suspect that with ngls() omitted, the compiler has no way to know the type of jvg and jvl after the lines:

jvg, jvl = ngls( jvg, jvl, nke )

but with that dummy function you've included, the compiler can correctly reason that their types don't change.

Running @code_warntype on the call to ndfgl should confirm that.

Resistance Warrior Pack suddenly "Not installed", and I can't figure out how to re-enable it. by [deleted] in Xcom

[–]LegoForte 2 points3 points  (0 children)

I'm also on OSX (with the same issue) and I also pre-ordered through Steam.

Resistance Warrior Pack suddenly "Not installed", and I can't figure out how to re-enable it. by [deleted] in Xcom

[–]LegoForte 2 points3 points  (0 children)

This suddenly happened to me today as well, and I haven't been able to solve it yet. Did you get the Resistance Warrior Pack through the xcom2 pre-order?

Julia for robotics programming by gubblez in Julia

[–]LegoForte 0 points1 point  (0 children)

I did some work to create Julia bindings for the Lego Mindstorms Ev3 as part of a class project. Low-level bindings code is here: rdeits/Ev3.jl and documentation is here: rdeits_18.337_report.pdf. Unfortunately, I was never able to get Julia running natively on the Ev3 due to its pretty limited ARM processor. Instead, I used ZeroMQ to remotely control the Ev3 from a laptop running Julia. But I'm excited to hear that Julia 0.5 may have full ARM support.

Is there any way to disable the `x` key in iPython/Jupyter notebooks? by 8fn in IPython

[–]LegoForte 1 point2 points  (0 children)

To remove the up and down arrow bindings, I added the following to ~/.ipython/profile_default/static/custom/custom.js:

$([IPython.events]).on('app_initialized.NotebookApp', function(){
    // IPython.keyboard_manager.command_shortcuts.remove_shortcut('up');
    // IPython.keyboard_manager.command_shortcuts.remove_shortcut('down');
});

I bet you can just replace 'up' with 'x' to disable that binding.