Arrays
Constructors and Types
Core.AbstractArray
— Type.AbstractArray{T,N}
Supertype for N
-dimensional arrays (or array-like types) with elements of type T
. Array
and other types are subtypes of this. See the manual section on the AbstractArray
interface.
Base.AbstractVector
— Type.AbstractVector{T}
Supertype for one-dimensional arrays (or array-like types) with elements of type T
. Alias for AbstractArray{T,1}
.
Base.AbstractMatrix
— Type.AbstractMatrix{T}
Supertype for two-dimensional arrays (or array-like types) with elements of type T
. Alias for AbstractArray{T,2}
.
Base.AbstractVecOrMat
— Constant.AbstractVecOrMat{T}
Union type of AbstractVector{T}
and AbstractMatrix{T}
.
Core.Array
— Type.Array{T,N} <: AbstractArray{T,N}
N
-dimensional dense array with elements of type T
.
Core.Array
— Method.Array{T}(undef, dims)
+
Arrays
Constructors and Types
Core.AbstractArray
— Type.AbstractArray{T,N}
Supertype for N
-dimensional arrays (or array-like types) with elements of type T
. Array
and other types are subtypes of this. See the manual section on the AbstractArray
interface.
sourceBase.AbstractVector
— Type.AbstractVector{T}
Supertype for one-dimensional arrays (or array-like types) with elements of type T
. Alias for AbstractArray{T,1}
.
sourceBase.AbstractMatrix
— Type.AbstractMatrix{T}
Supertype for two-dimensional arrays (or array-like types) with elements of type T
. Alias for AbstractArray{T,2}
.
sourceBase.AbstractVecOrMat
— Constant.AbstractVecOrMat{T}
Union type of AbstractVector{T}
and AbstractMatrix{T}
.
sourceCore.Array
— Type.Array{T,N} <: AbstractArray{T,N}
N
-dimensional dense array with elements of type T
.
sourceCore.Array
— Method.Array{T}(undef, dims)
Array{T,N}(undef, dims)
Construct an uninitialized N
-dimensional Array
containing elements of type T
. N
can either be supplied explicitly, as in Array{T,N}(undef, dims)
, or be determined by the length or number of dims
. dims
may be a tuple or a series of integer arguments corresponding to the lengths in each dimension. If the rank N
is supplied explicitly, then it must match the length or number of dims
. See undef
.
Examples
julia> A = Array{Float64,2}(undef, 2, 3) # N given explicitly
2×3 Array{Float64,2}:
6.90198e-310 6.90198e-310 6.90198e-310
diff --git a/en/stable/base/base/index.html b/en/stable/base/base/index.html
index 11cc38d5b0412..4793544b3ef8c 100644
--- a/en/stable/base/base/index.html
+++ b/en/stable/base/base/index.html
@@ -6,7 +6,7 @@
ga('create', 'UA-28835595-6', 'auto');
ga('send', 'pageview');
-
Essentials
Introduction
Julia Base contains a range of functions and macros appropriate for performing scientific and numerical computing, but is also as broad as those of many general purpose programming languages. Additional functionality is available from a growing collection of available packages. Functions are grouped by topic below.
Some general notes:
- To use module functions, use
import Module
to import the module, and Module.fn(x)
to use the functions. - Alternatively,
using Module
will import all exported Module
functions into the current namespace. - By convention, function names ending with an exclamation point (
!
) modify their arguments. Some functions have both modifying (e.g., sort!
) and non-modifying (sort
) versions.
Getting Around
Base.exit
— Function.exit(code=0)
Stop the program with an exit code. The default exit code is zero, indicating that the program completed successfully. In an interactive session, exit()
can be called with the keyboard shortcut ^D
.
sourceBase.atexit
— Function.atexit(f)
Register a zero-argument function f()
to be called at process exit. atexit()
hooks are called in last in first out (LIFO) order and run before object finalizers.
sourceBase.isinteractive
— Function.isinteractive() -> Bool
Determine whether Julia is running an interactive session.
sourceBase.summarysize
— Function.Base.summarysize(obj; exclude=Union{...}, chargeall=Union{...}) -> Int
Compute the amount of memory used by all unique objects reachable from the argument.
Keyword Arguments
exclude
: specifies the types of objects to exclude from the traversal.chargeall
: specifies the types of objects to always charge the size of all of their fields, even if those fields would normally be excluded.
sourceBase.require
— Function.require(module::Symbol)
This function is part of the implementation of using
/ import
, if a module is not already defined in Main
. It can also be called directly to force reloading a module, regardless of whether it has been loaded before (for example, when interactively developing libraries).
Loads a source file, in the context of the Main
module, on every active node, searching standard locations for files. require
is considered a top-level operation, so it sets the current include
path but does not use it to search for files (see help for include
). This function is typically used to load library code, and is implicitly called by using
to load packages.
When searching for files, require
first looks for package code in the global array LOAD_PATH
. require
is case-sensitive on all platforms, including those with case-insensitive filesystems like macOS and Windows.
For more details regarding code loading, see the manual.
sourceBase.compilecache
— Function.Base.compilecache(module::PkgId)
Creates a precompiled cache file for a module and all of its dependencies. This can be used to reduce package load times. Cache files are stored in DEPOT_PATH[1]/compiled
. See Module initialization and precompilation for important notes.
sourceBase.__precompile__
— Function.__precompile__(isprecompilable::Bool)
Specify whether the file calling this function is precompilable, defaulting to true
. If a module or file is not safely precompilable, it should call __precompile__(false)
in order to throw an error if Julia attempts to precompile it.
sourceBase.include
— Function.Base.include([m::Module,] path::AbstractString)
Evaluate the contents of the input source file in the global scope of module m
. Every module (except those defined with baremodule
) has its own 1-argument definition of include
, which evaluates the file in that module. Returns the result of the last evaluated expression of the input file. During including, a task-local include path is set to the directory containing the file. Nested calls to include
will search relative to that path. This function is typically used to load source interactively, or to combine files in packages that are broken into multiple source files.
sourceBase.MainInclude.include
— Function.include(path::AbstractString)
Evaluate the contents of the input source file in the global scope of the containing module. Every module (except those defined with baremodule
) has its own 1-argument definition of include
, which evaluates the file in that module. Returns the result of the last evaluated expression of the input file. During including, a task-local include path is set to the directory containing the file. Nested calls to include
will search relative to that path. This function is typically used to load source interactively, or to combine files in packages that are broken into multiple source files.
Use Base.include
to evaluate a file into another module.
sourceBase.include_string
— Function.include_string(m::Module, code::AbstractString, filename::AbstractString="string")
Like include
, except reads code from the given string rather than from a file.
sourceBase.include_dependency
— Function.include_dependency(path::AbstractString)
In a module, declare that the file specified by path
(relative or absolute) is a dependency for precompilation; that is, the module will need to be recompiled if this file changes.
This is only needed if your module depends on a file that is not used via include
. It has no effect outside of compilation.
sourceBase.which
— Method.which(f, types)
Returns the method of f
(a Method
object) that would be called for arguments of the given types
.
If types
is an abstract type, then the method that would be called by invoke
is returned.
sourceBase.methods
— Function.methods(f, [types])
Returns the method table for f
.
If types
is specified, returns an array of methods whose types match.
sourceBase.@show
— Macro.@show
Show an expression and result, returning the result.
sourceans
— Keyword.ans
A variable referring to the last computed value, automatically set at the interactive prompt.
sourceKeywords
module
— Keyword.module
module
declares a Module
, which is a separate global variable workspace. Within a module, you can control which names from other modules are visible (via importing), and specify which of your names are intended to be public (via exporting). Modules allow you to create top-level definitions without worrying about name conflicts when your code is used together with somebody else’s. See the manual section about modules for more details.
Examples
module Foo
+
Essentials
Introduction
Julia Base contains a range of functions and macros appropriate for performing scientific and numerical computing, but is also as broad as those of many general purpose programming languages. Additional functionality is available from a growing collection of available packages. Functions are grouped by topic below.
Some general notes:
- To use module functions, use
import Module
to import the module, and Module.fn(x)
to use the functions. - Alternatively,
using Module
will import all exported Module
functions into the current namespace. - By convention, function names ending with an exclamation point (
!
) modify their arguments. Some functions have both modifying (e.g., sort!
) and non-modifying (sort
) versions.
Getting Around
Base.exit
— Function.exit(code=0)
Stop the program with an exit code. The default exit code is zero, indicating that the program completed successfully. In an interactive session, exit()
can be called with the keyboard shortcut ^D
.
sourceBase.atexit
— Function.atexit(f)
Register a zero-argument function f()
to be called at process exit. atexit()
hooks are called in last in first out (LIFO) order and run before object finalizers.
sourceBase.isinteractive
— Function.isinteractive() -> Bool
Determine whether Julia is running an interactive session.
sourceBase.summarysize
— Function.Base.summarysize(obj; exclude=Union{...}, chargeall=Union{...}) -> Int
Compute the amount of memory used by all unique objects reachable from the argument.
Keyword Arguments
exclude
: specifies the types of objects to exclude from the traversal.chargeall
: specifies the types of objects to always charge the size of all of their fields, even if those fields would normally be excluded.
sourceBase.require
— Function.require(module::Symbol)
This function is part of the implementation of using
/ import
, if a module is not already defined in Main
. It can also be called directly to force reloading a module, regardless of whether it has been loaded before (for example, when interactively developing libraries).
Loads a source file, in the context of the Main
module, on every active node, searching standard locations for files. require
is considered a top-level operation, so it sets the current include
path but does not use it to search for files (see help for include
). This function is typically used to load library code, and is implicitly called by using
to load packages.
When searching for files, require
first looks for package code in the global array LOAD_PATH
. require
is case-sensitive on all platforms, including those with case-insensitive filesystems like macOS and Windows.
For more details regarding code loading, see the manual.
sourceBase.compilecache
— Function.Base.compilecache(module::PkgId)
Creates a precompiled cache file for a module and all of its dependencies. This can be used to reduce package load times. Cache files are stored in DEPOT_PATH[1]/compiled
. See Module initialization and precompilation for important notes.
sourceBase.__precompile__
— Function.__precompile__(isprecompilable::Bool)
Specify whether the file calling this function is precompilable, defaulting to true
. If a module or file is not safely precompilable, it should call __precompile__(false)
in order to throw an error if Julia attempts to precompile it.
sourceBase.include
— Function.Base.include([m::Module,] path::AbstractString)
Evaluate the contents of the input source file in the global scope of module m
. Every module (except those defined with baremodule
) has its own 1-argument definition of include
, which evaluates the file in that module. Returns the result of the last evaluated expression of the input file. During including, a task-local include path is set to the directory containing the file. Nested calls to include
will search relative to that path. This function is typically used to load source interactively, or to combine files in packages that are broken into multiple source files.
sourceBase.MainInclude.include
— Function.include(path::AbstractString)
Evaluate the contents of the input source file in the global scope of the containing module. Every module (except those defined with baremodule
) has its own 1-argument definition of include
, which evaluates the file in that module. Returns the result of the last evaluated expression of the input file. During including, a task-local include path is set to the directory containing the file. Nested calls to include
will search relative to that path. This function is typically used to load source interactively, or to combine files in packages that are broken into multiple source files.
Use Base.include
to evaluate a file into another module.
sourceBase.include_string
— Function.include_string(m::Module, code::AbstractString, filename::AbstractString="string")
Like include
, except reads code from the given string rather than from a file.
sourceBase.include_dependency
— Function.include_dependency(path::AbstractString)
In a module, declare that the file specified by path
(relative or absolute) is a dependency for precompilation; that is, the module will need to be recompiled if this file changes.
This is only needed if your module depends on a file that is not used via include
. It has no effect outside of compilation.
sourceBase.which
— Method.which(f, types)
Returns the method of f
(a Method
object) that would be called for arguments of the given types
.
If types
is an abstract type, then the method that would be called by invoke
is returned.
sourceBase.methods
— Function.methods(f, [types])
Returns the method table for f
.
If types
is specified, returns an array of methods whose types match.
sourceBase.@show
— Macro.@show
Show an expression and result, returning the result.
sourceans
— Keyword.ans
A variable referring to the last computed value, automatically set at the interactive prompt.
sourceKeywords
module
— Keyword.module
module
declares a Module
, which is a separate global variable workspace. Within a module, you can control which names from other modules are visible (via importing), and specify which of your names are intended to be public (via exporting). Modules allow you to create top-level definitions without worrying about name conflicts when your code is used together with somebody else’s. See the manual section about modules for more details.
Examples
module Foo
import Base.show
export MyType, foo
diff --git a/en/stable/base/c/index.html b/en/stable/base/c/index.html
index 4045d60e5c8f3..3e45f5092021e 100644
--- a/en/stable/base/c/index.html
+++ b/en/stable/base/c/index.html
@@ -6,7 +6,7 @@
ga('create', 'UA-28835595-6', 'auto');
ga('send', 'pageview');
-
C Interface
ccall
— Keyword.ccall((function_name, library), returntype, (argtype1, ...), argvalue1, ...)
+
C Interface
ccall
— Keyword.ccall((function_name, library), returntype, (argtype1, ...), argvalue1, ...)
ccall(function_pointer, returntype, (argtype1, ...), argvalue1, ...)
Call a function in a C-exported shared library, specified by the tuple (function_name, library)
, where each component is either a string or symbol. Alternatively, ccall
may also be used to call a function pointer function_pointer
, such as one returned by dlsym
.
Note that the argument type tuple must be a literal tuple, and not a tuple-valued variable or expression.
Each argvalue
to the ccall
will be converted to the corresponding argtype
, by automatic insertion of calls to unsafe_convert(argtype, cconvert(argtype, argvalue))
. (See also the documentation for unsafe_convert
and cconvert
for further details.) In most cases, this simply results in a call to convert(argtype, argvalue)
.
sourceCore.Intrinsics.cglobal
— Function.cglobal((symbol, library) [, type=Cvoid])
Obtain a pointer to a global variable in a C-exported shared library, specified exactly as in ccall
. Returns a Ptr{Type}
, defaulting to Ptr{Cvoid}
if no Type
argument is supplied. The values can be read or written by unsafe_load
or unsafe_store!
, respectively.
sourceBase.@cfunction
— Macro.@cfunction(callable, ReturnType, (ArgumentTypes...,)) -> Ptr{Cvoid}
@cfunction($callable, ReturnType, (ArgumentTypes...,)) -> CFunction
Generate a C-callable function pointer from the Julia function closure
for the given type signature. To pass the return value to a ccall
, use the argument type Ptr{Cvoid}
in the signature.
Note that the argument type tuple must be a literal tuple, and not a tuple-valued variable or expression (although it can include a splat expression). And that these arguments will be evaluated in global scope during compile-time (not deferred until runtime). Adding a '$' in front of the function argument changes this to instead create a runtime closure over the local variable callable
.
See manual section on ccall and cfunction usage.
Examples
julia> function foo(x::Int, y::Int)
return x + y
diff --git a/en/stable/base/collections/index.html b/en/stable/base/collections/index.html
index 4782865629675..8db41db828cd5 100644
--- a/en/stable/base/collections/index.html
+++ b/en/stable/base/collections/index.html
@@ -6,7 +6,7 @@
ga('create', 'UA-28835595-6', 'auto');
ga('send', 'pageview');
-
Collections and Data Structures
Iteration
Sequential iteration is implemented by the iterate
function. The general for
loop:
for i in iter # or "for i = iter"
+
Collections and Data Structures
Iteration
Sequential iteration is implemented by the iterate
function. The general for
loop:
for i in iter # or "for i = iter"
# body
end
is translated into:
next = iterate(iter)
while next !== nothing
diff --git a/en/stable/base/constants/index.html b/en/stable/base/constants/index.html
index 4d5a776e1f8b4..e67df560b5305 100644
--- a/en/stable/base/constants/index.html
+++ b/en/stable/base/constants/index.html
@@ -6,4 +6,4 @@
ga('create', 'UA-28835595-6', 'auto');
ga('send', 'pageview');
-
Constants
Core.nothing
— Constant.nothing
The singleton instance of type Nothing
, used by convention when there is no value to return (as in a C void
function) or when a variable or field holds no value.
sourceBase.PROGRAM_FILE
— Constant.PROGRAM_FILE
A string containing the script name passed to Julia from the command line. Note that the script name remains unchanged from within included files. Alternatively see @__FILE__
.
sourceBase.ARGS
— Constant.ARGS
An array of the command line arguments passed to Julia, as strings.
sourceBase.C_NULL
— Constant.C_NULL
The C null pointer constant, sometimes used when calling external code.
sourceBase.VERSION
— Constant.VERSION
A VersionNumber
object describing which version of Julia is in use. For details see Version Number Literals.
sourceBase.LOAD_PATH
— Constant.LOAD_PATH
An array of paths for using
and import
statements to consdier as project environments or package directories when loading code. See Code Loading.
sourceBase.Sys.BINDIR
— Constant.Sys.BINDIR
A string containing the full path to the directory containing the julia
executable.
sourceBase.Sys.CPU_THREADS
— Constant.Sys.CPU_THREADS
The number of logical CPU cores available in the system, i.e. the number of threads that the CPU can run concurrently. Note that this is not necessarily the number of CPU cores, for example, in the presence of hyper-threading.
See Hwloc.jl or CpuId.jl for extended information, including number of physical cores.
sourceBase.Sys.WORD_SIZE
— Constant.Sys.WORD_SIZE
Standard word size on the current machine, in bits.
sourceBase.Sys.KERNEL
— Constant.Sys.KERNEL
A symbol representing the name of the operating system, as returned by uname
of the build configuration.
sourceBase.Sys.ARCH
— Constant.Sys.ARCH
A symbol representing the architecture of the build configuration.
sourceBase.Sys.MACHINE
— Constant.Sys.MACHINE
A string containing the build triple.
sourceSee also:
stdin
stdout
stderr
ENV
ENDIAN_BOM
Libc.MS_ASYNC
Libc.MS_INVALIDATE
Libc.MS_SYNC