Quantcast
Channel: First steps - JuliaLang
Viewing all 2795 articles
Browse latest View live

Help understanding broadcasted pipe operator

$
0
0

@jonniedie wrote:

I would expect the result of

[1, 2] .|> u->u^2 |> sum

to give the answer 5 since

[1, 2] .|> u->u^2

gives

2-element Array{Int64,1}:
 1
 4

and

[1, 4] |> sum

gives 5.

Instead I am getting

[1, 2] .|> u->u^2 |> sum

2-element Array{Int64,1}:
 1
 4

What’s going on here? It seems like the second pipe is broadcasting over the vector even though I am not using the dot pipe operator.

What’s weird is I can call them separately in the REPL and it works the way I expect it to:

julia> [1, 2] .|> u->u^2
2-element Array{Int64,1}:
 1
 4

julia> ans |> sum
5

Posts: 5

Participants: 3

Read full topic


Can't see Julia in Jupyter's "new" menu

$
0
0

@Caterina_Cerutti wrote:

I can’t see Julia in Jupyter’s new. I have anaconda3 and Julia 1.2.0. I have written using Pkg and PKg.add(“IJulia”) and this procedure must be corrected. I cannot understand why. Can someone help me? PLEASE!

Posts: 3

Participants: 2

Read full topic

Julia Package for Unit Conversion

$
0
0

@Usor wrote:

Not exactly my first steps, but I saw no other place to post this.

Is there a Julia package taking care of unit conversions (like converting metres to miles, etc.)?

Posts: 5

Participants: 3

Read full topic

MethodError: no method matching isless(::Float64, ::Array{Float64,1})

What is the basic structure of a Julia Program?

$
0
0

@sara_J wrote:

I am new to Julia language but i need to know the basic structure of a Julia Program?
I asked in stack-overflow but they are not sure.
in c and java they have but in Julia I didn’t find and I search a lot

Posts: 6

Participants: 5

Read full topic

Workflow for local packages with local dependencies

$
0
0

@dapz wrote:

Hi, I am working simultaneously on a few Julia packages. Until now, all these packages are only local, so when I have for instance a local package A depending on another local package B, I add B as a dependency using ]dev B in A’s environment.

But when I do so, the Manifest file of A contains a local link to the folder where B is developed (seems normal). My question is, how do you do when you want to release both A and B publicly somewhere (and still keep working on them locally) ?

The only way I see to get rid of all the local paths in the Manifest file is to add public-url-to-B rather than dev B, but if you do that then you need to commit every single change to B in order to use it (and update the environment), which can be painful for further development and seems unnecessary if you are the only person working on the repo (I guess that for repositories with many contributors, there might not be any other choice). Am I missing something, or is that the price to pay? What is the preferred workflow for such situations?

Posts: 2

Participants: 2

Read full topic

Understanding mutating functions correctly

$
0
0

@1991sig wrote:

I am taking the next step with Julia, and trying to learn more. Up to now, I have used it mostly just as a calculator, but I recently started to make my own modules and so on.

One thing I am having trouble understanding is how mutating functions work.

In the code below, I send in a mutable struct, GLMFit, and want to set some of its fields/attributes with this function (full code at the end).

If I do not include this part after the loop is finished, the \beta-, \mu-, and \eta-vectors have the same value as before the loop.

        M.Fit.β = β
        M.Fit.μ = μ
        M.Fit.η = η

But the \beta is still changed inside the function, before the loop, since I set the first element equal to the mean of y, with this code:

if sum(β) == 0
    β[1] = sum(y)/length(y)
end

It is just the changes to \beta that happen inside the loop which are not captured, unless I specifically include the M.Fit.β = β after the loop.

Am I doing something wrong, or is the M.Fit.β = β and same for the other vectors strictly necessary in these cases?

The full code for the function:

