Documentation ¶
Index ¶
- Variables
- func Atan(q *big.Float) *big.Float
- func ComplexSqrt(r, i *big.Float) (*big.Float, *big.Float)
- func Cos(q *big.Float) *big.Float
- 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
- func Pow(x *big.Float, e *big.Float) *big.Float
- func Sin(q *big.Float) *big.Float
- type BigFloat
- type BigInt
- type BigRat
- type BinaryOp
- type Char
- type Complex
- type Config
- func (c *Config) Base() (inputBase, outputBase int)
- func (c *Config) BigOrigin() *big.Int
- func (c *Config) CPUTime() (real, user, sys time.Duration)
- func (c *Config) Debug(flag string) bool
- func (c *Config) ErrOutput() io.Writer
- func (c *Config) FloatFormat() (verb byte, prec int, ok bool)
- func (c *Config) FloatPrec() uint
- func (c *Config) Format() string
- func (c *Config) InputBase() int
- func (c *Config) MaxBits() uint
- func (c *Config) MaxDigits() uint
- func (c *Config) MaxStack() uint
- func (c *Config) Mobile() bool
- func (c *Config) Origin() int
- func (c *Config) Output() io.Writer
- func (c *Config) OutputBase() int
- func (c *Config) PrintCPUTime() string
- func (c *Config) Prompt() string
- func (c *Config) Random() *rand.Rand
- func (c *Config) RandomSeed() int64
- func (c *Config) RatFormat() string
- func (c *Config) SetBase(inputBase, outputBase int)
- func (c *Config) SetCPUTime(real, user, sys time.Duration)
- func (c *Config) SetDebug(flag string, state bool) bool
- func (c *Config) SetErrOutput(output io.Writer)
- func (c *Config) SetFloatPrec(prec uint)
- func (c *Config) SetFormat(s string)
- func (c *Config) SetMaxBits(digits uint)
- func (c *Config) SetMaxDigits(digits uint)
- func (c *Config) SetMaxStack(depth uint)
- func (c *Config) SetMobile(mobile bool)
- func (c *Config) SetOrigin(origin int)
- func (c *Config) SetOutput(output io.Writer)
- func (c *Config) SetPrompt(prompt string)
- func (c *Config) SetRandomSeed(seed int64)
- type Context
- type Decomposable
- type Error
- type ExecContext
- func (c *ExecContext) AssignGlobal(name string, val Value)
- func (c *ExecContext) AssignLocal(i int, value Value)
- func (c *ExecContext) Binary(op string) BinaryOp
- func (c *ExecContext) Config() *Config
- func (c *ExecContext) Declare(name string)
- func (c *ExecContext) Define(fn *Function)
- func (c *ExecContext) Eval(exprs []Expr) []Value
- func (c *ExecContext) EvalBinary(left Value, op string, right Value) Value
- func (c *ExecContext) EvalUnary(op string, right Value) Value
- func (c *ExecContext) ForgetAll()
- func (c *ExecContext) Global(name string) Value
- func (c *ExecContext) Local(i int) Value
- func (c *ExecContext) SetConstants()
- func (c *ExecContext) Unary(op string) UnaryOp
- func (c *ExecContext) UserDefined(op string, isBinary bool) bool
- type Expr
- type Function
- 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) string
- func (m *Matrix) String() string
- type OpDef
- type Symtab
- 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, 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
Constants ¶
This section is empty.
Variables ¶
var BinaryOps = make(map[string]BinaryOp)
var DebugFlags = [...]string{
"cpu",
"panic",
"parse",
"tokens",
"types",
}
Order here determines order in the Config.debug array.
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 ¶
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 ¶
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 Complex ¶
type Complex struct {
// contains filtered or unexported fields
}
func (Complex) Components ¶
func (Complex) ProgString ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
A Config holds information about the configuration of the system. The zero value of a Config represents the default values for all settings.
func (*Config) FloatFormat ¶
FloatFormat returns the parsed information about the format, if it's a floating-point format.
func (*Config) FloatPrec ¶
FloatPrec returns the floating-point precision in bits. The exponent size is fixed by math/big.
func (*Config) Format ¶
Format returns the formatting string. If empty, the default formatting is used, as defined by the bases.
func (*Config) MaxDigits ¶
MaxDigits returns the maximum integer size to print as integer, in digits.
func (*Config) PrintCPUTime ¶
PrintCPUTime returns a nicely formatted version of the CPU time.
func (*Config) RandomSeed ¶
RandomSeed returns the seed used to initialize the random number generator.
func (*Config) SetCPUTime ¶
SetCPUTime sets the duration of the last interactive operation.
func (*Config) SetDebug ¶
SetDebug sets the value of the specified boolean debugging flag. It returns false if the flag is unknown.
func (*Config) SetErrOutput ¶
SetErrOutput sets the writer to which error output is printed; default is os.Stderr.
func (*Config) SetFloatPrec ¶
SetFloatPrec sets the floating-point precision in bits.
func (*Config) SetFormat ¶
SetFormat sets the formatting string. Rational formatting is just this format applied twice with a / in between.
func (*Config) SetMaxBits ¶
MaxBits sets the maximum integer size to store, in bits.
func (*Config) SetMaxDigits ¶
SetMaxDigits sets the maximum integer size to print as integer, in digits.
func (*Config) SetMaxStack ¶
SetMaxStack sets the maximum call stack depth.
func (*Config) SetOutput ¶
SetOutput sets the writer to which program output is printed; default is os.Stdout.
func (*Config) SetRandomSeed ¶
SetRandomSeed sets the seed for the random number generator.
type Context ¶
type Context interface { // Lookup returns the configuration state for evaluation. 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.
func NewContext ¶
NewContext returns a new execution context: the stack and variables, plus the execution configuration.
type Decomposable ¶
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 ExecContext ¶
type ExecContext struct { Globals Symtab // UnaryFn maps the names of unary functions (ops) to their implemenations. UnaryFn map[string]*Function // BinaryFn maps the names of binary functions (ops) to their implemenations. BinaryFn map[string]*Function // Defs is a list of defined ops, in time order. It is used when saving the // Context to a file. Defs []OpDef // contains filtered or unexported fields }
Context holds execution context, specifically the binding of names to values and operators. It is the only implementation of ../Context, but since it references the value package, there would be a cycle if that package depended on this type definition.
func (*ExecContext) AssignGlobal ¶
func (c *ExecContext) AssignGlobal(name string, val Value)
Assign assigns the global variable the value. The variable must be defined either in the current function or globally. Inside a function, new variables become locals.
func (*ExecContext) AssignLocal ¶
func (c *ExecContext) AssignLocal(i int, value Value)
AssignLocal assigns the local variable with the given index the value.
func (*ExecContext) Binary ¶
func (c *ExecContext) Binary(op string) BinaryOp
func (*ExecContext) Config ¶
func (c *ExecContext) Config() *Config
func (*ExecContext) Declare ¶
func (c *ExecContext) Declare(name string)
Declare makes the name a variable while parsing the next function.
func (*ExecContext) Define ¶
func (c *ExecContext) Define(fn *Function)
Define defines the function and installs it. It also performs some error checking and adds the function to the sequencing information used by the save method.
func (*ExecContext) Eval ¶
func (c *ExecContext) Eval(exprs []Expr) []Value
Eval evaluates a list of expressions.
func (*ExecContext) EvalBinary ¶
func (c *ExecContext) EvalBinary(left Value, op string, right Value) Value
EvalBinary evaluates a binary operator, including products.
func (*ExecContext) EvalUnary ¶
func (c *ExecContext) EvalUnary(op string, right Value) Value
EvalUnary evaluates a unary operator, including reductions and scans.
func (*ExecContext) ForgetAll ¶
func (c *ExecContext) ForgetAll()
ForgetAll forgets the declared variables.
func (*ExecContext) Global ¶
func (c *ExecContext) Global(name string) Value
Global returns the value of a global symbol, or nil if the symbol is not defined globally.
func (*ExecContext) Local ¶
func (c *ExecContext) Local(i int) Value
Local returns the value of the local variable with index i.
func (*ExecContext) SetConstants ¶
func (c *ExecContext) SetConstants()
SetConstants re-assigns the fundamental constant values using the current setting of floating-point precision.
func (*ExecContext) Unary ¶
func (c *ExecContext) Unary(op string) UnaryOp
func (*ExecContext) UserDefined ¶
func (c *ExecContext) UserDefined(op string, isBinary bool) bool
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 Function ¶
type Function struct { IsBinary bool Name string Left string Right string Body []Expr Locals []string Globals []string }
Function represents a unary or binary user-defined operator.
func (*Function) EvalBinary ¶
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 OpDef ¶
OpDef is just a record of an op's name and arg count. It is held in execContext.defs to control writing the ops out in the right order during save. See comment above.
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) 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 ¶
EvalFunctionBody evaluates the list of expressions inside a function, possibly with conditionals that generate an early return.
func Index ¶
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.