tensorflow-ops-0.2.0.0: Friendly layer around TensorFlow bindings.

Safe HaskellNone
LanguageHaskell2010

TensorFlow.Ops

Contents

Description

This module contains definitions for some built-in TensorFlow operations.

Note that certain, "stateful" ops like variable and assign return a Build action (e.g., Build (Tensor Ref a) instead of a pure value; the returned Tensors are always rendered in the current Build context. This approach helps us avoid problems with inlining or common subexpression elimination, by writing

do
    v <- variable []
    w <- assign v 3
    render $ w * w

instead of

let
   v = variable []
   w = assign v 3
in w * w

since the latter could be reasonably transformed by the compiler into (or vice versa)

let
   v = variable []
   w = assign v 3
   w' = assign v 3
in w * w'

Ops should return a Build action if their original OpDef marks them as stateful, or if they take any Refs as input. (This mirrors the rules that TensorFlow uses to avoid common subexpression elimination.)

Synopsis

Documentation

add #

Arguments

:: OneOf ((:) * (Complex Double) ((:) * (Complex Float) ((:) * ByteString ((:) * Int16 ((:) * Int32 ((:) * Int64 ((:) * Int8 ((:) * Word16 ((:) * Word8 ((:) * Double ((:) * Float ([] *)))))))))))) t 
=> Tensor v'1 t

x

-> Tensor v'2 t

y

-> Tensor Build t

z

add' #

Arguments

:: OneOf ((:) * (Complex Double) ((:) * (Complex Float) ((:) * ByteString ((:) * Int16 ((:) * Int32 ((:) * Int64 ((:) * Int8 ((:) * Word16 ((:) * Word8 ((:) * Double ((:) * Float ([] *)))))))))))) t 
=> OpParams 
-> Tensor v'1 t

x

-> Tensor v'2 t

y

-> Tensor Build t

z

abs #

Arguments

:: OneOf ((:) * Int32 ((:) * Int64 ((:) * Word16 ((:) * Double ((:) * Float ([] *)))))) t 
=> Tensor v'1 t

x

-> Tensor Build t

y

abs' #

Arguments

:: OneOf ((:) * Int32 ((:) * Int64 ((:) * Word16 ((:) * Double ((:) * Float ([] *)))))) t 
=> OpParams 
-> Tensor v'1 t

x

-> Tensor Build t

y

addN #

Arguments

:: OneOf ((:) * (Complex Double) ((:) * (Complex Float) ((:) * Int16 ((:) * Int32 ((:) * Int64 ((:) * Int8 ((:) * Word16 ((:) * Word32 ((:) * Word64 ((:) * Word8 ((:) * Double ((:) * Float ((:) * Variant ([] *)))))))))))))) t 
=> [Tensor v'1 t]

inputs

-> Tensor Build t

sum

addN' #

Arguments

:: OneOf ((:) * (Complex Double) ((:) * (Complex Float) ((:) * Int16 ((:) * Int32 ((:) * Int64 ((:) * Int8 ((:) * Word16 ((:) * Word32 ((:) * Word64 ((:) * Word8 ((:) * Double ((:) * Float ((:) * Variant ([] *)))))))))))))) t 
=> OpParams 
-> [Tensor v'1 t]

inputs

-> Tensor Build t

sum

argMax #

Arguments

:: (OneOf ((:) * (Complex Double) ((:) * (Complex Float) ((:) * Int16 ((:) * Int32 ((:) * Int64 ((:) * Int8 ((:) * Word16 ((:) * Word32 ((:) * Word64 ((:) * Word8 ((:) * Double ((:) * Float ([] *))))))))))))) t, OneOf ((:) * Int32 ((:) * Int64 ([] *))) tidx, OneOf ((:) * Int32 ((:) * Int64 ([] *))) output_type) 
=> Tensor v'1 t

input

-> Tensor v'2 tidx

dimension

-> Tensor Build output_type

output

argMax' #

Arguments

:: (OneOf ((:) * (Complex Double) ((:) * (Complex Float) ((:) * Int16 ((:) * Int32 ((:) * Int64 ((:) * Int8 ((:) * Word16 ((:) * Word32 ((:) * Word64 ((:) * Word8 ((:) * Double ((:) * Float ([] *))))))))))))) t, OneOf ((:) * Int32 ((:) * Int64 ([] *))) tidx, OneOf ((:) * Int32 ((:) * Int64 ([] *))) output_type) 
=> OpParams 
-> Tensor v'1 t

input

-> Tensor v'2 tidx

dimension

-> Tensor Build output_type

output

assign #

Arguments

:: (MonadBuild m', TensorType t) 
=> Tensor Ref t

ref

-> Tensor v'2 t

value

-> m' (Tensor Ref t)

output_ref

assign' #

Arguments

:: (MonadBuild m', TensorType t) 
=> OpParams 
-> Tensor Ref t

ref

-> Tensor v'2 t

value

-> m' (Tensor Ref t)

output_ref

broadcastGradientArgs #

Arguments

:: OneOf ((:) * Int32 ((:) * Int64 ([] *))) t 
=> Tensor v'1 t

s0

-> Tensor v'2 t

s1

-> (Tensor Build t, Tensor Build t)

(r0, r1)

  • r0
  • r1

broadcastGradientArgs' #

Arguments

:: OneOf ((:) * Int32 ((:) * Int64 ([] *))) t 
=> OpParams 
-> Tensor v'1 t

s0

-> Tensor v'2 t

s1

-> (Tensor Build t, Tensor Build t)

(r0, r1)

  • r0
  • r1

cast #

Arguments

:: (TensorType srcT, TensorType dstT) 
=> Tensor v'1 srcT

x

-> Tensor Build dstT

y

cast' #

Arguments

:: (TensorType srcT, TensorType dstT) 
=> OpParams 
-> Tensor v'1 srcT

x

-> Tensor Build dstT

y

concat #

Arguments

:: TensorType t 
=> Tensor v'1 Int32

concat_dim

-> [Tensor v'2 t]

values

-> Tensor Build t

output

concat' #

Arguments

:: TensorType t 
=> OpParams 
-> Tensor v'1 Int32

concat_dim

-> [Tensor v'2 t]

values

-> Tensor Build t

output

constant :: TensorType a => Shape -> [a] -> Tensor Build a Source #

Create a constant tensor.

The values should be in row major order, e.g.,

element 0: index (0, ..., 0) element 1: index (0, ..., 1) ...

constant' :: forall a. TensorType a => OpParams -> Shape -> [a] -> Tensor Build a Source #

equal #

Arguments

:: OneOf ((:) * (Complex Double) ((:) * (Complex Float) ((:) * Bool ((:) * ByteString ((:) * Int16 ((:) * Int32 ((:) * Int64 ((:) * Int8 ((:) * Word16 ((:) * Word8 ((:) * Double ((:) * Float ([] *))))))))))))) t 
=> Tensor v'1 t

x

-> Tensor v'2 t

y

-> Tensor Build Bool

z

equal' #

Arguments

:: OneOf ((:) * (Complex Double) ((:) * (Complex Float) ((:) * Bool ((:) * ByteString ((:) * Int16 ((:) * Int32 ((:) * Int64 ((:) * Int8 ((:) * Word16 ((:) * Word8 ((:) * Double ((:) * Float ([] *))))))))))))) t 
=> OpParams 
-> Tensor v'1 t

x

-> Tensor v'2 t

y

-> Tensor Build Bool

z

initializedVariable :: (MonadBuild m, TensorType a) => Tensor v a -> m (Tensor Ref a) Source #

Creates a variable initialized to the given value. Initialization happens next time session runs.

zeroInitializedVariable :: (MonadBuild m, TensorType a, Num a) => Shape -> m (Tensor Ref a) Source #

Creates a zero-initialized variable with the given shape.

fill #

Arguments

:: (TensorType t, OneOf ((:) * Int32 ((:) * Int64 ([] *))) index_type) 
=> Tensor v'1 index_type

dims

-> Tensor v'2 t

value

-> Tensor Build t

output

fill' #

Arguments

:: (TensorType t, OneOf ((:) * Int32 ((:) * Int64 ([] *))) index_type) 
=> OpParams 
-> Tensor v'1 index_type

dims

-> Tensor v'2 t

value

-> Tensor Build t

output

identity #

Arguments

:: TensorType t 
=> Tensor v'1 t

input

-> Tensor Build t

output

identity' #

Arguments

:: TensorType t 
=> OpParams 
-> Tensor v'1 t

input

-> Tensor Build t

output

matMul #

Arguments

:: OneOf ((:) * (Complex Double) ((:) * (Complex Float) ((:) * Int32 ((:) * Word16 ((:) * Double ((:) * Float ([] *))))))) t 
=> Tensor v'1 t

a

-> Tensor v'2 t

b

-> Tensor Build t

product

matMul' #

Arguments

:: OneOf ((:) * (Complex Double) ((:) * (Complex Float) ((:) * Int32 ((:) * Word16 ((:) * Double ((:) * Float ([] *))))))) t 
=> OpParams 
-> Tensor v'1 t

a

-> Tensor v'2 t

b

-> Tensor Build t

product

mean #

Arguments

:: (OneOf ((:) * (Complex Double) ((:) * (Complex Float) ((:) * Int16 ((:) * Int32 ((:) * Int64 ((:) * Int8 ((:) * Word16 ((:) * Word32 ((:) * Word64 ((:) * Word8 ((:) * Double ((:) * Float ([] *))))))))))))) t, OneOf ((:) * Int32 ((:) * Int64 ([] *))) tidx) 
=> Tensor v'1 t

input

-> Tensor v'2 tidx

reduction_indices

-> Tensor Build t

output

mean' #

Arguments

:: (OneOf ((:) * (Complex Double) ((:) * (Complex Float) ((:) * Int16 ((:) * Int32 ((:) * Int64 ((:) * Int8 ((:) * Word16 ((:) * Word32 ((:) * Word64 ((:) * Word8 ((:) * Double ((:) * Float ([] *))))))))))))) t, OneOf ((:) * Int32 ((:) * Int64 ([] *))) tidx) 
=> OpParams 
-> Tensor v'1 t

input

-> Tensor v'2 tidx

reduction_indices

-> Tensor Build t

output

mul #

Arguments

:: OneOf ((:) * (Complex Double) ((:) * (Complex Float) ((:) * Int16 ((:) * Int32 ((:) * Int64 ((:) * Int8 ((:) * Word16 ((:) * Word8 ((:) * Double ((:) * Float ([] *))))))))))) t 
=> Tensor v'1 t

x

-> Tensor v'2 t

y

-> Tensor Build t

z

mul' #

Arguments

:: OneOf ((:) * (Complex Double) ((:) * (Complex Float) ((:) * Int16 ((:) * Int32 ((:) * Int64 ((:) * Int8 ((:) * Word16 ((:) * Word8 ((:) * Double ((:) * Float ([] *))))))))))) t 
=> OpParams 
-> Tensor v'1 t

x

-> Tensor v'2 t

y

-> Tensor Build t

z

neg #

Arguments

:: OneOf ((:) * (Complex Double) ((:) * (Complex Float) ((:) * Int32 ((:) * Int64 ((:) * Word16 ((:) * Double ((:) * Float ([] *)))))))) t 
=> Tensor v'1 t

x

-> Tensor Build t

y

neg' #

Arguments

:: OneOf ((:) * (Complex Double) ((:) * (Complex Float) ((:) * Int32 ((:) * Int64 ((:) * Word16 ((:) * Double ((:) * Float ([] *)))))))) t 
=> OpParams 
-> Tensor v'1 t

x

-> Tensor Build t

y

oneHot #

Arguments

:: (TensorType t, OneOf ((:) * Int32 ((:) * Int64 ((:) * Word8 ([] *)))) tI) 
=> Tensor v'1 tI

indices

-> Tensor v'2 Int32

depth

-> Tensor v'3 t

on_value

-> Tensor v'4 t

off_value

-> Tensor Build t

output

oneHot' #

Arguments

:: (TensorType t, OneOf ((:) * Int32 ((:) * Int64 ((:) * Word8 ([] *)))) tI) 
=> OpParams 
-> Tensor v'1 tI

indices

-> Tensor v'2 Int32

depth

-> Tensor v'3 t

on_value

-> Tensor v'4 t

off_value

-> Tensor Build t

output

pack #

Arguments

:: TensorType t 
=> [Tensor v'1 t]

values

-> Tensor Build t

output

pack' #

Arguments

:: TensorType t 
=> OpParams 
-> [Tensor v'1 t]

values

-> Tensor Build t

output

placeholder' :: forall m a. (MonadBuild m, TensorType a) => OpParams -> Shape -> m (Tensor Value a) Source #

range #

Arguments

:: OneOf ((:) * Int32 ((:) * Int64 ((:) * Word16 ((:) * Double ((:) * Float ([] *)))))) tidx 
=> Tensor v'1 tidx

start

-> Tensor v'2 tidx

limit

-> Tensor v'3 tidx

delta

-> Tensor Build tidx

output

range' #

Arguments

:: OneOf ((:) * Int32 ((:) * Int64 ((:) * Word16 ((:) * Double ((:) * Float ([] *)))))) tidx 
=> OpParams 
-> Tensor v'1 tidx

start

-> Tensor v'2 tidx

limit

-> Tensor v'3 tidx

delta

-> Tensor Build tidx

output

reducedShape :: (OneOf '[Int32, Int64] t1, OneOf '[Int32, Int64] t2) => Tensor v1 t1 -> Tensor v2 t2 -> Tensor Build Int32 Source #

Helper function for reduction ops (translation of math_ops.reduced_shape).

reduceMean :: (TensorType a, OneOf '[Double, Float, Complex Float, Complex Double] a) => Tensor v a -> Tensor Build a Source #

Computes the mean of elements across dimensions of a tensor. See mean

relu #

Arguments

:: OneOf ((:) * Int16 ((:) * Int32 ((:) * Int64 ((:) * Int8 ((:) * Word16 ((:) * Word32 ((:) * Word64 ((:) * Word8 ((:) * Double ((:) * Float ([] *))))))))))) t 
=> Tensor v'1 t

features

-> Tensor Build t

activations

relu' #

Arguments

:: OneOf ((:) * Int16 ((:) * Int32 ((:) * Int64 ((:) * Int8 ((:) * Word16 ((:) * Word32 ((:) * Word64 ((:) * Word8 ((:) * Double ((:) * Float ([] *))))))))))) t 
=> OpParams 
-> Tensor v'1 t

features

-> Tensor Build t

activations

reluGrad #

Arguments

:: OneOf ((:) * Int16 ((:) * Int32 ((:) * Int64 ((:) * Int8 ((:) * Word16 ((:) * Word32 ((:) * Word64 ((:) * Word8 ((:) * Double ((:) * Float ([] *))))))))))) t 
=> Tensor v'1 t

gradients

-> Tensor v'2 t

features

-> Tensor Build t

backprops

reluGrad' #

Arguments

:: OneOf ((:) * Int16 ((:) * Int32 ((:) * Int64 ((:) * Int8 ((:) * Word16 ((:) * Word32 ((:) * Word64 ((:) * Word8 ((:) * Double ((:) * Float ([] *))))))))))) t 
=> OpParams 
-> Tensor v'1 t

gradients

-> Tensor v'2 t

features

-> Tensor Build t

backprops

reshape #

Arguments

:: (TensorType t, OneOf ((:) * Int32 ((:) * Int64 ([] *))) tshape) 
=> Tensor v'1 t

tensor

-> Tensor v'2 tshape

shape

-> Tensor Build t

output

reshape' #

Arguments

:: (TensorType t, OneOf ((:) * Int32 ((:) * Int64 ([] *))) tshape) 
=> OpParams 
-> Tensor v'1 t

tensor

-> Tensor v'2 tshape

shape

-> Tensor Build t

output

restore Source #

Arguments

:: (MonadBuild m, TensorType a) 
=> ByteString

File path.

-> Tensor Ref a

Tensor to restore.

-> m ControlNode 

Restore a tensor's value from a checkpoint file.

restoreFromName Source #

Arguments

:: (MonadBuild m, TensorType a) 
=> ByteString

File path.

-> ByteString

Tensor name override.

-> Tensor Ref a

Tensor to restore.

-> m ControlNode 

Restore a tensor's value from a checkpoint file.

This version allows restoring from a checkpoint file that uses a different tensor name than the variable.

save Source #

Arguments

:: (Rendered (Tensor v), MonadBuild m, TensorType a) 
=> ByteString

File path.

-> [Tensor v a]

Tensors to save.

-> m ControlNode 

scalar :: TensorType a => a -> Tensor Build a Source #

Create a constant scalar.

sign #

Arguments

:: OneOf ((:) * (Complex Double) ((:) * (Complex Float) ((:) * Int32 ((:) * Int64 ((:) * Word16 ((:) * Double ((:) * Float ([] *)))))))) t 
=> Tensor v'1 t

x

-> Tensor Build t

y

sign' #

Arguments

:: OneOf ((:) * (Complex Double) ((:) * (Complex Float) ((:) * Int32 ((:) * Int64 ((:) * Word16 ((:) * Double ((:) * Float ([] *)))))))) t 
=> OpParams 
-> Tensor v'1 t

x

-> Tensor Build t

y

size #

Arguments

:: (TensorType t, OneOf ((:) * Int32 ((:) * Int64 ([] *))) out_type) 
=> Tensor v'1 t

input

-> Tensor Build out_type

output

size' #

Arguments

:: (TensorType t, OneOf ((:) * Int32 ((:) * Int64 ([] *))) out_type) 
=> OpParams 
-> Tensor v'1 t

input

-> Tensor Build out_type

output

softmax #

Arguments

:: OneOf ((:) * Word16 ((:) * Double ((:) * Float ([] *)))) t 
=> Tensor v'1 t

logits

-> Tensor Build t

softmax

softmax' #

Arguments

:: OneOf ((:) * Word16 ((:) * Double ((:) * Float ([] *)))) t 
=> OpParams 
-> Tensor v'1 t

logits

-> Tensor Build t

softmax

softmaxCrossEntropyWithLogits #

Arguments

:: OneOf ((:) * Word16 ((:) * Double ((:) * Float ([] *)))) t 
=> Tensor v'1 t

features

-> Tensor v'2 t

labels

-> (Tensor Build t, Tensor Build t)

(loss, backprop)

  • loss
  • backprop

softmaxCrossEntropyWithLogits' #

Arguments

:: OneOf ((:) * Word16 ((:) * Double ((:) * Float ([] *)))) t 
=> OpParams 
-> Tensor v'1 t

features

-> Tensor v'2 t

labels

-> (Tensor Build t, Tensor Build t)

(loss, backprop)

  • loss
  • backprop

sparseToDense #

Arguments

:: (TensorType t, OneOf ((:) * Int32 ((:) * Int64 ([] *))) tindices) 
=> Tensor v'1 tindices

sparse_indices

-> Tensor v'2 tindices

output_shape

-> Tensor v'3 t

sparse_values

-> Tensor v'4 t

default_value

-> Tensor Build t

dense

sparseToDense' #

Arguments

:: (TensorType t, OneOf ((:) * Int32 ((:) * Int64 ([] *))) tindices) 
=> OpParams 
-> Tensor v'1 tindices

sparse_indices

-> Tensor v'2 tindices

output_shape

-> Tensor v'3 t

sparse_values

-> Tensor v'4 t

default_value

-> Tensor Build t

dense

sub #

Arguments

:: OneOf ((:) * (Complex Double) ((:) * (Complex Float) ((:) * Int16 ((:) * Int32 ((:) * Int64 ((:) * Int8 ((:) * Word16 ((:) * Word8 ((:) * Double ((:) * Float ([] *))))))))))) t 
=> Tensor v'1 t

x

-> Tensor v'2 t

y

-> Tensor Build t

z

sub' #

Arguments

:: OneOf ((:) * (Complex Double) ((:) * (Complex Float) ((:) * Int16 ((:) * Int32 ((:) * Int64 ((:) * Int8 ((:) * Word16 ((:) * Word8 ((:) * Double ((:) * Float ([] *))))))))))) t 
=> OpParams 
-> Tensor v'1 t

x

-> Tensor v'2 t

y

-> Tensor Build t

z

sum #

Arguments

:: (OneOf ((:) * (Complex Double) ((:) * (Complex Float) ((:) * Int16 ((:) * Int32 ((:) * Int64 ((:) * Int8 ((:) * Word16 ((:) * Word32 ((:) * Word64 ((:) * Word8 ((:) * Double ((:) * Float ([] *))))))))))))) t, OneOf ((:) * Int32 ((:) * Int64 ([] *))) tidx) 
=> Tensor v'1 t

input

-> Tensor v'2 tidx

reduction_indices

-> Tensor Build t

output

sum' #

Arguments

:: (OneOf ((:) * (Complex Double) ((:) * (Complex Float) ((:) * Int16 ((:) * Int32 ((:) * Int64 ((:) * Int8 ((:) * Word16 ((:) * Word32 ((:) * Word64 ((:) * Word8 ((:) * Double ((:) * Float ([] *))))))))))))) t, OneOf ((:) * Int32 ((:) * Int64 ([] *))) tidx) 
=> OpParams 
-> Tensor v'1 t

input

-> Tensor v'2 tidx

reduction_indices

-> Tensor Build t

output

reduceSum :: OneOf '[Double, Float, Int32, Int64, Complex Float, Complex Double] a => Tensor v a -> Tensor Build a Source #

Sum a tensor down to a scalar Seee sum

transpose #

Arguments

:: (TensorType t, OneOf ((:) * Int32 ((:) * Int64 ([] *))) tperm) 
=> Tensor v'1 t

x

-> Tensor v'2 tperm

perm

-> Tensor Build t

y

transpose' #

Arguments

:: (TensorType t, OneOf ((:) * Int32 ((:) * Int64 ([] *))) tperm) 
=> OpParams 
-> Tensor v'1 t

x

-> Tensor v'2 tperm

perm

-> Tensor Build t

y

truncatedNormal Source #

Arguments

:: (MonadBuild m, OneOf '[Word16, Double, Float] a) 
=> Tensor v Int64

Shape.

-> m (Tensor Value a) 

Random tensor from the unit normal distribution with bounded values.

This is a type-restricted version of truncatedNormal.

truncatedNormal' Source #

Arguments

:: (MonadBuild m, OneOf '[Word16, Double, Float] a) 
=> OpParams 
-> Tensor v Int64

Shape.

-> m (Tensor Value a) 

variable #

Arguments

:: (MonadBuild m', TensorType dtype) 
=> Shape

shape

-> m' (Tensor Ref dtype)

ref

variable' #

Arguments

:: (MonadBuild m', TensorType dtype) 
=> OpParams 
-> Shape

shape

-> m' (Tensor Ref dtype)

ref

vector :: TensorType a => [a] -> Tensor Build a Source #

Create a constant vector.

zeros :: forall a. (Num a, TensorType a) => Shape -> Tensor Build a Source #

zerosLike #

Arguments

:: TensorType t 
=> Tensor v'1 t

x

-> Tensor Build t

y

zerosLike' #

Arguments

:: TensorType t 
=> OpParams 
-> Tensor v'1 t

x

-> Tensor Build t

y

scalarize :: TensorType a => Tensor v a -> Tensor Build a Source #

Reshape a N-D tensor down to a scalar.

See reshape.

Orphan instances

(TensorType a, Num a, (~) (* -> *) v Build, OneOf ((:) * Double ((:) * Float ((:) * Int32 ((:) * Int64 ((:) * (Complex Float) ((:) * (Complex Double) ([] *))))))) a) => Num (Tensor v a) Source #

Must be defined as an orphan because of the dependency order between Ops and Tensor.

The indirect constraint "v ~ Value" helps disambiguate types, for example in "neg 1 :: Tensor Value Float", it helps find the type of the subexpression "1".

Methods

(+) :: Tensor v a -> Tensor v a -> Tensor v a #

(-) :: Tensor v a -> Tensor v a -> Tensor v a #

(*) :: Tensor v a -> Tensor v a -> Tensor v a #

negate :: Tensor v a -> Tensor v a #

abs :: Tensor v a -> Tensor v a #

signum :: Tensor v a -> Tensor v a #

fromInteger :: Integer -> Tensor v a #