function FisherScoring!(M::GLMFit, maxiter=25, tol=1e-10)
        dist, lp, link = M.Model.d, M.Model.lp, M.Model.g
        X = lp.X
        β = M.Fit.β
        μ = M.Fit.μ
        y = M.Fit.y
        η = M.Fit.η
        p = length(β)

        local J, Jinv, w

        if sum(β) == 0
            β[1] = sum(y)/length(y)
        end

        for i in 1:maxiter

            η = X * β
            μ = InverseLinkFunction(link, η)
            w = Var(dist, μ)

            U = Score(X, y, μ, dist, link)
            J = FisherInformation(X, w, dist, link)
            Jinv = inv(J)

            βtemp = β

            β = β + Jinv * U
            δ = β - βtemp
            if sqrt(δ' *  δ) < tol
                println(@sprintf "Stopping after %d iterations" i)
                M.Fit.SE = sqrt.(diag(Jinv))
                break
            else
                L = Likelihood(dist, μ, y)
                println(@sprintf "Fisher Iteration %d 𝐿(β) = %.12f" i L)
                M.Fit.SE = sqrt.(diag(Jinv))
            end
        end
        M.Fit.β = β
        M.Fit.μ = μ
        M.Fit.η = η
        M.Fit.𝐃 = Deviance(dist, μ, y)
        M.Fit.DoF = length(y) - length(β)
        L = Likelihood(dist, μ, y)
        M.Fit.AIC = AIC(length(β), L)
        M.IsFitted = true
end

Posts: 4

Participants: 3

Read full topic

Failure to add package Gmsh

$
0
0

@egcjm wrote:

I fail to install package Gmsh. After Pkg.add(“Gmsh”), using Gmsh and Pkg.build(“Gmsh”) produce the errors below. I am an administrator on my Windows 10 environment running Julia 1.2 yet Pkg.build command seems to think otherwise: “On Windows, creating file symlinks requires Administrator privileges”. Any help appreciated. -Eric

ERROR: LoadError: Gmsh not installed properly, run Pkg.build(“Gmsh”), restart Julia and try again
Stacktrace:
[1] error(::String) at .\error.jl:33
[2] top-level scope at C:\Users\emichiel.julia\packages\Gmsh\eZVOZ\src\Gmsh.jl:6
[3] include at .\boot.jl:328 [inlined]
[4] include_relative(::Module, ::String) at .\loading.jl:1094
[5] include(::Module, ::String) at .\Base.jl:31
[6] top-level scope at none:2
[7] eval at .\boot.jl:330 [inlined]
[8] eval(::Expr) at .\client.jl:432
[9] top-level scope at .\none:3
in expression starting at C:\Users\emichiel.julia\packages\Gmsh\eZVOZ\src\Gmsh.jl:5

julia> Pkg.build(“Gmsh”)
Building Gmsh → C:\Users\emichiel\.julia\packages\Gmsh\eZVOZ\deps\build.log
┌ Error: Error building Gmsh:
│ ┌ Warning: On Windows, creating file symlinks requires Administrator privileges
│ └ @ Base.Filesystem file.jl:797
│ ERROR: LoadError: Your platform (“x86_64-w64-mingw32”, parsed as “x86_64-w64-mingw32-gcc7-cxx11”) is not supported by this package!
│ Stacktrace:
│ [1] error(::String) at .\error.jl:33
│ [2] top-level scope at C:\Users\emichiel.julia\packages\Gmsh\eZVOZ\deps\build.jl:26
│ [3] include at .\boot.jl:328 [inlined]
│ [4] include_relative(::Module, ::String) at .\loading.jl:1094
│ [5] include(::Module, ::String) at .\Base.jl:31
│ [6] include(::String) at .\client.jl:431
│ [7] top-level scope at none:5
│ in expression starting at C:\Users\emichiel.julia\packages\Gmsh\eZVOZ\deps\build.jl:22
│ caused by [exception 1]
│ IOError: symlink: operation not permitted (EPERM)
│ Stacktrace:
│ [1] uv_error at .\libuv.jl:90 [inlined]
│ [2] symlink(::String, ::String) at .\file.jl:800
│ [3] probe_symlink_creation(::String) at C:\Users\emichiel.julia\packages\BinaryProvider\gnxnM\src\PlatformEngines.jl:121
│ [4] #probe_platform_engines!#30(::Bool, ::typeof(BinaryProvider.probe_platform_engines!)) at C:\Users\emichiel.julia\packages\BinaryProvider\gnxnM\src\PlatformEngines.jl:175
│ [5] probe_platform_engines! at C:\Users\emichiel.julia\packages\BinaryProvider\gnxnM\src\PlatformEngines.jl:169 [inlined]
│ [6] init() at C:\Users\emichiel.julia\packages\BinaryProvider\gnxnM\src\BinaryProvider.jl:28
│ [7] _include_from_serialized(::String, ::Array{Any,1}) at .\loading.jl:685
│ [8] _require_search_from_serialized(::Base.PkgId, ::String) at .\loading.jl:765
│ [9] _require(::Base.PkgId) at .\loading.jl:990
│ [10] require(::Base.PkgId) at .\loading.jl:911
│ [11] require(::Module, ::Symbol) at .\loading.jl:906
│ [12] include at .\boot.jl:328 [inlined]
│ [13] include_relative(::Module, ::String) at .\loading.jl:1094
│ [14] include(::Module, ::String) at .\Base.jl:31
│ [15] include(::String) at .\client.jl:431
│ [16] top-level scope at none:5
└ @ Pkg.Operations C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.2\Pkg\src\backwards_compatible_isolation.jl:647
false

Posts: 7

Participants: 3

Read full topic


Deleterows! column length error

No OpenCascade or FLTK on GMSH

$
0
0

@Gig wrote:

I was interesting in using GMSH with Julia.
I’ve installe the api and everything works fine until I don’t try to use fltk or the functions in ooc that uses opencascade, if I try to run for example: gmsh.model.ooc.addBox(-R,-R,-R, 2R,2R,2*R, 1),
I revieve the following error:

gmshModelOccAddBox returned non-zero error code: 1
error(::String) at error.jl:33
addBox(::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Int64) at gmsh.jl:3234
top-level scope at none:0

someone know the problem?

Posts: 1

Participants: 1

Read full topic

Accessing file from google drive

Repl in Juno, type enter and report an error

$
0
0

@nick-stu wrote:

I successfully installed Julia, atom, and Juno (including july-client, etc.)
julia version 0.6.4
It runs successfully directly from the command line.


But in the repl in atom, pressing enter causes the following error
Press Enter to start Julia. 
ERROR: LoadError: UndefVarError: @error not defined
Stacktrace:
 [1] include_from_node1(::String) at .\loading.jl:576
 [2] include(::String) at .\sysimg.jl:14
 [3] process_options(::Base.JLOptions) at .\client.jl:305
 [4] _start() at .\client.jl:371
while loading C:\Users\*****\.atom\packages\julia-client\script\boot_repl.jl, in expression starting on line 1

I’ve tried to reinstall july-client, and Julia Path has been set.
How to solve it? Thank you in advance.

Posts: 4

Participants: 3

Read full topic

Composite type whose fields are all different suptypes of a supertype

$
0
0

@MatFi wrote:

I have a composite type whose fields are all different suptypes of a supertype. Can this be expresses in a more elagnat way then shown below?

struct Operators{A<:AbstractArray{Float64,2}, L<:AbstractArray{Float64,2}, D<:AbstractArray{Float64,2}, AH<:AbstractArray{Float64,2}, LH<:AbstractArray{Float64,2}, DH<:AbstractArray{Float64,2},AE<:AbstractArray{Float64,2}, LE<:AbstractArray{Float64,2}, DE<:AbstractArray{Float64,2}}
    𝕴::A
    𝕴ₑ::AE
    𝕴ₕ::AH
    𝔏::L
    𝔏ₑ::LE
    𝔏ₕ::LH
    𝔇::D
    𝔇ₑ::DE
    𝔇ₕ::DH
end
end

I thout about someting like

struct Operators{A, L, D, AH, LH, DH, L, LE, DE} where {A, L, D, AH, LH, DH, L, LE, DE} <:AbstractArray{Float64,2}
    𝕴::A
    𝕴ₑ::AE
    𝕴ₕ::AH
    𝔏::L
    𝔏ₑ::LE
    𝔏ₕ::LH
    𝔇::D
    𝔇ₑ::DE
    𝔇ₕ::DH
end

Any suggestions about style and how to do better are welcome.

Posts: 9

Participants: 4

Read full topic

Unable to run Julia in Atom

$
0
0

@gcalajo wrote:

I was using Julia v 0.64 ( I need to use a code written in this version) in Atom in the last months without any issues.
Today the REPL was not able to start Julia exting all time.
I so uninstalled and reinstalled again both Julia, Atom and all the related folders.
Now it gives me this error-

Press Enter to start a new session.
ERROR: LoadError: UndefVarError: @error not defined
Stacktrace:
[1] include_from_node1(::String) at .\loading.jl:576
[2] include(::String) at .\sysimg.jl:14
[3] process_options(::Base.JLOptions) at .\client.jl:305
[4] _start() at .\client.jl:371
while loading C:\Users\gcalajo.atom\packages\julia-client\script\boot_repl.jl, in expression starting on line 1

I retried to repeat uninstall and reinstall again and give me always the same error.
Someone can help?

Posts: 7

Participants: 3

Read full topic

Cannot import some python packages due to CLIBCXX version mismatch

$
0
0

@aplavin wrote:

I’m using PyCall with python from my anaconda installation, i.e. ENV["PYTHON"] = "/home/aplavin/anaconda3/bin/python". Almost everything has been working fine, but I’m unable to load xgboost package: pyimport("xgboost") throws

ERROR: PyError (PyImport_ImportModule) <class 'xgboost.core.XGBoostError'>
XGBoostError('XGBoost Library (libxgboost.so) could not be loaded.\nLikely causes:\n  * OpenMP runtime is not installed (vcomp140.dll or libgomp-1.dll for Windows, libgomp.so for UNIX-like OSes)\n  * You are running 32-bit Python on a 64-bit OS\nError message(s): ["/home/aplavin/julia-1.2.0/bin/../lib/julia/libstdc++.so.6: version `GLIBCXX_3.4.26\' not found (required by /home/aplavin/anaconda3/lib/python3.7/site-packages/xgboost/./lib/libxgboost.so)"]\n')
  File "/home/aplavin/anaconda3/lib/python3.7/site-packages/xgboost/__init__.py", line 11, in <module>
    from .core import DMatrix, Booster
  File "/home/aplavin/anaconda3/lib/python3.7/site-packages/xgboost/core.py", line 161, in <module>
    _LIB = _load_lib()
  File "/home/aplavin/anaconda3/lib/python3.7/site-packages/xgboost/core.py", line 152, in _load_lib
    'Error message(s): {}\n'.format(os_error_list))

