Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtensors.html
More file actions
Latest commit
195 lines (176 loc) · 14.9 KB
/
Copy pathtensors.html
File metadata and controls
195 lines (176 loc) · 14.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="utf-8">
<title>tensors</title>
<metaname="viewport" content="width=device-width, initial-scale=1.0">
<metaname="author" content="Atılım Güneş Baydin, Don Syme, Barak A. Pearlmutter, Jeffrey Siskind, and DiffSharp contributors">
<metaname="description" content="DiffSharp is a tensor library with support for differentiable programming. It is designed for use in machine learning, probabilistic programming, optimization and other domains.">
<scriptsrc="https://code.jquery.com/jquery-1.8.0.js"></script>
<scriptsrc="https://code.jquery.com/ui/1.8.23/jquery-ui.js"></script>
<scriptsrc="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/js/bootstrap.min.js"></script>
<scripttype="text/javascript" asyncsrc="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<linkhref="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/css/bootstrap-combined.min.css" rel="stylesheet">
<linktype="text/css" rel="stylesheet" href="https://diffsharp.github.io/content/fsdocs-default.css" />
<scriptsrc="https://diffsharp.github.io/content/fsdocs-tips.js" type="text/javascript"></script>
<!-- BEGIN SEARCH BOX: this adds support for the search box -->
<linkrel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/JavaScript-autoComplete/1.0.4/auto-complete.css" />
<!-- END SEARCH BOX: this adds support for the search box -->
</head>
<body>
<divclass="container">
<!-- <div class="masthead">
<ul class="nav nav-pills pull-right">
<li><a href="https://fsharp.org">fsharp.org</a></li>
</ul>
<h3 class="muted">DiffSharp</h3>
</div> -->
<!-- <hr /> -->
<divclass="row">
<divclass="col-xs-12" style="height:10px;"></div>
</div>
<divclass="row">
<divclass="span3" id="fsdocs-nav">
<ahref="index.html"><imgclass="logo" src="https://diffsharp.github.io/img/diffsharp-logo-text.png"/></a>
<!-- BEGIN SEARCH BOX: this adds support for the search box -->
<divid="header">
<divclass="searchbox">
<labelfor="search-by">
<iclass="fas fa-search"></i>
</label>
<inputdata-search-input="" id="search-by" type="search" placeholder="Search..." />
<spandata-search-clear="">
<iclass="fas fa-times"></i>
</span>
</div>
</div>
<!-- END SEARCH BOX: this adds support for the search box -->
<ulclass="nav nav-list" id="menu">
<!-- <li class="nav-header">DiffSharp</li> -->
<!-- <li class="divider"></li> -->
<li><ahref="https://diffsharp.github.io/index.html">Home</a></li>
<li><ahref="https://github.com/DiffSharp/DiffSharp/">GitHub</a></li>
<li><ahref="https://github.com/DiffSharp/DiffSharp/blob/dev/LICENSE">License (BSD)</a></li>
<liclass="nav-header">Getting Started</li>
<!-- <li class="divider"></li> -->
<li><ahref="https://diffsharp.github.io/install.html">Install</a></li>
<li><ahref="https://diffsharp.github.io/quickstart.html">Quickstart</a></li>
<!-- <li><a href="https://diffsharp.github.io/tensors.html">Tensors</a></li> -->
<!-- <li><a href="https://diffsharp.github.io/differentiable-programming.html">Differentiable Programming</a></li> -->
<!-- <li><a href="https://diffsharp.github.io/nested-derivatives.html">Nested Derivatives</a></li> -->
<!-- <li><a href="https://diffsharp.github.io/models.html">Models</a></li> -->
<!-- <li><a href="https://diffsharp.github.io/optimization.html">Optimization</a></li> -->
<!-- <li><a href="https://diffsharp.github.io/probability-distributions.html">Probability Distributions</a></li> -->
<liclass="nav-header">Tutorials</li>
<!-- <li class="divider"></li> -->
<!-- <li><a href="https://diffsharp.github.io/tutorial-classifier.html">Classifier</a></li> -->
<!-- <li><a href="https://diffsharp.github.io/tutorial-gan.html">GAN</a></li> -->
<!-- <li><a href="https://diffsharp.github.io/tutorial-vae.html">VAE</a></li> -->
<!-- <li><a href="https://diffsharp.github.io/tutorial-language.html">Language Models</a></li> -->
<li><ahref="https://github.com/DiffSharp/DiffSharp/tree/dev/examples">More Examples</a></li>
<liclass="nav-header">API Documentation</li>
<li><ahref="https://diffsharp.github.io/reference/index.html">API Reference</a></li>
<li><ahref="https://diffsharp.github.io/extensions.html">Extensions</a></li>
<!-- <li class="nav-header">Examples</li> -->
<!-- <li class="divider"></li> -->
<!-- <li class="nav-header">Machine Learning</li> -->
<!-- <li><a href="https://diffsharp.github.io/examples-topic1.html">Topic 1</a></li> -->
<!-- <li class="divider"></li>
<li class="nav-header">Authors</li>
<li><a href="http://www.robots.ox.ac.uk/~gunes/">Atılım Güneş Baydin</a></li>
<li><a href="http://www.bcl.hamilton.ie/~barak/">Barak A. Pearlmutter</a></li>
<li><a href="https://www.microsoft.com/en-us/research/people/dsyme/">Don Syme</a></li> -->
</ul>
</div>
<divclass="span9" id="fsdocs-content">
<p><ahref="https://colab.research.google.com/github/DiffSharp/diffsharp.github.io/blob/master/tensors.ipynb"><imgsrc="https://colab.research.google.com/assets/colab-badge.svg" alt="Binder" /></a> 
<ahref="https://mybinder.org/v2/gh/diffsharp/diffsharp.github.io/master?filepath=tensors.ipynb"><imgsrc="img/badge-binder.svg" alt="Binder" /></a> 
<ahref="tensors.fsx"><imgsrc="img/badge-script.svg" alt="Script" /></a> 
<ahref="tensors.ipynb"><imgsrc="img/badge-notebook.svg" alt="Script" /></a></p>
<ul>
<li><p>The <ahref="https://diffsharp.github.io/reference/diffsharp-dsharp.html">dsharp</a> API</p></li>
<li><p>The <ahref="https://diffsharp.github.io/reference/diffsharp-tensor.html">Tensor</a> type</p></li>
</ul>
<p>Saving tensors as image and loading images as tensors</p>
<h2><aname="Converting-between-Tensors-and-arrays" class="anchor" href="#Converting-between-Tensors-and-arrays">Converting between Tensors and arrays</a></h2>
<p>System.Array and F# arrays</p>
<preclass="fssnip highlighted"><codelang="fsharp"><spanclass="k">open</span><spanonmouseout="hideTip(event, 'fs1', 10)" onmouseover="showTip(event, 'fs1', 10)" class="id">DiffSharp</span>
<spanclass="c">// Tensor</span>
<spanclass="k">let</span><spanonmouseout="hideTip(event, 'fs7', 11)" onmouseover="showTip(event, 'fs7', 11)" class="id">t1</span><spanclass="o">=</span><spanonmouseout="hideTip(event, 'fs2', 12)" onmouseover="showTip(event, 'fs2', 12)" class="rt">dsharp</span><spanclass="pn">.</span><spanonmouseout="hideTip(event, 'fs8', 13)" onmouseover="showTip(event, 'fs8', 13)" class="id">tensor</span><spanclass="pn">[</span><spanclass="o">0.0</span><spanclass="o">..</span><spanclass="n">0.2</span><spanclass="o">..</span><spanclass="n">1.0</span><spanclass="pn">]</span>
<spanclass="c">// System.Array</span>
<spanclass="k">let</span><spanonmouseout="hideTip(event, 'fs9', 14)" onmouseover="showTip(event, 'fs9', 14)" class="id">a1</span><spanclass="o">=</span><spanonmouseout="hideTip(event, 'fs7', 15)" onmouseover="showTip(event, 'fs7', 15)" class="id">t1</span><spanclass="pn">.</span><spanclass="id">toArray</span><spanclass="pn">(</span><spanclass="pn">)</span>
<spanclass="c">// []<float32></span>
<spanclass="k">let</span><spanonmouseout="hideTip(event, 'fs10', 16)" onmouseover="showTip(event, 'fs10', 16)" class="id">a1b</span><spanclass="o">=</span><spanonmouseout="hideTip(event, 'fs7', 17)" onmouseover="showTip(event, 'fs7', 17)" class="id">t1</span><spanclass="pn">.</span><spanclass="id">toArray</span><spanclass="pn">(</span><spanclass="pn">)</span><spanclass="o">:?></span><spanonmouseout="hideTip(event, 'fs11', 18)" onmouseover="showTip(event, 'fs11', 18)" class="vt">float32</span><spanclass="pn">[</span><spanclass="pn">]</span>
<spanclass="c">// Tensor</span>
<spanclass="k">let</span><spanonmouseout="hideTip(event, 'fs12', 19)" onmouseover="showTip(event, 'fs12', 19)" class="id">t2</span><spanclass="o">=</span><spanonmouseout="hideTip(event, 'fs2', 20)" onmouseover="showTip(event, 'fs2', 20)" class="rt">dsharp</span><spanclass="pn">.</span><spanonmouseout="hideTip(event, 'fs13', 21)" onmouseover="showTip(event, 'fs13', 21)" class="id">randn</span><spanclass="pn">(</span><spanclass="pn">[</span><spanclass="n">3</span><spanclass="pn">;</span><spanclass="n">3</span><spanclass="pn">;</span><spanclass="n">3</span><spanclass="pn">]</span><spanclass="pn">)</span>
<spanclass="c">// [,,]<float32></span>
<spanclass="k">let</span><spanonmouseout="hideTip(event, 'fs14', 22)" onmouseover="showTip(event, 'fs14', 22)" class="id">a2</span><spanclass="o">=</span><spanonmouseout="hideTip(event, 'fs12', 23)" onmouseover="showTip(event, 'fs12', 23)" class="id">t2</span><spanclass="pn">.</span><spanclass="id">toArray</span><spanclass="pn">(</span><spanclass="pn">)</span><spanclass="o">:?></span><spanonmouseout="hideTip(event, 'fs11', 24)" onmouseover="showTip(event, 'fs11', 24)" class="vt">float32</span><spanclass="pn">[</span><spanclass="pn">,</span><spanclass="pn">,</span><spanclass="pn">]</span>
</code></pre>
<divclass="fsdocs-tip" id="fs1">namespace DiffSharp</div>
<divclass="fsdocs-tip" id="fs2">type dsharp =
static member abs: input: Tensor -> Tensor
static member acos: input: Tensor -> Tensor
static member add: a: Tensor * b: Tensor -> Tensor
static member arange: endVal: float * ?startVal: float * ?step: float * ?device: Device * ?dtype: Dtype * ?backend: Backend -> Tensor + 1 overload
static member arangeLike: input: Tensor * endVal: float * ?startVal: float * ?step: float * ?device: Device * ?dtype: Dtype * ?backend: Backend -> Tensor + 1 overload
static member argmax: input: Tensor -> int[] + 1 overload
static member argmin: input: Tensor -> int[] + 1 overload
static member asin: input: Tensor -> Tensor
static member atan: input: Tensor -> Tensor
static member backends: unit -> Backend list
...<br/><em><summary>
Tensor operations
</summary></em></div>
<divclass="fsdocs-tip" id="fs3">static member DiffSharp.dsharp.config: unit -> DiffSharp.Device * DiffSharp.Dtype * DiffSharp.Backend * DiffSharp.Printer<br/>static member DiffSharp.dsharp.config: configuration: (DiffSharp.Device * DiffSharp.Dtype * DiffSharp.Backend * DiffSharp.Printer) -> unit<br/>static member DiffSharp.dsharp.config: ?device: DiffSharp.Device * ?dtype: DiffSharp.Dtype * ?backend: DiffSharp.Backend * ?printer: DiffSharp.Printer -> unit</div>
<divclass="fsdocs-tip" id="fs4">Multiple items<br/>module Backend
from DiffSharp<br/><em><summary>
Contains functions and settings related to backend specifications.
</summary></em><br/><br/>--------------------<br/>type Backend =
| Reference
| Torch
| Other of name: string * code: int
override ToString: unit -> string
member Name: string<br/><em><summary>
Represents a backend for DiffSharp tensors
</summary></em></div>
<divclass="fsdocs-tip" id="fs5">union case DiffSharp.Backend.Reference: DiffSharp.Backend<br/><em><summary>
The reference backend
</summary></em></div>
<divclass="fsdocs-tip" id="fs6">static member DiffSharp.dsharp.seed: ?seed: int -> unit</div>
<divclass="fsdocs-tip" id="fs7">val t1: Tensor</div>
<divclass="fsdocs-tip" id="fs8">static member dsharp.tensor: value: obj * ?device: Device * ?dtype: Dtype * ?backend: Backend -> Tensor</div>
<divclass="fsdocs-tip" id="fs9">val a1: System.Array</div>
<divclass="fsdocs-tip" id="fs10">val a1b: float32[]</div>
<divclass="fsdocs-tip" id="fs11">Multiple items<br/>val float32: value: 'T -> float32 (requires member op_Explicit)<br/><em><summary>Converts the argument to 32-bit float. This is a direct conversion for all
primitive numeric types. For strings, the input is converted using <c>Single.Parse()</c>
with InvariantCulture settings. Otherwise the operation requires an appropriate
static conversion method on the input type.</summary><br/><param name="value">The input value.</param><br/><returns>The converted float32</returns><br/><example id="float32-example"><code lang="fsharp"></code></example></em><br/><br/>--------------------<br/>[<Struct>]
type float32 = System.Single<br/><em><summary>An abbreviation for the CLI type <see cref="T:System.Single" />.</summary><br/><category>Basic Types</category></em><br/><br/>--------------------<br/>type float32<'Measure> =
float32<br/><em><summary>The type of single-precision floating point numbers, annotated with a unit of measure.
The unit of measure is erased in compiled code and when values of this type
are analyzed using reflection. The type is representationally equivalent to
<see cref="T:System.Single" />.
</summary><br/><category>Basic Types with Units of Measure</category></em></div>
<divclass="fsdocs-tip" id="fs12">val t2: Tensor</div>
<divclass="fsdocs-tip" id="fs13">static member dsharp.randn: length: int * ?device: Device * ?dtype: Dtype * ?backend: Backend -> Tensor<br/>static member dsharp.randn: shape: seq<int> * ?device: Device * ?dtype: Dtype * ?backend: Backend -> Tensor</div>
<divclass="fsdocs-tip" id="fs14">val a2: float32[,,]</div>
</div>
</div>
<divclass="row">
<divclass="span3"></div>
<divclass="span9">
<hr>
<pstyle="height:50px; display: table-cell; vertical-align: bottom;">© Copyright 2021, DiffSharp Contributors.</p>
<br>
</div>
</div>
</div>
<!-- BEGIN SEARCH BOX: this adds support for the search box -->
<linkrel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/JavaScript-autoComplete/1.0.4/auto-complete.css" />
<scripttype="text/javascript">varfsdocs_search_baseurl='https://diffsharp.github.io/'</script>
<scripttype="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lunr.js/2.3.8/lunr.min.js"></script>
<scripttype="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/JavaScript-autoComplete/1.0.4/auto-complete.min.js"></script>
<scripttype="text/javascript" src="https://diffsharp.github.io/content/fsdocs-search.js"></script>
<!-- END SEARCH BOX: this adds support for the search box -->
</body>
</html>