Documentation ¶
Overview ¶
Copyright 2019 Google LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2019 Google LLC ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- type Apply
- type Evaluator
- type Expression
- type Function
- type Plus
- type Profiler
- type Tensor
- func NewComplexTensor(f func(i ...int) complex128, signature string, dim []int) Tensor
- func NewIntTensor(f func(i ...int) int, signature string, dim []int) Tensor
- func NewRealTensor(f func(i ...int) float64, signature string, dim []int) Tensor
- func NewStringTensor(f func(i ...int) string, signature string, dim []int) Tensor
- func Product(t1, t2 Tensor, profiler *Profiler) Tensor
- func Trace(t Tensor, a, b int, profiler *Profiler) (Tensor, error)
- func Transpose(t Tensor, a, b int) (Tensor, error)
- func (t Tensor) ContravariantIndices() []int
- func (t Tensor) CovariantIndices() []int
- func (t *Tensor) D(indices string) Expression
- func (t Tensor) Dimension() []int
- func (t Tensor) Eval() (Tensor, error, *Profiler)
- func (t Tensor) Reify() [][]interface{}
- func (t *Tensor) Reshape(signature string)
- func (t Tensor) Signature() string
- func (t Tensor) String() string
- func (t *Tensor) U(indices string) Expression
- type Term
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Expression ¶
type Expression struct {
// contains filtered or unexported fields
}
An Expression is not a Tensor. It's an Expression symbolizing a desired combination of tensor products and contractions on Tensors. When you evaluate it, you get a Tensor. Abstract index notation with Einstein summation.
func (Expression) D ¶
func (e Expression) D(indices string) Expression
func (Expression) Eval ¶
func (e Expression) Eval() (Tensor, error, *Profiler)
More pedestrian eval functions
func (Expression) U ¶
func (e Expression) U(indices string) Expression
type Function ¶
type Function struct {
// contains filtered or unexported fields
}
Function is a function that can be applied to every element of a Tensor. As of now, a caller can't make their own. They have to use a constructor from the types file which ensures types are aligned.
func NewRealFunction ¶
func NewRealScalar ¶
func NewStringFunction ¶
type Tensor ¶
type Tensor struct {
// contains filtered or unexported fields
}
A Tensor is not a matrix. It's a tensor. A Tensor is a multi-dimensional array that transforms according to the co and contravariant. tensor transformation laws.
func NewComplexTensor ¶
func NewComplexTensor(f func(i ...int) complex128, signature string, dim []int) Tensor
func NewRealTensor ¶
func NewStringTensor ¶
func Trace ¶
Trace is a contraction on two indices. eventually should forbid callers from accessing directly and/or verify indices exist to contract and are same dimensions.
func (Tensor) ContravariantIndices ¶
func (Tensor) CovariantIndices ¶
func (*Tensor) D ¶
func (t *Tensor) D(indices string) Expression
func (Tensor) Reify ¶
func (t Tensor) Reify() [][]interface{}
This method is the one most badly in need of testing. "Reify" is one of *many* possible ways to visualize a tensor as a matrix. The horizontal and vertical indices correspond to walking the covariant and contravariant indices of the tensor.
E.g. If a tensor has 3 contravariant indices of dimension 1 | 2 \ 3 and 1 covariant index of dimension 4, Reify will produce a 4 by (1*2*3)=6 matrix, with the indices sorted. Do not treat this as a real matrix it's merely for convenience.
func (*Tensor) U ¶
func (t *Tensor) U(indices string) Expression
Like t.U("ij").D("k").U("a").D("b") Like t1.U("jk").U("arb").D("xyz") Eval(t, t1) Eval(t.U("ij").D("k").U("a").D("b"), t1.U("jk").U("arb").D("xyz")) Mat multiply example Eval(t1.U("i"), t2.D("j")) Transpose like Eval(t1.I().U("j").D("i"))
type Term ¶
type Term struct {
List []Expression
}
A Term is a list of Expressions. It represents a single term of tensor products and contractions in abstract index notation.
func (Term) Eval ¶
Eval takes a list of expressions representing a solo or product term of tensors in abstract index notation and returns the resulting Tensor.
Note that shmensor Tensors are lazy, so computation is only performed when you call Reify().
Consider verbose mode boolean to explore what's happening.
type Type ¶
type Type interface { // Take two things, like numbers, get a new thing. Multiply(interface{}, interface{}) interface{} // Take two things, like numbers, get a new thing. Add(interface{}, interface{}) interface{} }
Type defines a ring element. To implement the interface define multiplication and addition of the ring elements.
Several default Tensor types and initializer functions are defined at the end of the file.
Note that most applications expect the inputs and output to be of the same type. You have to enforce that at object construction.