As I understand, it requires GLIBCXX_3.4.26 while Julia has another version which it tries to use here. Of course, everything works fine when I do import xgboost from plain Python REPL, because it uses the library from conda (I suppose) which has the matching version. I tried playing with ld_library_path and other environment variables, but no success.

So, the question is - how do I use the installed python package through PyCall, providing it with the correct libstdc++?

Posts: 1

Participants: 1

Read full topic


Error on running tests for a self-written package

$
0
0

@peterlane wrote:

I have written a package along with some unit tests, which I would like to be able to run once the package is added to Julia. But I get an error:

pkg> add gitlink-to-PackageName
pkg> test PackageName
ERROR: LoadError: ArgumentError: Package Test not found in current path:
- Run `import Pkg; Pkg.add("Test")` to install the Test package.

I do: pkg> add Test
which adds Test to the package list, but still ‘test PackageName’ fails with the same error.

I am using Julia 1.2.0. I can run tests on other packages I have installed.

Questions:

  1. What step am I missing, so the ‘Test’ package I load in ‘pkg’ is available to my package’s ‘runtests’?
  2. Why does ‘Test’ need installing separately, if it’s in the stdlib?

I am following the (possibly outdated) page: http://www.stochasticlifestyle.com/finalizing-julia-package-documentation-testing-coverage-publishing/

