aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorArun Isaac2021-03-10 17:21:32 +0530
committerArun Isaac2021-03-10 17:21:32 +0530
commitca09b0fbfe37f8cce391259bff6e2d2892127756 (patch)
tree891cb27a79842dd59645e47bfae5e4138f6a6e70 /contrib
parent6a0f16d7b2f1b9f441048ef8d81c10d6866e68ab (diff)
downloadnsmc-ca09b0fbfe37f8cce391259bff6e2d2892127756.tar.gz
nsmc-ca09b0fbfe37f8cce391259bff6e2d2892127756.tar.lz
nsmc-ca09b0fbfe37f8cce391259bff6e2d2892127756.zip
Do not concatenate numpy arrays.
* contrib/cone-vector.py: Import empty. Don't import concatenate. (random_vector_on_spherical_cap): Build random vector without concatenation.
Diffstat (limited to 'contrib')
-rw-r--r--contrib/cone-vector.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/contrib/cone-vector.py b/contrib/cone-vector.py
index 16d1dfa..6526817 100644
--- a/contrib/cone-vector.py
+++ b/contrib/cone-vector.py
@@ -16,7 +16,7 @@
# along with this program. If not, see
# <https://www.gnu.org/licenses/>.
-from numpy import arcsin, concatenate, cos, dot, ones, sin, sqrt, tan, pi
+from numpy import arcsin, cos, dot, empty, ones, sin, sqrt, tan, pi
from numpy.random import randn, random
from numpy.linalg import norm
from scipy.special import betainc, betaincinv, gamma
@@ -58,10 +58,11 @@ def rotate_from_nth_canonical (x, axis):
def random_vector_on_spherical_cap (axis, maximum_planar_angle):
dim = axis.size
maximum_solid_angle_fraction = planar_angle2solid_angle_fraction(maximum_planar_angle, dim)
- x = random_vector_on_sphere(dim - 1) \
+ x = empty(dim)
+ x[:-1] = random_vector_on_sphere(dim - 1) \
* cos(maximum_planar_angle) \
* tan(solid_angle_fraction2planar_angle(maximum_solid_angle_fraction*random(), dim))
- x = concatenate([x, [cos(maximum_planar_angle)]])
+ x[-1] = cos(maximum_planar_angle)
return rotate_from_nth_canonical(x / norm(x), axis)
# Sample code exercising the above functions