Skip to content

Commit

Permalink
Merge branch 'master' of github.com:torch/torch7
Browse files Browse the repository at this point in the history
  • Loading branch information
andresy committed Apr 16, 2014
2 parents a28a1b0 + afbc6cd commit ccd3950
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
12 changes: 8 additions & 4 deletions doc/maths.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<a name="torch.maths.dok"/>
# Math Functions #

Expand Down Expand Up @@ -803,9 +802,14 @@ might be handy, they create and return a new tensor containing the
results. They are thus not as fast as the operations available in the
[previous section](#torch.Tensor.BasicOperations.dok).

### Addition and substraction ###
Another important point to note is that these operators are only overloaded when the first operand is a tensor. For example, this will NOT work:
```
> x = 5 + torch.rand(3)
```

### Addition and subtraction ###

You can add a tensor to another one with the `+` operator. Substraction is done with `-`.
You can add a tensor to another one with the `+` operator. Subtraction is done with `-`.
The number of elements in the tensors must match, but the sizes do not matter. The size
of the returned tensor will be the size of the first tensor.
```
Expand All @@ -826,7 +830,7 @@ of the returned tensor will be the size of the first tensor.
[torch.Tensor of dimension 4]
```

A scalar might also be added or substracted to a tensor. The scalar might be on the right or left of the operator.
A scalar might also be added or subtracted to a tensor. The scalar might be on the right or left of the operator.
```
> x = torch.Tensor(2,2):fill(2)
> = x+3
Expand Down
48 changes: 47 additions & 1 deletion doc/tensor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ t7> =x

```

## Expanding/Replicating Tensors ##
## Expanding/Replicating/Squeezing Tensors ##

These methods returns a `Tensor` which is created by replications of the
original tensor.
Expand Down Expand Up @@ -1437,8 +1437,54 @@ t7> return torch.repeatTensor(x,3,2,1)
[torch.DoubleTensor of dimension 3x2x5]

```

<a name="torch.Tensor.squeeze"/>
#### [Tensor] squeeze([dim]) ####

Removes all singleton dimensions of the tensor.
If `dim` is given, squeezes only that particular dimension of the tensor.

```lua
t7> x=torch.rand(2,1,2,1,2)
t7> =x
(1,1,1,.,.) =
0.6020 0.8897

(2,1,1,.,.) =
0.4713 0.2645

(1,1,2,.,.) =
0.4441 0.9792

(2,1,2,.,.) =
0.5467 0.8648
[torch.DoubleTensor of dimension 2x1x2x1x2]

t7> =torch.squeeze(x)
(1,.,.) =
0.6020 0.8897
0.4441 0.9792

(2,.,.) =
0.4713 0.2645
0.5467 0.8648
[torch.DoubleTensor of dimension 2x2x2]

t7> =torch.squeeze(x, 2)
(1,1,.,.) =
0.6020 0.8897

(2,1,.,.) =
0.4713 0.2645

(1,2,.,.) =
0.4441 0.9792

(2,2,.,.) =
0.5467 0.8648
[torch.DoubleTensor of dimension 2x2x1x2]

```

## Manipulating the tensor view ##

Expand Down
1 change: 1 addition & 0 deletions lib/TH/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ SET(TH_INLINE "")
ENDIF(NOT DEFINED C_INLINE)

# Is __thread supported?
INCLUDE (CheckCSourceCompiles)
CHECK_C_SOURCE_COMPILES("static __thread int x = 1; int main() { return x; }" C_HAS_THREAD)
IF(NOT DEFINED C_HAS_THREAD)
MESSAGE(STATUS "Warning: __thread is not supported, generating thread-unsafe code")
Expand Down
4 changes: 2 additions & 2 deletions lib/TH/THDiskFile.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,11 @@ READ_WRITE_METHODS(long, Long,

READ_WRITE_METHODS(float, Float,
int ret = fscanf(dfself->handle, "%g", &data[i]); if(ret <= 0) break; else nread++,
int ret = fprintf(dfself->handle, "%g", data[i]); if(ret <= 0) break; else nwrite++)
int ret = fprintf(dfself->handle, "%.9g", data[i]); if(ret <= 0) break; else nwrite++)

READ_WRITE_METHODS(double, Double,
int ret = fscanf(dfself->handle, "%lg", &data[i]); if(ret <= 0) break; else nread++,
int ret = fprintf(dfself->handle, "%lg", data[i]); if(ret <= 0) break; else nwrite++)
int ret = fprintf(dfself->handle, "%.17g", data[i]); if(ret <= 0) break; else nwrite++)

static long THDiskFile_readString(THFile *self, const char *format, char **str_)
{
Expand Down

0 comments on commit ccd3950

Please sign in to comment.