I had to replace ‘using Base.Test’ with ‘using Test’, but apart from that,

  • PackageName/src has my code
  • PackageName/test has ‘runtests.jl’

$ julia test/runtests.jl runs and shows all tests passing.

Posts: 5

Participants: 3

Read full topic

JuliaMedicine Domain

$
0
0

@PharmCat wrote:

Is it possible to create JuliaMedicine domain or something like this? I found BioJulia, but this domain include bioinformatics packajes that not in clinical trials or medicine sphere. MAny pckages in JuliaStats or in others domains can be applied to medicine but i think there are packages like pharmakokinitics/pharmacodynamycs, randomization, trial simulation, MRT and others graphics analysis in medicine can be under this domain.

Posts: 4

Participants: 3

Read full topic

Executing a method given its name as a string

$
0
0

@frtps wrote:

I would like to define a macro that would execute a function having been provided its name in a string-valued variable. So the following code gives a naive implementation:

macro invoke_callback(c,args...) =
quote
eval(Symbol($c))($args...)
end
end

However, while it works in the REPL for testing, it doesn’t work in more complex situations where the expression “c” and/or its contents are defined in a different module to the invocation site of the macro. I think this is because the eval method that is used is the one from the module in which the macro is invoked, and so it doesn’t necessarily have access to the module from which expression “c” has been passed.

