Caten Documentation

  • Home
  • Quickstart
  • Development
  • API Reference
    • caten/air
    • caten/aasm
    • caten/codegen
    • caten/api
      • Overview
      • Tensor
      • Func
      • Module
      • Model
      • Initializers
      • ShapeTracker
      • Facet API
      • StateDict
    • caten/nn
      • Activation
      • Convolution
      • Criterion
      • Embedding
      • Linear
      • Normalization
      • Padding
      • Pooling
      • Encoding
      • Optimizers
  • Ready to use packages
    • Overview
    • caten/apps.gpt2
  • External Packages
    • caten/gguf
    • caten/oonx
    • caten/llm
In this article
  • Initializers
    • [function] set-manual-seed
    • [macro] with-manual-seed
    • [function] ax+b
    • [function] !rand
    • [function] !normal
    • [function] !randn
    • [function] !uniform
    • [function] !randint
    • [function] !full
    • [function] xavier-uniform
    • [function] xavier-gaussian

Initializers

  1. Caten Documentation
  2. API Reference
  3. caten/api
  4. Initializers
|
  • Share via

  •  Edit this article

Initializers

[function] set-manual-seed

(set-manual-seed &key (seed 0))
Sets the seed for random operations.

[macro] with-manual-seed

(with-manual-seed (seed) &body body)
Sets the seed for random operations within the scope of the body.

[function] ax+b

(ax+b shape a b &key (out nil) (dtype *default-float*) (order *default-order*))

Generates an array sampled from this formula: x_i = a * index_components(i) + b.

There is a linspace function for the same purpose, but it is not lazy.

