ocnn 2.2.7__py3-none-any.whl → 2.2.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ocnn/nn/octree_align.py CHANGED
@@ -1,46 +1,46 @@
1
- # --------------------------------------------------------
2
- # Octree-based Sparse Convolutional Neural Networks
3
- # Copyright (c) 2022 Peng-Shuai Wang <wangps@hotmail.com>
4
- # Licensed under The MIT License [see LICENSE for details]
5
- # Written by Peng-Shuai Wang
6
- # --------------------------------------------------------
7
-
8
- import torch
9
-
10
- from ocnn.octree import Octree
11
-
12
-
13
- def search_value(value: torch.Tensor, key: torch.Tensor, query: torch.Tensor):
14
- r''' Searches values according to sorted shuffled keys.
15
-
16
- Args:
17
- value (torch.Tensor): The input tensor with shape (N, C).
18
- key (torch.Tensor): The key tensor corresponds to :attr:`value` with shape
19
- (N,), which contains sorted shuffled keys of an octree.
20
- query (torch.Tensor): The query tensor, which also contains shuffled keys.
21
- '''
22
-
23
- # deal with out-of-bound queries, the indices of these queries
24
- # returned by torch.searchsorted equal to `key.shape[0]`
25
- out_of_bound = query > key[-1]
26
-
27
- # search
28
- idx = torch.searchsorted(key, query)
29
- idx[out_of_bound] = -1 # to avoid overflow when executing the following line
30
- found = key[idx] == query
31
-
32
- # assign the found value to the output
33
- out = torch.zeros(query.shape[0], value.shape[1], device=value.device)
34
- out[found] = value[idx[found]]
35
- return out
36
-
37
-
38
- def octree_align(value: torch.Tensor, octree: Octree, octree_query: Octree,
39
- depth: int, nempty: bool = False):
40
- r''' Wraps :func:`octree_align` to take octrees as input for convenience.
41
- '''
42
-
43
- key = octree.key(depth, nempty)
44
- query = octree_query.key(depth, nempty)
45
- assert key.shape[0] == value.shape[0]
46
- return search_value(value, key, query)
1
+ # --------------------------------------------------------
2
+ # Octree-based Sparse Convolutional Neural Networks
3
+ # Copyright (c) 2022 Peng-Shuai Wang <wangps@hotmail.com>
4
+ # Licensed under The MIT License [see LICENSE for details]
5
+ # Written by Peng-Shuai Wang
6
+ # --------------------------------------------------------
7
+
8
+ import torch
9
+
10
+ from ocnn.octree import Octree
11
+
12
+
13
+ def search_value(value: torch.Tensor, key: torch.Tensor, query: torch.Tensor):
14
+ r''' Searches values according to sorted shuffled keys.
15
+
16
+ Args:
17
+ value (torch.Tensor): The input tensor with shape (N, C).
18
+ key (torch.Tensor): The key tensor corresponds to :attr:`value` with shape
19
+ (N,), which contains sorted shuffled keys of an octree.
20
+ query (torch.Tensor): The query tensor, which also contains shuffled keys.
21
+ '''
22
+
23
+ # deal with out-of-bound queries, the indices of these queries
24
+ # returned by torch.searchsorted equal to `key.shape[0]`
25
+ out_of_bound = query > key[-1]
26
+
27
+ # search
28
+ idx = torch.searchsorted(key, query)
29
+ idx[out_of_bound] = -1 # to avoid overflow when executing the following line
30
+ found = key[idx] == query
31
+
32
+ # assign the found value to the output
33
+ out = torch.zeros(query.shape[0], value.shape[1], device=value.device)
34
+ out[found] = value[idx[found]]
35
+ return out
36
+
37
+
38
+ def octree_align(value: torch.Tensor, octree: Octree, octree_query: Octree,
39
+ depth: int, nempty: bool = False):
40
+ r''' Wraps :func:`octree_align` to take octrees as input for convenience.
41
+ '''
42
+
43
+ key = octree.key(depth, nempty)
44
+ query = octree_query.key(depth, nempty)
45
+ assert key.shape[0] == value.shape[0]
46
+ return search_value(value, key, query)