Questions tagged [julia]

0

votes
0

answer
4

Views

Failed to precompile NumericalMath in Julia

I am trying to use a package from NumericalMath available at https://github.com/hwborchers/NumericalMath.jl. I have installed (?) the package by doing so: Pkg.clone("https://github.com/hwborchers/NumericalMath.jl.git"). However, when I issue the command using NumericalMath- the following error is re...
Schlator Borgenson
0

votes
1

answer
12

Views

How to hard code struct variables in Julia?

I have a Julia struct: struct WindChillCalc location::Tuple; w_underground_url::String; WindChillCalc(location, wug) = new(location, w_underground_url); end How do I hard code w_underground_url to contain "someString" upon the constructor of WindChillCalc being called?
jkaros
1

votes
1

answer
142

Views

Incremental text file processing for parallel processing

I'm at the first experience with the Julia language, and I'm quite surprises by its simplicity. I need to process big files, where each line is composed by a set of tab separated strings. As a first example, I started by a simple count program; I managed to use @parallel with the following code: d =...
Estoque'm'
3

votes
1

answer
18

Views

Dict with array key in julia

In julia language (ver 1.1.0), I am experimenting what would happen when I mutate a dictionary key. Before mutation, both the variable x and [1,2,3] is recognized. x = [1,2,3]; d = Dict(x=>"x") haskey(d, x) # true haskey(d, [1,2,3]) # true Once I mutate x, neither the variable x nor [1,2,3,4] is rec...
Kota Mori
1

votes
2

answer
75

Views

Concatenate Multidimensional arrays in Julia

I have an array of multi-dim arrays Array{Array{Float64,3},1} and what I want is a single 4 dimensional array Array{Float64,4}. I have gone through the other responses concatenate array in julia Concatenating arrays in Julia Multidimensional Array Comprehension in Julia But no combination of cat and...
user1902291
0

votes
0

answer
7

Views

Julia/Dates : convert a timespan from “days” to “year” or “Float64”

I would like to convert a timespan from "days" to "year" or "Float64" let be at timespan t: t = Date("2000-02-04") - Date("1996-06-04") However each following lines give me an error t/365 Float64(t) parse(Float64,t) convert(Dates.Year, t)
ecjb
0

votes
0

answer
4

Views

Updating a static array, in a nested function without making a temporary array? <Julia>

I have been banging my head against a wall trying to use static arrays in julia. https://github.com/JuliaArrays/StaticArrays.jl They are fast but updating them is a pain. This is no surprise, they are meant to be immutable! But it is continuously recommended to me that I use static arrays even thou...
Charlie Crown
1

votes
1

answer
57

Views

For loop inside vs outside function

I've been experimenting with this for a while but can't seem to come to a conclusion. If I have the following options, function fxn1() for i in 1:N do_something() end end function main() fxn1() end and function fxn2() do_something() end function main() for i in 1:N fxn2() end end Is there a general...
Renato
1

votes
1

answer
52

Views

Design pattern for preallocating data and passing it around in Julia

I am looking to improve certain aspects of how I write Julia code for a computation heavy program that operates on large arrays and matrices. There are a lot of private functions that do intermediate processing and the system was previously designed in C++ in such a way that memory was handled expli...
jc211
1

votes
2

answer
52

Views

3D scatter plot in Julia

Working in Julia and using Plots, I have an array of points that lie on two distinct surfaces. The points are mixed together such that doing a surface plot looks like garbage, because it tries to connect points on the two surfaces. I think the best way to get around this is to plot the points simp...
Yly
1

votes
1

answer
51

Views

What is the julia equivalent of np.indices in numpy?

In Python, there is np.indices, which returns the indices of a grid: Python 2.7.1 > import numpy as np > x,y = np.indices((2,2)) > x array([[0, 0], [1, 1]]) > y array([[0, 1], [0, 1]]) What would be a similar function in Julia? Especially for multidimensional grids. I tried eachindex, but it expects...
Streamfighter
1

votes
1

answer
76

Views

How to generate all possible sample paths in Julia from vectors of unequal length

I have 5 vectors t1,...,t5, of respective unequal lengths n1, .. ,n5. How can I generate an (n1*...*n5)x(5) matrix in Julia, which would be:
Chris Martin
2

votes
2

answer
18

Views

Problem implementing reciprocally nested structures in Julia

I am trying to define two structs, Node and Edge. A node contains an array of edges, while an edge contains the destination node and the probability of reaching that node. Because of how the rest of the problem is structured, I cannot avoid having the Edge object. struct Node edges::Vector{Edge} end...
0

votes
0

answer
23

Views