Lazy
CATEN-USER> (proceed (ax+b `(3 3) 2 1))
Result
Result
{Tensor{LISPBUFFER}[float32] :shape (3 3) :id STC207777
   ((1.0  3.0  5.0)
    (7.0  9.0  11.0)
    (13.0 15.0 17.0))
  :op #<PROCEEDNODE {1003239673}>
  :requires-grad NIL
  :variables (STC207688)
  :tracker #<TRACKER :order={row(0 1)} :shape=(3 3) :contiguous-p=T>}
Static
CATEN-USER> (linspace `(3 3) 1 0)
Result
Result
{Tensor{LISPBUFFER}[float32] :shape (3 3) :id TID207778
   ((0.0 1.0 2.0)
    (3.0 4.0 5.0)
    (6.0 7.0 8.0))
  :op #<ALLOCATE {1003269B63}>
  :requires-grad NIL
  :variables NIL
  :tracker #<TRACKER :order={row(0 1)} :shape=(3 3) :contiguous-p=T>}

[function] !rand

(!rand shape &key (dtype *default-float*) (order *default-order*) (out nil))

Creates a tensor whose elements are randomly sampled from a uniform distribution over the interval [0, 1).

There is a rand function for the same purpose, but it is not lazy.

Lazy
CATEN-USER> (proceed (!rand `(3 3)))
Result
Result
{Tensor{LISPBUFFER}[float32] :shape (3 3) :id STC215307
   ((0.40309912  0.8688215   0.9638163)
    (0.032803092 0.918832    0.59222883)
    (0.53384453  0.48372424  0.8027758))
  :op #<PROCEEDNODE {10072FC363}>
  :requires-grad NIL
  :variables (STC207840)
  :tracker #<TRACKER :order={row(0 1)} :shape=(3 3) :contiguous-p=T>}
Static
CATEN-USER> (rand `(3 3))
Result
Result
{Tensor{LISPBUFFER}[float32] :shape (3 3) :id TID215308
   ((0.8544815    0.89949685   0.06944181)
    (0.78085196   7.4467063e-4 0.94722736)
    (0.047116876  0.9624656    0.6471626))
  :op #<ALLOCATE {10073A1E13}>
  :requires-grad NIL
  :variables NIL
  :tracker #<TRACKER :order={row(0 1)} :shape=(3 3) :contiguous-p=T>}

[function] !normal

(!normal shape &key (mean 0.0) (std 1.0) (dtype *default-float*) (order *default-order*) (out nil))

Creates a tensor whose elements are randomly sampled from a normal distribution with the given mean and std.

There is a normal function for the same purpose, but it is not lazy.

Lazy
CATEN-USER> (proceed (!normal `(3 3) :mean 0.0 :std 2.0))
Result
Result
{Tensor{LISPBUFFER}[float32] :shape (3 3) :id STC231243
   ((1.9926395   -3.0460858  2.0359108)
    (-1.3665679  2.2740877   -0.34971234)
    (0.7738801   -0.7173807  1.5476315))
  :op #<PROCEEDNODE {100394FD63}>
  :requires-grad NIL
  :variables (STC215320)
  :tracker #<TRACKER :order={row(0 1)} :shape=(3 3) :contiguous-p=T>}
Static
CATEN-USER> (normal `(3 3) :mean 0.0 :std 1.0)
Result
Result
{Tensor{LISPBUFFER}[float32] :shape (3 3) :id TID231244
   ((-0.6933528   -0.618868    -0.09813504)
    (-0.3018336   0.73544437   -1.0356082)
    (-1.6392002   0.5641113    -0.094371416))
  :op #<ALLOCATE {10038585C3}>
  :requires-grad NIL
  :variables NIL
  :tracker #<TRACKER :order={row(0 1)} :shape=(3 3) :contiguous-p=T>}

[function] !randn

(!randn shape &key (dtype *default-float*) (order *default-order*) (out nil))

Creates a tensor whose elements are randomly sampled from a normal distribution with a mean of 0 and a standard deviation of 1.

There is a randn function for the same purpose, but it is not lazy.

Lazy
CATEN-USER> (proceed (!randn `(3 3)))
Result
Result
{Tensor{LISPBUFFER}[float32] :shape (3 3) :id STC263491
   ((0.4054314    -2.6517396   -0.93262064)
    (-0.44230795  -0.18937276  -0.42351857)
    (0.09603451   -0.004643383 -0.9779817))
  :op #<PROCEEDNODE {1001D978C3}>
  :requires-grad NIL
  :variables (STC248794)
  :tracker #<TRACKER :order={row(0 1)} :shape=(3 3) :contiguous-p=T>}
Static
CATEN-USER> (randn `(3 3))
Result
Result
{Tensor{LISPBUFFER}[float32] :shape (3 3) :id TID263492
   ((-0.23316607 0.39065427  0.5918632)
    (-0.771492   1.3980544   -0.2156676)
    (-0.96204996 -0.6995641  1.4401776))
  :op #<ALLOCATE {1001DEE6E3}>
  :requires-grad NIL
  :variables NIL
  :tracker #<TRACKER :order={row(0 1)} :shape=(3 3) :contiguous-p=T>}

[function] !uniform

(!uniform shape &key (low 0.0) (high 1.0) (dtype *default-float*) (order *default-order*) (out nil))

Creates a tensor whose elements are randomly sampled from a uniform distribution over the interval [low, high)

There is a uniform function for the same purpose, but it is not lazy.

Lazy
CATEN-USER> (proceed (!uniform `(3 3) :low 1.0 :high 2.0))
Result
Result
{Tensor{LISPBUFFER}[float32] :shape (3 3) :id STC272262
   ((1.5054502 1.7935554 1.0513923)
    (1.4500921 1.7713478 1.5610737)
    (1.7057834 1.4408889 1.9995518))
  :op #<PROCEEDNODE {10054A87E3}>
  :requires-grad NIL
  :variables (STC263504)
  :tracker #<TRACKER :order={row(0 1)} :shape=(3 3) :contiguous-p=T>}
Static
CATEN-USER> (uniform `(3 3) :low 1.0 :high 2.0)
Result
Result
{Tensor{LISPBUFFER}[float32] :shape (3 3) :id TID272263
   ((1.5276278 1.196649  1.2917286)
    (1.0492711 1.2254326 1.0443223)
    (1.2354891 1.7603551 1.2700266))
  :op #<ALLOCATE {1001A52793}>
  :requires-grad NIL
  :variables NIL
  :tracker #<TRACKER :order={row(0 1)} :shape=(3 3) :contiguous-p=T>}

[function] !randint

(!randint shape &key (low 0) (high 1) (dtype *default-int*) (order *default-order*) (out nil))

Creates a tensor whose elements are randomly sampled from a uniform distribution over the interval [low, high).

There is a randint function for the same purpose, but it is not lazy.

Lazy
CATEN-USER> (ctx:with-contextvar (:backend "clang") (proceed (!randint `(3 3) :low 1 :high 10)))
Result
Result
{Tensor{CLANGBUFFER}[int64] :shape (3 3) :id STC311011
   ((5 5 6)
    (7 8 9)
    (1 2 6))
  :op #<PROCEEDNODE {1002B03DA3}>
  :requires-grad NIL
  :variables (STC279893)
  :tracker #<TRACKER :order={row(0 1)} :shape=(3 3) :contiguous-p=T>}
Static
CATEN-USER> (ctx:with-contextvar (:backend "clang") (randint `(3 3) :low 1 :high 10 :dtype :int32))
Result
Result
{Tensor{CLANGBUFFER}[int32] :shape (3 3) :id TID311012
   ((3 3 4)
    (7 4 3)
    (5 1 9))
  :op #<ALLOCATE {100916C1F3}>
  :requires-grad NIL
  :variables NIL
  :tracker #<TRACKER :order={row(0 1)} :shape=(3 3) :contiguous-p=T>}

[function] !full

(!full shape fill-value &key (dtype *default-float*) (order *default-order*))

Initializes a tensor filled with fill-value.

lisp
CATEN-USER> (proceed (!full `(3 3) (inf)))
Result
Result
{Tensor{LISPBUFFER}[float32] :shape (3 3) :id STC339745
   ((#.SB-EXT:SINGLE-FLOAT-POSITIVE-INFINITY #.SB-EXT:SINGLE-FLOAT-POSITIVE-INFINITY #.SB-EXT:SINGLE-FLOAT-POSITIVE-INFINITY)
    (#.SB-EXT:SINGLE-FLOAT-POSITIVE-INFINITY #.SB-EXT:SINGLE-FLOAT-POSITIVE-INFINITY #.SB-EXT:SINGLE-FLOAT-POSITIVE-INFINITY)
    (#.SB-EXT:SINGLE-FLOAT-POSITIVE-INFINITY #.SB-EXT:SINGLE-FLOAT-POSITIVE-INFINITY #.SB-EXT:SINGLE-FLOAT-POSITIVE-INFINITY))
  :op #<PROCEEDNODE {10091948C3}>
  :requires-grad NIL
  :variables (TID339684)
  :tracker #<TRACKER :order={row(0 1)} :shape=(3 3) :contiguous-p=T>}

[function] xavier-uniform

No description provided

[function] xavier-gaussian

No description provided

Search
Enter a keyword to search.