@@ -73,7 +73,7 @@ VARIANT // Variant
73
73
74
74
TensorFlow Scala also provides value classes for the types
75
75
that are not natively supported by Scala (e.g.,
76
- @scaladoc [ UByte] ( org.platanios.tensorflow.api.types.UByte )
76
+ @scaladoc [ UByte] ( org.platanios.tensorflow.api.core. types.UByte )
77
77
corresponds to ` UINT8 ` ).
78
78
79
79
It is also possible to cast tensors from one data type to
@@ -98,11 +98,50 @@ which stands for *TensorFlow Imperative*
98
98
99
99
@@@
100
100
101
- ## Rank
101
+ ## Shape
102
+
103
+ The shape of a tensor is the number of elements it contains
104
+ in each dimension. The TensorFlow documentation uses two
105
+ notational conventions to describe tensor dimensionality:
106
+ * rank* , and * shape* . The following table shows how these
107
+ relate to one another:
108
+
109
+ | Rank | Shape | Example |
110
+ | :-----| :-------------------| :----------------------------------------|
111
+ | 0 | [ ] | A 0-D tensor. A scalar. |
112
+ | 1 | [ D0] | A 1-D tensor with shape [ 5] . |
113
+ | 2 | [ D0, D1] | A 2-D tensor with shape [ 3, 4] . |
114
+ | 3 | [ D0, D1, D2] | A 3-D tensor with shape [ 1, 4, 3] . |
115
+ | n | [ D0, D1, ... Dn-1] | A tensor with shape [ D0, D1, ... Dn-1] . |
116
+
117
+ Shapes can be automatically converted to integer tensors,
118
+ if necessary.
119
+
120
+ @@@ note
121
+
122
+ Shapes are automatically converted to ` Tensor[Int] ` and not
123
+ ` Tensor[Long] ` in order to improve performance when working
124
+ with GPUs. The reason is that TensorFlow treats integer
125
+ tensors in a special manner, if they are placed on GPUs,
126
+ assuming that they represent shapes.
127
+
128
+ @@@
129
+
130
+ For example:
131
+
132
+ @@snip [ Tensors.scala] ( /docs/src/main/scala/Tensors.scala ) { #tensor_shape_examples }
102
133
103
- The rank of a [ ` Tensor ` ] [ tensor ] is its number of dimensions. Synonyms for rank include order or degree or
104
- ` n ` -dimension. Note that rank in TensorFlow is not the same as matrix rank in mathematics. As the following table shows,
105
- each rank in TensorFlow corresponds to a different mathematical entity:
134
+ The shape of a tensor can be inspected using:
135
+
136
+ @@snip [ Tensors.scala] ( /docs/src/main/scala/Tensors.scala ) { #tensor_inspect_shape_example }
137
+
138
+ ### Rank
139
+
140
+ The rank of of a tensor is its number of dimensions.
141
+ Synonyms for rank include order or degree or ` n ` -dimension.
142
+ Note that rank in TensorFlow is not the same as matrix rank
143
+ in mathematics. As the following table shows, each rank in
144
+ TensorFlow corresponds to a different mathematical entity:
106
145
107
146
| Rank | Math Entity |
108
147
| :-----| :---------------------------------|
@@ -112,50 +151,33 @@ each rank in TensorFlow corresponds to a different mathematical entity:
112
151
| 3 | 3-Tensor (cube of numbers) |
113
152
| n | n-Tensor (you get the idea) |
114
153
115
- For example:
116
- ``` tut:silent
117
- val t0 = Tensor.ones(INT32, Shape()) // Creates a scalar equal to the value 1
118
- val t1 = Tensor.ones(INT32, Shape(10)) // Creates a vector with 10 elements, all of which are equal to 1
119
- val t2 = Tensor.ones(INT32, Shape(5, 2)) // Creates a matrix with 5 rows with 2 columns
120
-
121
- // You can also create tensors in the following way:
122
- val t3 = Tensor(2.0, 5.6) // Creates a vector that contains the numbers 2.0 and 5.6
123
- val t4 = Tensor(Tensor(1.2f, -8.4f), Tensor(-2.3f, 0.4f)) // Creates a matrix with 2 rows and 2 columns
124
- ```
125
-
126
- A rank of a tensor can be obtained in one of two ways:
127
- ``` tut:silent
128
- t4.rank // Returns the value 2
129
- tfi.rank(t4) // Also returns the value 2
130
- ```
131
-
132
- ## Shape
154
+ The rank of a tensor can be inspected using:
133
155
156
+ @@snip [ Tensors.scala] ( /docs/src/main/scala/Tensors.scala ) { #tensor_inspect_rank_example }
134
157
135
158
## Indexing / Slicing
136
159
137
- Similar to NumPy, tensors can be indexed/sliced in various ways:
160
+ Similar to NumPy, tensors can be indexed/sliced in various
161
+ ways. An indexer can be one of:
138
162
139
- An indexer can be one of:
140
- - ` Ellipsis ` : Corresponds to a full slice over multiple dimensions of a tensor. Ellipses are used to represent
141
- zero or more dimensions of a full-dimension indexer sequence.
142
- - ` NewAxis ` : Corresponds to the addition of a new dimension.
143
- - ` Slice ` : Corresponds to a slice over a single dimension of a tensor.
163
+ - ` Ellipsis ` : Full slice over multiple dimensions of a
164
+ tensor. Ellipses are used to represent zero or more
165
+ dimensions of a full-dimension indexer sequence.
166
+ - ` NewAxis ` : Addition of a new dimension.
167
+ - ` Slice ` : Slice over a single dimension of a tensor.
144
168
145
- Examples of constructing and using indexers are provided in the ` Ellipsis ` and the ` Slice ` class documentation.
146
- Here we provide examples of indexing over tensors using indexers:
169
+ Examples of constructing and using indexers are provided in
170
+ the @scaladoc [ Ellipsis] ( org.platanios.tensorflow.api.core.Ellipsis )
171
+ and the @scaladoc [ Slice] ( org.platanios.tensorflow.api.core.Slice )
172
+ documentation. Here we provide examples of indexing over
173
+ tensors using indexers:
147
174
148
- ``` scala
149
- val t = Tensor .zeros[Float ](Shape (4 , 2 , 3 , 8 ))
150
- t(:: , :: , 1 , :: ) // Tensor with shape [4, 2, 1, 8]
151
- t(1 :: - 2 , --- , 2 ) // Tensor with shape [1, 2, 3, 1]
152
- t(--- ) // Tensor with shape [4, 2, 3, 8]
153
- t(1 :: - 2 , --- , NewAxis , 2 ) // Tensor with shape [1, 2, 3, 1, 1]
154
- t(1 :: , --- , NewAxis , 2 ) // Tensor with shape [3, 2, 3, 1, 1]
155
- ```
175
+ @@snip [ Tensors.scala] ( /docs/src/main/scala/Tensors.scala ) { #tensor_indexer_examples }
156
176
157
177
where ` --- ` corresponds to an ellipsis.
158
178
159
- Note that each indexing sequence is only allowed to contain at most one Ellipsis. Furthermore, if an ellipsis is not
160
- provided, then one is implicitly appended at the end of indexing sequence. For example, ` foo(2 :: 4) ` is equivalent to
161
- ` foo(2 :: 4, ---) ` .
179
+ Note that each indexing sequence is only allowed to contain
180
+ at most one ellipsis. Furthermore, if an ellipsis is not
181
+ provided, then one is implicitly appended at the end of the
182
+ indexing sequence. For example, ` foo(2 :: 4) ` is equivalent
183
+ to ` foo(2 :: 4, ---) ` .
0 commit comments