So the question is, is there an elegant way to access the appropriate eval, or should I just go about this a different way, e.g by using a Dict{String,Function}?

Posts: 1

Participants: 1

Read full topic

How to plot columns of a matrix on a single line graph in Julia

Why are for loops slower than broadcast with splatted arguments?

$
0
0

@jlchan wrote:

I’m broadcasting functions which return tuples, and have been converting arrays of tuples to tuples of arrays using “unzip”. I used for loops over each individual entry and re-assembled the output as a tuple.

using BenchmarkTools

function foo(a,b,c,d)
    ab = exp(a*b)
    return ab+c, ab-d
end

N = 10000
a,b,c,d = [randn(N) for i = 1:4]
X = (a,b)
Y = (c,d)

function foo_loop(N,a,b,c,d)
    for i = 1:N
        foo(a[i],b[i],c[i],d[i])
    end
end
@btime foo_loop($N,$a,$b,$c,$d)

function foo_loop_splat!(N,X,Y,X_entry,Y_entry)
    for i = 1:N
        for fld in eachindex(X)
            X_entry[fld] = X[fld][i]
            Y_entry[fld] = Y[fld][i]
        end
        foo(X_entry...,Y_entry...)
    end
end
X_entry, Y_entry = [zeros(length(X)) for i = 1:2]
@btime foo_loop_splat!($N,$X,$Y,$X_entry,$Y_entry)

I noticed that the splatted for loop is much slower than the broadcasted “unzip” approach

  102.436 μs (0 allocations: 0 bytes)
  1.046 ms (50000 allocations: 937.50 KiB)

In comparison, using broadcasting and unzip

unzip(a) = map(x->getfield.(a, x), fieldnames(eltype(a)))
@btime unzip(foo.($X...,$Y...))
@btime unzip(foo.($a,$b,$c,$d))

both runtimes are about the same

  158.962 μs (8 allocations: 312.78 KiB)
  156.331 μs (8 allocations: 312.78 KiB)

Why does this occur? I’m not clear on why splatting adds so much extra time. Is it runtime dispatch?

Posts: 6

Participants: 4

Read full topic

Viewing all 2795 articles
Browse latest View live