Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
torch-scatter
Commits
d536e0d3
Commit
d536e0d3
authored
Dec 15, 2018
by
rusty1s
Browse files
typo
parent
632a1783
Changes
16
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
380 additions
and
13 deletions
+380
-13
README.md
README.md
+1
-0
docs/source/_figures/build.sh
docs/source/_figures/build.sh
+1
-1
docs/source/_figures/std.svg
docs/source/_figures/std.svg
+295
-0
docs/source/_figures/std.tex
docs/source/_figures/std.tex
+8
-0
docs/source/functions/std.rst
docs/source/functions/std.rst
+6
-0
setup.py
setup.py
+2
-3
test/test_std.py
test/test_std.py
+19
-0
torch_scatter/__init__.py
torch_scatter/__init__.py
+1
-1
torch_scatter/add.py
torch_scatter/add.py
+1
-1
torch_scatter/div.py
torch_scatter/div.py
+1
-1
torch_scatter/max.py
torch_scatter/max.py
+1
-1
torch_scatter/mean.py
torch_scatter/mean.py
+1
-1
torch_scatter/min.py
torch_scatter/min.py
+1
-1
torch_scatter/mul.py
torch_scatter/mul.py
+1
-1
torch_scatter/std.py
torch_scatter/std.py
+40
-1
torch_scatter/sub.py
torch_scatter/sub.py
+1
-1
No files found.
README.md
View file @
d536e0d3
...
@@ -28,6 +28,7 @@ The package consists of the following operations:
...
@@ -28,6 +28,7 @@ The package consists of the following operations:
*
[
**Scatter Mul**
](
https://rusty1s.github.io/pytorch_scatter/build/html/functions/mul.html
)
*
[
**Scatter Mul**
](
https://rusty1s.github.io/pytorch_scatter/build/html/functions/mul.html
)
*
[
**Scatter Div**
](
https://rusty1s.github.io/pytorch_scatter/build/html/functions/div.html
)
*
[
**Scatter Div**
](
https://rusty1s.github.io/pytorch_scatter/build/html/functions/div.html
)
*
[
**Scatter Mean**
](
https://rusty1s.github.io/pytorch_scatter/build/html/functions/mean.html
)
*
[
**Scatter Mean**
](
https://rusty1s.github.io/pytorch_scatter/build/html/functions/mean.html
)
*
[
**Scatter Std**
](
https://rusty1s.github.io/pytorch_scatter/build/html/functions/std.html
)
*
[
**Scatter Min**
](
https://rusty1s.github.io/pytorch_scatter/build/html/functions/min.html
)
*
[
**Scatter Min**
](
https://rusty1s.github.io/pytorch_scatter/build/html/functions/min.html
)
*
[
**Scatter Max**
](
https://rusty1s.github.io/pytorch_scatter/build/html/functions/max.html
)
*
[
**Scatter Max**
](
https://rusty1s.github.io/pytorch_scatter/build/html/functions/max.html
)
...
...
docs/source/_figures/build.sh
View file @
d536e0d3
#!/bin/bash
#!/bin/bash
files
=(
add sub mul div mean max min
)
files
=(
add sub mul div mean max min
std
)
for
name
in
"
${
files
[@]
}
"
;
do
for
name
in
"
${
files
[@]
}
"
;
do
pdflatex
"
$name
"
pdflatex
"
$name
"
...
...
docs/source/_figures/std.svg
0 → 100644
View file @
d536e0d3
This diff is collapsed.
Click to expand it.
docs/source/_figures/std.tex
0 → 100644
View file @
d536e0d3
\def\indices
{{
0, 0, 1, 0, 2, 2, 3, 3
}}
\def\inputs
{{
5, 1, 7, 2, 3, 2, 1, 3
}}
\def\outputs
{{
2.1, 0, 0.7, 1.4
}}
\def\colors
{{
"cyan", "orange", "olive", "magenta"
}}
\def\numberInputs
{
7
}
\def\numberOutputs
{
3
}
\def\operation
{
std
}
\input
{
template
}
docs/source/functions/std.rst
0 → 100644
View file @
d536e0d3
Scatter Std
===========
.. automodule:: torch_scatter
.. autofunction:: scatter_std
setup.py
View file @
d536e0d3
...
@@ -15,7 +15,7 @@ if CUDA_HOME is not None:
...
@@ -15,7 +15,7 @@ if CUDA_HOME is not None:
[
'cuda/scatter.cpp'
,
'cuda/scatter_kernel.cu'
])
[
'cuda/scatter.cpp'
,
'cuda/scatter_kernel.cu'
])
]
]
__version__
=
'1.
0.5
'
__version__
=
'1.
1.0
'
url
=
'https://github.com/rusty1s/pytorch_scatter'
url
=
'https://github.com/rusty1s/pytorch_scatter'
install_requires
=
[]
install_requires
=
[]
...
@@ -36,5 +36,4 @@ setup(
...
@@ -36,5 +36,4 @@ setup(
tests_require
=
tests_require
,
tests_require
=
tests_require
,
ext_modules
=
ext_modules
,
ext_modules
=
ext_modules
,
cmdclass
=
cmdclass
,
cmdclass
=
cmdclass
,
packages
=
find_packages
(),
packages
=
find_packages
(),
)
)
test/test_std.py
0 → 100644
View file @
d536e0d3
from
itertools
import
product
import
pytest
import
torch
from
torch_scatter
import
scatter_std
from
.utils
import
grad_dtypes
as
dtypes
,
devices
,
tensor
biass
=
[
True
,
False
]
@
pytest
.
mark
.
parametrize
(
'dtype,device,bias'
,
product
(
dtypes
,
devices
,
biass
))
def
test_std
(
dtype
,
device
,
bias
):
src
=
tensor
([[
2
,
0
,
1
,
4
,
3
],
[
0
,
2
,
1
,
3
,
4
]],
dtype
,
device
)
index
=
tensor
([[
0
,
0
,
0
,
0
,
0
],
[
1
,
1
,
1
,
1
,
1
]],
torch
.
long
,
device
)
out
=
scatter_std
(
src
,
index
,
dim
=-
1
,
unbiased
=
bias
)
expected
=
src
.
std
(
dim
=-
1
,
unbiased
=
bias
)
assert
out
.
tolist
()
==
[[
expected
[
0
].
item
(),
0
],
[
0
,
expected
[
0
].
item
()]]
torch_scatter/__init__.py
View file @
d536e0d3
...
@@ -7,7 +7,7 @@ from .std import scatter_std
...
@@ -7,7 +7,7 @@ from .std import scatter_std
from
.max
import
scatter_max
from
.max
import
scatter_max
from
.min
import
scatter_min
from
.min
import
scatter_min
__version__
=
'1.
0.5
'
__version__
=
'1.
1.0
'
__all__
=
[
__all__
=
[
'scatter_add'
,
'scatter_add'
,
...
...
torch_scatter/add.py
View file @
d536e0d3
...
@@ -13,7 +13,7 @@ def scatter_add(src, index, dim=-1, out=None, dim_size=None, fill_value=0):
...
@@ -13,7 +13,7 @@ def scatter_add(src, index, dim=-1, out=None, dim_size=None, fill_value=0):
|
|
Sums all values from the :attr:`src` tensor into :attr:`out` at the indices
Sums all values from the :attr:`src` tensor into :attr:`out` at the indices
specified in the :attr:`index` tensor along a
n
given axis :attr:`dim`. For
specified in the :attr:`index` tensor along a given axis :attr:`dim`. For
each value in :attr:`src`, its output index is specified by its index in
each value in :attr:`src`, its output index is specified by its index in
:attr:`input` for dimensions outside of :attr:`dim` and by the
:attr:`input` for dimensions outside of :attr:`dim` and by the
corresponding value in :attr:`index` for dimension :attr:`dim`. If
corresponding value in :attr:`index` for dimension :attr:`dim`. If
...
...
torch_scatter/div.py
View file @
d536e0d3
...
@@ -39,7 +39,7 @@ def scatter_div(src, index, dim=-1, out=None, dim_size=None, fill_value=1):
...
@@ -39,7 +39,7 @@ def scatter_div(src, index, dim=-1, out=None, dim_size=None, fill_value=1):
|
|
Divides all values from the :attr:`src` tensor into :attr:`out` at the
Divides all values from the :attr:`src` tensor into :attr:`out` at the
indices specified in the :attr:`index` tensor along a
n
given axis
indices specified in the :attr:`index` tensor along a given axis
:attr:`dim`.If multiple indices reference the same location, their
:attr:`dim`.If multiple indices reference the same location, their
**contributions divide** (`cf.` :meth:`~torch_scatter.scatter_add`).
**contributions divide** (`cf.` :meth:`~torch_scatter.scatter_add`).
...
...
torch_scatter/max.py
View file @
d536e0d3
...
@@ -42,7 +42,7 @@ def scatter_max(src, index, dim=-1, out=None, dim_size=None, fill_value=0):
...
@@ -42,7 +42,7 @@ def scatter_max(src, index, dim=-1, out=None, dim_size=None, fill_value=0):
|
|
Maximizes all values from the :attr:`src` tensor into :attr:`out` at the
Maximizes all values from the :attr:`src` tensor into :attr:`out` at the
indices specified in the :attr:`index` tensor along a
n
given axis
indices specified in the :attr:`index` tensor along a given axis
:attr:`dim`.If multiple indices reference the same location, their
:attr:`dim`.If multiple indices reference the same location, their
**contributions maximize** (`cf.` :meth:`~torch_scatter.scatter_add`).
**contributions maximize** (`cf.` :meth:`~torch_scatter.scatter_add`).
The second return tensor contains index location in :attr:`src` of each
The second return tensor contains index location in :attr:`src` of each
...
...
torch_scatter/mean.py
View file @
d536e0d3
...
@@ -15,7 +15,7 @@ def scatter_mean(src, index, dim=-1, out=None, dim_size=None, fill_value=0):
...
@@ -15,7 +15,7 @@ def scatter_mean(src, index, dim=-1, out=None, dim_size=None, fill_value=0):
|
|
Averages all values from the :attr:`src` tensor into :attr:`out` at the
Averages all values from the :attr:`src` tensor into :attr:`out` at the
indices specified in the :attr:`index` tensor along a
n
given axis
indices specified in the :attr:`index` tensor along a given axis
:attr:`dim`.If multiple indices reference the same location, their
:attr:`dim`.If multiple indices reference the same location, their
**contributions average** (`cf.` :meth:`~torch_scatter.scatter_add`).
**contributions average** (`cf.` :meth:`~torch_scatter.scatter_add`).
...
...
torch_scatter/min.py
View file @
d536e0d3
...
@@ -42,7 +42,7 @@ def scatter_min(src, index, dim=-1, out=None, dim_size=None, fill_value=0):
...
@@ -42,7 +42,7 @@ def scatter_min(src, index, dim=-1, out=None, dim_size=None, fill_value=0):
|
|
Minimizes all values from the :attr:`src` tensor into :attr:`out` at the
Minimizes all values from the :attr:`src` tensor into :attr:`out` at the
indices specified in the :attr:`index` tensor along a
n
given axis
indices specified in the :attr:`index` tensor along a given axis
:attr:`dim`.If multiple indices reference the same location, their
:attr:`dim`.If multiple indices reference the same location, their
**contributions maximize** (`cf.` :meth:`~torch_scatter.scatter_add`).
**contributions maximize** (`cf.` :meth:`~torch_scatter.scatter_add`).
The second return tensor contains index location in :attr:`src` of each
The second return tensor contains index location in :attr:`src` of each
...
...
torch_scatter/mul.py
View file @
d536e0d3
...
@@ -39,7 +39,7 @@ def scatter_mul(src, index, dim=-1, out=None, dim_size=None, fill_value=1):
...
@@ -39,7 +39,7 @@ def scatter_mul(src, index, dim=-1, out=None, dim_size=None, fill_value=1):
|
|
Multiplies all values from the :attr:`src` tensor into :attr:`out` at the
Multiplies all values from the :attr:`src` tensor into :attr:`out` at the
indices specified in the :attr:`index` tensor along a
n
given axis
indices specified in the :attr:`index` tensor along a given axis
:attr:`dim`.If multiple indices reference the same location, their
:attr:`dim`.If multiple indices reference the same location, their
**contributions multiply** (`cf.` :meth:`~torch_scatter.scatter_add`).
**contributions multiply** (`cf.` :meth:`~torch_scatter.scatter_add`).
...
...
torch_scatter/std.py
View file @
d536e0d3
...
@@ -5,6 +5,45 @@ from torch_scatter.utils.gen import gen
...
@@ -5,6 +5,45 @@ from torch_scatter.utils.gen import gen
def
scatter_std
(
src
,
index
,
dim
=-
1
,
out
=
None
,
dim_size
=
None
,
unbiased
=
True
):
def
scatter_std
(
src
,
index
,
dim
=-
1
,
out
=
None
,
dim_size
=
None
,
unbiased
=
True
):
r
"""
|
.. image:: https://raw.githubusercontent.com/rusty1s/pytorch_scatter/
master/docs/source/_figures/std.svg?sanitize=true
:align: center
:width: 400px
|
Computes the standard-deviation from all values from the :attr:`src` tensor
into :attr:`out` at the indices specified in the :attr:`index` tensor along
a given axis :attr:`dim` (`cf.` :meth:`~torch_scatter.scatter_add`).
For one-dimensional tensors, the operation computes
.. math::
\mathrm{out}_i = \sqrt{\frac{\sum_j {\left( x_j - \overline{x}_i
\right)}^2}{N_i - 1}}
where :math:`\sum_j` is over :math:`j` such that
:math:`\mathrm{index}_j = i`. :math:`N_i` and :math:`\overline{x}_i`
indicate the number of indices referencing :math:`i` and their mean value,
respectively.
Args:
src (Tensor): The source tensor.
index (LongTensor): The indices of elements to scatter.
dim (int, optional): The axis along which to index.
(default: :obj:`-1`)
out (Tensor, optional): The destination tensor. (default: :obj:`None`)
dim_size (int, optional): If :attr:`out` is not given, automatically
create output with size :attr:`dim_size` at dimension :attr:`dim`.
If :attr:`dim_size` is not given, a minimal sized output tensor is
returned. (default: :obj:`None`)
unbiased (bool, optional): If set to :obj:`False`, then the standard-
deviation will be calculated via the biased estimator.
(default: :obj:`True`)
"""
src
,
out
,
index
,
dim
=
gen
(
src
,
index
,
dim
,
out
,
dim_size
,
fill_value
=
0
)
src
,
out
,
index
,
dim
=
gen
(
src
,
index
,
dim
,
out
,
dim_size
,
fill_value
=
0
)
tmp
=
scatter_add
(
src
,
index
,
dim
,
None
,
dim_size
)
tmp
=
scatter_add
(
src
,
index
,
dim
,
None
,
dim_size
)
...
@@ -15,6 +54,6 @@ def scatter_std(src, index, dim=-1, out=None, dim_size=None, unbiased=True):
...
@@ -15,6 +54,6 @@ def scatter_std(src, index, dim=-1, out=None, dim_size=None, unbiased=True):
var
=
var
*
var
var
=
var
*
var
out
=
scatter_add
(
var
,
index
,
dim
,
out
,
dim_size
)
out
=
scatter_add
(
var
,
index
,
dim
,
out
,
dim_size
)
out
=
out
/
(
count
-
1
if
unbiased
else
count
).
clamp
(
min
=
1
)
out
=
out
/
(
count
-
1
if
unbiased
else
count
).
clamp
(
min
=
1
)
out
=
torch
.
sqrt
(
out
.
clamp
(
min
=
1e-12
)
)
out
=
torch
.
sqrt
(
out
)
return
out
return
out
torch_scatter/sub.py
View file @
d536e0d3
...
@@ -13,7 +13,7 @@ def scatter_sub(src, index, dim=-1, out=None, dim_size=None, fill_value=0):
...
@@ -13,7 +13,7 @@ def scatter_sub(src, index, dim=-1, out=None, dim_size=None, fill_value=0):
|
|
Subtracts all values from the :attr:`src` tensor into :attr:`out` at the
Subtracts all values from the :attr:`src` tensor into :attr:`out` at the
indices specified in the :attr:`index` tensor along a
n
given axis
indices specified in the :attr:`index` tensor along a given axis
:attr:`dim`.If multiple indices reference the same location, their
:attr:`dim`.If multiple indices reference the same location, their
**negated contributions add** (`cf.` :meth:`~torch_scatter.scatter_add`).
**negated contributions add** (`cf.` :meth:`~torch_scatter.scatter_add`).
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment