is there an API for Julia packages

Viewed 113

Hi I am an old Java/Haskell/Cobol programmer. And Julia has many fantastic features but I am struggling with what I consider the basics. Particularly how to find what is in the many packages (Flux, Plots, DifferentialEquations, etc).

  1. I have tried both VSCode and Jupiter notebook and the Julia REPL but have found no way to extract this essential information while working on a program.
  2. I have also failed to find the information on line without it being spread very thinly over tutorial for each package.

Is there and "cheetsheet" or "summary" or java like API?

1 Answers

For the basics, I would recommend two "cheatsheets" in particular

However, the package ecosystem is too diverse for any cheatsheet to cover all the useful packages out there, so for individual packages I would recommend a few tricks built in to the language:

  • Tab-complete in the REPL. Typing PackageName.<tab><tab> will print everything in the namespace of PackageName, e.g.:
julia> using Statistics

julia> Statistics.

_conj               _vmean               covm                 quantile!
_getnobs            centralize_sumabs2   covzm                range_varm
_mean               centralize_sumabs2!  eval                 realXcY
_mean_promote       centralizedabs2fun   include              sqrt!
_median             clampcor             mean                 std
_quantile           cor                  mean!                stdm
_quantilesort!      corm                 median               unscaled_covzm
_std                corzm                median!              var
_var                cov                  middle               varm
_varm               cov2cor!             quantile             varm!

Note that since this prints everything in the package, this includes functions that may not be intended for general use. By general convention, any function beginning with an underscore _ is not intended for public use.

  • The names function -- will give you a list of all the functions exported by a given package (and thus is a bit more selective than just typing PackageName.<tab><tab>). This is effectively the public API of any given Julia package:
julia> using Statistics

julia> names(Statistics)
14-element Vector{Symbol}:
 :Statistics
 :cor
 :cov
 :mean
 :mean!
 :median
 :median!
 :middle
 :quantile
 :quantile!
 :std
 :stdm
 :var
 :varm
  • Once you find a function that looks promising, the built-in help, accessed by just typing ? at the REPL prompt:
help?> cov
search: cov convert StackOverflowError CUSOLVER has_cusolvermg code_llvm @code_llvm cudaconvert

  cov(x::AbstractVector; corrected::Bool=true)

  Compute the variance of the vector x. If corrected is true (the default) then the sum is scaled with
  n-1, whereas the sum is scaled with n if corrected is false where n = length(x).

  ────────────────────────────────────────────────────────────────────────────────────────────────────

  cov(X::AbstractMatrix; dims::Int=1, corrected::Bool=true)

  Compute the covariance matrix of the matrix X along the dimension dims. If corrected is true (the
  default) then the sum is scaled with n-1, whereas the sum is scaled with n if corrected is false
  where n = size(X, dims).
  ────────────────────────────────────────────────────────────────────────────────────────────────────
...
...
...
  • The methodswith function -- will give you a list of all functions that can operate on objects of a given Type:
julia> using LinearAlgebra, SparseArrays

julia> methodswith(SparseMatrixCSC)

[1] sizehint!(S::SparseMatrixCSC, n::Integer) in SparseArrays
[2] cov(X::SparseMatrixCSC; dims, corrected) in Statistics
[3] \(L::SuiteSparse.CHOLMOD.Factor, B::SparseMatrixCSC) in SuiteSparse.CHOLMOD 
[4] lu(A::SparseMatrixCSC; check) in SuiteSparse.UMFPACK a
[5] lu!(F::SuiteSparse.UMFPACK.UmfpackLU, A::SparseMatrixCSC; check) in SuiteSparse.UMFPACK
[6] qr(A::SparseMatrixCSC; tol) in SuiteSparse.SPQR 
[7] rank(S::SparseMatrixCSC) in SuiteSparse.SPQR
...
...
...
  • On @OscarSmith's suggestion -- you can search for functions, types, and other symbols across multiple packages, as well as searching the full text of all Julia packages, on JuliaHub. For example: sprandn

Finally, for getting a feel for what sort of packages are out there in the package ecosystem beyond the stdlib, I can recommend joining one of the several Julia community fora, such as the discourse, the slack, or the zulip.

Related