grouping sales aggregate by month using SQLite sandbox in Julia

I am using the SQLite package in Julia. I need to aggregate the sum of sales by months. I have 3 tables Order, Order items and products. I have tried a few queries but nothing seems to work. DataFrame(SQLite.Query(acme, """select strftime('%m',OrderDate)as month, sum(price*quantity) as sales from...
adi
1

votes
1

answer
74

Views

Get the type of objects in a container like Array or NullableArray

Suppose I have an object which has a type like NullableArray{Int64} -- how do I know that the elements have type Int64 (well, Nullable{Int64}) without actually accessing any element (ie, it can be done when the object is empty). Is there a general way to figure out what SubType is from an object of...
ARM
1

votes
2

answer
667

Views

Parametric return types

I'm trying to understand how parametric types work in Julia. Suppose I have a function foo, which takes an Integer (i.e. non-parametric type), and I want to assert this function to return a vector, whose elements are subtypes of Real. From documentation I deduced that it should be implemented as fol...
aberdysh
1

votes
1

answer
186

Views

Trying to improve execution time of Julia code

I need to write a code to generate a string using a grammar with just one rule. For example, if the rule is "G -> [G+G]", and we apply the rule to "G", the result is the string "[G+G]"; if we apply it to the previous result, we obtain "[[G+G]+[G+G]]" and so on. In other words, it's about rewritting...
Jennifer Hurtado
1

votes
1

answer
78

Views

Changing function arguments to keywords in Julia seems to introduce type instability

I have a program in which the main() function takes four arguments. When I run @code_warntype on the function there seems to be nothing untoward. All the variables have specified types, and there are no instances of UNION or other obvious warning signs. Apologies, the program is rather long but I'm...
Mark Birtwistle
1

votes
1

answer
287

Views

Downloading Julia from Anaconda or from julialang.org

I want to download Julia (the last version is 1.0) from Anaconda. However, you can download from https://julialang.org/. My questions are: What are the differences between both ways of installing Julia? Can I install, for example, DifferentialEquations.jlor Symata.jl without problems if I choose Ana...
David
1

votes
1

answer
612

Views

export an array to CSV file in Julia

Given an (2d) array A how to export it into csv file with Julia ? Back in older versions I would write writecsv( "FileName.csv", A); which would dump the array A into the given file. This, however, does not work in version >= 1.0. After some googling, I also tried to use CSV module doing f = open(...
Hayk
1

votes
1

answer
47

Views

Need to translate in function iteration from Python to Julia

I've got this sentence in Python: max(xrange(j, n), key=lambda i: abs(m[i][j])) I know how to implement lambda sentence but don't have any idea how to do the xrange(j, n) iteration. Best regards, Szymon
Szymon Żak
1

votes
1

answer
44

Views

Finding univariate-roots in Julia of a function with many arguments

Using the package Roots and its function find_zero, I am trying to solve a univariate rootfinding problem of a function that takes more than one argument. While I am a Julia-beginner, I have checked the documentation and searched on internet but cannot really figure it out. Say, e.g. the function to...
user2084063
1

votes
1

answer
58

Views

Controlling resource usage in Julia lang

I want to build a software that will run every once in a while, automatically, to sort significant number of files sitting in my disk in Julia. I tried to do it with the following code, but eats up my resources. while true // if it's 6 O'clock in the morning, runs function for batch processing end H...
HelloWorld
1

votes
1

answer
60

Views

Can I pass keyword args to do-blocks in julia?

Below is an example: def(f::Function) = f f1 = def() do x x end f2 = def() do x, y x, y end f3 = def() do x, y; z # this syntax is accepted x, y, z end f1(1) f2(1, 2) f3(1, 2, z=3) # ERROR: LoadError: function #13 does not accept keyword arguments The example below is not my actual use case, but it...
Sam De Meyer
1

votes
2

answer
98

Views

Plotting a circle equations in Julia

I have a problem to plot a circle equation in Julia. I'm trying to plot these two equations: 2y^2 + x^2 = 2 (x-1)^2 + (y-1/2)^2 = 1/4 At this time, the only solution i found is using ImplicitEquations.jl but with this, the resulting plot is not satisfying (it looks like filled wit separate pixels):...
Szymon Żak
1

votes
1

answer
32

Views

Guidelines for choosing Array of Struct or Multiple Arrays

This question has been asked for other languages. I would like to ask this in relation to Julia. What are the general guidelines for choosing between an array of struct e.g. struct vertex x::Real y::Real gradient_x::Real gradient_y::Real end myarray::Array{Vertex} and multiple arrays. xpositions::A...
jc211
1

votes
1

answer
34

Views

Evaluate an expression in an environment created from a struct (Julia equivalent of R 'with')

Is there a way to evaluate an expression in an environment created from the fields of a struct? In R, this can be done using the function with: parameters
clbieganek
1

votes
1

answer
435

Views

Read a single number from a text file and advance stream position in Julia

I understand that Julia has a complete set of low level tools for interfacing with binary files on one hand and some powerfull utilities such as readdlm to load text files containing rectangular data into Array structures on the other hand. What I cannot discover in the standard library docs, howeve...
krcools
1

votes
1

answer
770

Views

setindex! error in Julia

I have been writing scripts in Julia recently, and have run across a problem using the setindex! function that I cannot find an answer to in any documentation (I have also searched stackoverflow, but could not find an answer - my apologies if my search was not good enough and I am repeating a questi...
benk
1

votes
1

answer
168

Views

Dataframes NAtype to binary Julia

I'm trying to write binary text files from a data frame in Julia using something along the lines of: for x in RICT["$i"]["Sick"] write(f9, convert(Int16, x )) and everything works nicely except for when it comes to NA values. Missing values are treated as NA it seems, and I know that there are diffe...
Chase CB
1

votes
2

answer
701

Views

Julia: setting up git

Julia have Git program/distributed version control system (git.exe, shell - sh.exe etc.) in her package. I have already installed Git (I think it's more than 1 time) so Julia's Git is redundant, I guess. I have tried to just unpack Julia without git directory but Pkg.add function ( for example Pkg...
Darek Nędza
1

votes
1

answer
350

Views

Parsing text in Julia- Invalid ascii sequence

I'm trying to format a data file so that my other program will properly handle it. I am trying to handle the following data and I am getting a very weird error that I can't seem to put my finger on. https://snap.stanford.edu/data/wiki-RfA.html I am trying to format the data as [SRC TGT VOT], so I'd...
user3587051
1

votes
1

answer
100

Views

Designer fields for Julia type

I want a type which takes an argument and uses that argument to construct a list internal to the type, something like this: type Foo index::Int end type Goo size::Int myList = [Foo(i) for i in 1:size] Goo(size) = new(size) end I've tried it a number of different ways, the way shown here hopefully co...
Thoth
1

votes
1

answer
176

Views

Julia, type interdependencies

How would I resolve something like this: type Foo x::Goo end type Goo y::Foo end I feel like this is a compile vs run-time issue, is there a way to pre-declare types so that the interpreter/compiler/whatever doesn't throw a LoadError?
Thoth
1

votes
1

answer
151

Views

Sorting a counter (and extracting the most common values)

DataStructures.jl provides a great set of tools, one of which is a counter. The corresponding Python object, Counter provides a most_common method. How would this be implemented in Julia?
Tim McNamara
1

votes
1

answer
205

Views

Unable to insert! into lists of various types in Julia (but push! works)

UPDATE: Oops, as pointed out below (very politely) by @rickhg12hs, I simply read the manual wrong. insert! totally works. In Julia, push! works for lists of many different types, but insert! does not. For example, consider arrays of type ASCIIString: x = ["a", "b"] push!(x, "c") results in x = ["a"...
Colin T Bowers
1

votes
2

answer
281

Views

Julia Code optimization

I have the following code from a previous question and I need help optimizing the code for speed. This is the code: function OfdmSym() N = 64 n = 1000 symbol = ones(Complex{Float64}, n, 64) data = ones(Complex{Float64}, 1, 48) unused = zeros(Complex{Float64}, 1, 12) pilot = ones(Complex{Float64},...
AboAmmar
1

votes
1

answer
313

Views

Julia Method Error converting Complex{Float64}

I'm novice to Julia and I have the following code with this error: MethodError(convert,(Complex{Float64},[-1.0 - 1.0im])). I would like to know the source of the error and how to optimize this piece of code for speed. This is my code: function OfdmSym() N = 64 n = 1000 symbol = convert(Array{Complex...
AboAmmar
1

votes
1

answer
273

Views

unit testing in julia notebook using Base.test not defined

I am running the julia notebook by running the following from inside the Julia command line. using IJulia notebook() I want to be a good programmer so I first start writing some unit tests before I start writing some actual code. These show different results compared to what the docs tell me to expe...
cantdutchthis
1

votes
1

answer
283

Views

reverse order columns/diag in matrix julia

This is my first 30 minutes with Julia. The goal is to find out what the contents are of the two diagonals of a matrix (upperleft->lowerright and upperright->lowerleft). Julia is new to me so my approach is to reverse the original matrix' columns such that I can use the diag function on both. The f...
cantdutchthis

View additional questions