Documentation ¶
Index ¶
- Variables
- func Errorf(format string, args ...interface{})
- func IndexAssign(context Context, top, left Expr, index []Expr, right Expr, rhs Value)
- func MaxParallelismForTesting()
- func ParseString(s string) string
- type BigFloat
- type BigInt
- type BigRat
- type BinaryOp
- type Char
- type Context
- type Decomposable
- type Error
- type Expr
- type Int
- type Matrix
- func (m *Matrix) Copy() *Matrix
- func (m *Matrix) Data() Vector
- func (m *Matrix) ElemSize() int64
- 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() int64
- func (m *Matrix) Sprint(conf *config.Config) string
- func (m *Matrix) String() string
- type UnaryOp
- type Value
- 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 Reduce(c Context, op string, v Value) Value
- func Scan(c Context, op string, v Value) Value
- type Vector
- func (v Vector) AllChars() bool
- func (v Vector) AllInts() bool
- func (v Vector) Copy() Vector
- 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))
)
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 MaxParallelismForTesting ¶ added in v0.1.12
func MaxParallelismForTesting()
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 Context ¶
type Context interface { // Lookup returns the configuration state for evaluation. Config() *config.Config // Lookup returns the value of a symbol. Lookup(name string) Value // Assign assigns the variable the value. The variable must // be defined either in the current function or globally. // Inside a function, new variables become locals. Assign(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(Context) 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 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.