From 8c61f67e3453249f02b40ef82ea8ad97781cc395 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 11 Apr 2020 18:14:15 +0200 Subject: [PATCH] cleaning --- python/damask/_rotation.py | 10 +++++----- python/tests/test_Rotation.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/python/damask/_rotation.py b/python/damask/_rotation.py index e728ab6ed..4c164376c 100644 --- a/python/damask/_rotation.py +++ b/python/damask/_rotation.py @@ -517,7 +517,7 @@ class Rotation: if len(qu.shape) == 1: if np.abs(np.sum(qu[1:4]**2)) < 1.e-6: # set axis to [001] if the angle is 0/360 ax = np.array([ 0.0, 0.0, 1.0, 0.0 ]) - elif np.abs(qu[0]) > 1.e-6: + elif qu[0] > 1.e-6: s = np.sign(qu[0])/np.sqrt(qu[1]**2+qu[2]**2+qu[3]**2) omega = 2.0 * np.arccos(np.clip(qu[0],-1.0,1.0)) ax = ax = np.array([ qu[1]*s, qu[2]*s, qu[3]*s, omega ]) @@ -527,10 +527,10 @@ class Rotation: with np.errstate(invalid='ignore',divide='ignore'): s = np.sign(qu[...,0:1])/np.sqrt(qu[...,1:2]**2+qu[...,2:3]**2+qu[...,3:4]**2) omega = 2.0 * np.arccos(np.clip(qu[...,0:1],-1.0,1.0)) - ax = np.where(np.sum(np.abs(qu[:,1:4])**2,axis=-1,keepdims=True) < 1.0e-6, - [0.0, 0.0, 1.0, 0.0], np.block([qu[...,1:4]*s,omega])) - ax = np.where(qu[...,0:1] < 1.0e-6, - np.block([qu[...,1:4],np.ones(qu.shape[:-1]+(1,))*np.pi]),ax) # TODO: Where not needed + ax = np.where(np.broadcast_to(qu[...,0:1] < 1.0e-6,qu.shape), + np.block([qu[...,1:4],np.ones(qu.shape[:-1]+(1,))*np.pi]), + np.block([qu[...,1:4]*s,omega])) + ax[np.sum(np.abs(qu[...,1:4])**2,axis=-1) < 1.0e-6,] = [0.0, 0.0, 1.0, 0.0] return ax @staticmethod diff --git a/python/tests/test_Rotation.py b/python/tests/test_Rotation.py index 2ac819f4c..0007a2aec 100644 --- a/python/tests/test_Rotation.py +++ b/python/tests/test_Rotation.py @@ -167,7 +167,7 @@ class TestRotation: conversion(qu.reshape(qu.shape[0]//2,-1,4)) co = conversion(qu) for q,c in zip(qu,co): - print(q,c) + #print(q,c) assert np.allclose(conversion(q),c) @pytest.mark.parametrize('conversion',[Rotation.om2qu,