API
Modules
Types and constants
Functions and macros
PropertyFunctions.@pf
PropertyFunctions.filterby
PropertyFunctions.props2varsyms
PropertyFunctions.sortby
Documentation
PropertyFunctions.PropertyFunctions
— ModulePropertyFunctions
Provides functionality for easy access to and efficient broadcasting over properties.
PropertyFunctions.PropSelFunction
— TypePropSelFunction{src_names,trg_names} <: PropertyFunction
A special kind of PropertyFunction
that selects (and possibly renames) properties, but does no other computations.
A PropSelFunction can be constructed via the @pf
macro
propsel = @pf (;$c, d = $a)
or directly via
propsel = PropSelFunction(:c, :a => :d)
or
propsel = PropSelFunction{(:c, :a), (:c, :d)}()
or just
PropSelFunction{(:c, :a)}()
if no property name mapping is required.
See also @pf
.
PropertyFunctions.PropertyFunction
— Typestruct PropertyFunction <: Function
Use only for dispatch in special cases. User code should not create instances of PropertyFunction
directly - use the @fp
macro instead.
The type parameters of PropertyFunction
are subject to change and not part of the public API of the PropertyFunctions package.
PropertyFunctions.@pf
— Macro@pf expression
Generates a function that accesses the properties of it's argument referenced via $property
in expression
.
@pf($a + $c^2)
is equivalent to x -> x.a + x.c^2
.
Examples:
xs = StructArrays.StructArray((
a = [0.9, 0.1, 0.9, 0.2, 0.7, 0.0, 0.7, 0.5, 0.2, 0.6],
b = [0.1, 0.5, 0.9, 0.9, 0.9, 0.6, 0.1, 0.9, 0.8, 0.2],
c = [0.4, 0.1, 0.4, 0.1, 0.9, 0.2, 0.4, 0.8, 0.0, 0.1]
))
@pf($a + $c^2)(xs[1])
xs .|> @pf $a + $c^2
Functions generated by @pf
come with broadcasting specializations that try to ensure that only the columns referenced via $colname
in expr
will be read, reducing memory traffic. So data.b
will not be accessed in the example above. If the broadcasted function generates structs (including NamedTuple
s), broadcasting specialization will try to return a StructArrays.StructArray
.
Property functions of the kind
propsel = @pf (;$c, d = $a)
Can be used to select (and rename) properties, and they have special broadcasting optimizations for table-like arguments. This can make broadcasts of such property selectors zero-copy O(1) operations:
new_xs = propsel.(xs)
new_xs.c === xs.c
new_xs.d === xs.a
@pf
is also very handy in sortby
and filterby
:
xs |> sortby(@pf $a + $c^2)
xs |> filterby(@pf $a + $c^2 < 0.5)
PropertyFunctions.filterby
— Functionfilterby([getindex|view,] f)
Generates a function that filters a table-like array by f
, returning either a copy (default) or a view (ignored if the object does not support views).
Example:
xs = [0.9, 0.1, 0.9, 0.2, 0.7, 0.0, 0.7, 0.5, 0.2, 0.6]
xs |> filterby(x -> x < 0.5)
PropertyFunctions.props2varsyms
— Methodprops2varsyms(expr)
Replace $
-escaped properties in expr
by generated variable names and return the original property names, new argument names and the modified expression.
Usage:
props, vars, new_expr = props2varsyms(expr)
PropertyFunctions.sortby
— Functionsortby(
[getindex|view,]
f;
rev::Bool = false,
)
Generates a function that sorts and array by f
, returning either a copy (default) or a view (ignored if the object does not support views).
Example:
xs = [0.9, 0.1, 0.9, 0.2, 0.7, 0.0, 0.7, 0.5, 0.2, 0.6]
xs |> sortby(x -> (x - 0.5)^2)