Documentation ¶
Index ¶
- Variables
- func Errorf(format string, args ...interface{})
- func IndexAssign(context Context, top, left Expr, index []Expr, right Expr, rhs Value)
- func IsScalarType(v Value) bool
- func MaxParallelismForTesting()
- func OrderedCompare(c Context, u, v Value) int
- func ParseString(s string) string
- type BigFloat
- type BigInt
- type BigRat
- type BinaryOp
- type Char
- type Complex
- func (c Complex) Components() (Value, Value)
- func (c Complex) Copy() Value
- func (c Complex) Eval(Context) Value
- func (c Complex) Inner() Value
- func (c Complex) ProgString() string
- func (c Complex) Rank() int
- func (c Complex) Signum(ctx Context) Complex
- func (c Complex) Sprint(conf *config.Config) string
- func (c Complex) String() string
- type Context
- type Decomposable
- type Error
- type Expr
- type Int
- type Matrix
- func (m *Matrix) Copy() Value
- func (m *Matrix) Data() Vector
- func (m *Matrix) ElemSize() int
- func (m *Matrix) Eval(Context) Value
- func (m *Matrix) Inner() Value
- func (m *Matrix) ProgString() string
- func (m *Matrix) Rank() int
- func (m *Matrix) Shape() []int
- func (m *Matrix) Size() int
- func (m *Matrix) Sprint(conf *config.Config) string
- func (m *Matrix) String() string
- type UnaryOp
- type Value
- func EvalCharEqual(u Value, isEqualOp bool, v Value) (Value, bool)
- func EvalFunctionBody(context Context, fnName string, body []Expr) Value
- func Index(context Context, top, left Expr, index []Expr) Value
- func Parse(conf *config.Config, s string) (Value, error)
- func Product(c Context, u Value, op string, v Value) Value
- func QuoRem(op string, c Context, a, b Value) (div, rem Value)
- func Reduce(c Context, op string, v Value) Value
- func ReduceFirst(c Context, op string, v Value) Value
- func Scan(c Context, op string, v Value) Value
- func ScanFirst(c Context, op string, v Value) Value
- type Vector
- func (v Vector) AllChars() bool
- func (v Vector) AllInts() bool
- func (v Vector) Copy() Value
- func (v Vector) Eval(Context) Value
- func (v Vector) Inner() Value
- func (v Vector) ProgString() string
- func (v Vector) Rank() int
- func (v Vector) Sprint(conf *config.Config) string
- func (v Vector) String() string
Constants ¶
This section is empty.
Variables ¶
var BinaryOps = make(map[string]BinaryOp)
var IvyEval func(context Context, s string) Value
Implemented in package run, handled as a func to avoid a dependency loop.
var (
MaxBigInt63 = big.NewInt(int64(^uint64(0) >> 1)) // Used in ../parse/special.go
)
var UnaryOps = make(map[string]UnaryOp)
Functions ¶
func Errorf ¶
func Errorf(format string, args ...interface{})
Errorf panics with the formatted string, with type Error.
func IndexAssign ¶ added in v0.1.12
IndexAssign handles general assignment to indexed expressions on the LHS. Left and index will be evaluated (right to left), while top is only for its ProgString method. The caller must check that left is a variable expression, so that the assignment is not being written into a temporary.
func IsScalarType ¶ added in v0.3.0
IsScalarType reports whether u is an actual scalar, an int or float etc.
func MaxParallelismForTesting ¶ added in v0.1.12
func MaxParallelismForTesting()
func OrderedCompare ¶ added in v0.3.0
OrderedCompare returns -1, 0, or 1 according to whether u is less than, equal to, or greater than v, according to total ordering rules. Total ordering is not the usual mathematical definition, as we honor things like 1.0 == 1, comparison of int and char is forbidden, and complex numbers do not implement <. Plus other than for scalars we don't need to follow any particular rules at all, just what works for sorting sets.
Thus we amend the usual orderings: - Char is below all other types - All other scalars are compared directly, except... - ...Complex is above all other scalars, unless on the real line: 1j0 == 1. - Vector is above all other types except... - ...Matrix, which is above all other types.
When comparing identically-typed values:
- Complex is ordered first by real component, then by imaginary.
- Vector and Matrix are ordered first by number of elements, then in lexical order of elements.
These are unusual rules, but they are provide a unique ordering of elements sufficient for set membership. // Exported for testing, which is done by the parent directory to avoid a dependency cycle.
func ParseString ¶
ParseString parses a string. Single quotes and double quotes are both allowed (but must be consistent.) The result must contain only valid Unicode code points.
Types ¶
type BigFloat ¶
func (BigFloat) Format ¶
func (f BigFloat) Format()
The fmt package looks for Formatter before Stringer, but we want to use Stringer only. big.Float implements Formatter, and we embed it in our BigFloat type. To make sure that our String gets called rather than the inner Format, we put a non-matching stub Format method into this interface. This is ugly but very simple and cheap.
func (BigFloat) ProgString ¶
type BigInt ¶
func (BigInt) Format ¶
func (i BigInt) Format()
The fmt package looks for Formatter before Stringer, but we want to use Stringer only. big.Int and big.Rat implement Formatter, and we embed them in our BigInt and BigRat types. To make sure that our String gets called rather than the inner Format, we put a non-matching stub Format method into this interface. This is ugly but very simple and cheap.
func (BigInt) ProgString ¶
type BigRat ¶
func (BigRat) ProgString ¶
type Complex ¶ added in v0.2.0
type Complex struct {
// contains filtered or unexported fields
}
func NewComplex ¶ added in v0.3.0
func (Complex) Components ¶ added in v0.2.0
func (Complex) ProgString ¶ added in v0.2.0
type Context ¶
type Context interface { // Lookup returns the configuration state for evaluation. Config() *config.Config // Local returns the value of the i'th local variable. Local(i int) Value // AssignLocal assigns to the i'th local variable. AssignLocal(i int, value Value) // Global returns the value of the named global variable. Global(name string) Value // AssignGlobal assigns to the named global variable. AssignGlobal(name string, value Value) // Eval evaluates a list of expressions. Eval(exprs []Expr) []Value // EvalUnaryFn evaluates a unary operator. EvalUnary(op string, right Value) Value // EvalBinary evaluates a binary operator. EvalBinary(left Value, op string, right Value) Value // UserDefined reports whether the specified op is user-defined. UserDefined(op string, isBinary bool) bool }
Context is the execution context for evaluation. The only implementation is ../exec/Context, but the interface is defined separately, here, because of the dependence on Expr and the import cycle that would otherwise result.
type Decomposable ¶ added in v0.1.1
type Decomposable interface { // Operator returns the operator, or "" for a singleton. Operator() string // Operands returns the left and right operands, or nil if absent. // For singletons, both will be nil, but ProgString can // give the underlying name or value. Operands() (left, right Expr) }
Decomposable allows one to pull apart a parsed expression. Only implemented by Expr types that need to be decomposed in function evaluation.
type Expr ¶
type Expr interface { // ProgString returns the unambiguous representation of the // expression to be used in program source. ProgString() string Eval(Context) Value }
Expr is the interface for a parsed expression. Also implemented by Value.
type Matrix ¶
type Matrix struct {
// contains filtered or unexported fields
}
func (*Matrix) ElemSize ¶
ElemSize returns the size of each top-level element of the matrix. Given shape [a, b, c, ...] it is b*c*....
func (*Matrix) ProgString ¶
type Value ¶
type Value interface { // String is for internal debugging only. It uses default configuration // and puts parentheses around every value so it's clear when it is used. // All user output should call Sprint instead. String() string Sprint(*config.Config) string // Eval evaluates (simplifies) the Value. Eval(Context) Value // Copy returns a copy of the Value. Copy() Value // Inner retrieves the value, without evaluation. But for Assignments, // it returns the right-hand side. Inner() Value // Rank returns the rank of the value: 0 for scalar, 1 for vector, etc. Rank() int // ProgString is like String, but suitable for program listing. // For instance, it ignores the user format for numbers and // puts quotes on chars, guaranteeing a correct representation. ProgString() string // contains filtered or unexported methods }
func EvalCharEqual ¶ added in v0.3.0
EvalCharEqual handles == and != in a special case: If comparing a scalar against a Char, avoid the conversion. The logic of type promotion in EvalBinary otherwise interferes with comparison because it tries to force scalar types to be the same, and char doesn't convert to any other type.
func EvalFunctionBody ¶ added in v0.1.1
EvalFunctionBody evaluates the list of expressions inside a function, possibly with conditionals that generate an early return.
func Index ¶ added in v0.1.12
Index returns left[index]. Left and index will be evaluated (right to left), while top is only for its ProgString method.
func Product ¶
Product computes a compound product, such as an inner product "+.*" or outer product "o.*". The op is known to contain a period. The operands are all at least vectors, and for inner product they must both be vectors.
func QuoRem ¶ added in v0.3.0
QuoRem uses Euclidean division to return the quotient and remainder for a/b. The quotient will be an integer, possibly negative; the remainder is always positive and may be fractional. Returned values satisfy the identity that
quo = a div b such that rem = a - b*quo with 0 <= rem < |y|
See comment for math/big.Int.DivMod for details. Exported for testing.
func ReduceFirst ¶ added in v0.3.0
ReduceFirst computes a reduction such as +/% along the first axis. The slash-percent has been removed.