How to use the clifford.MultiVector function in clifford

To help you get started, we’ve selected a few clifford examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pygae / clifford / test / test_clifford.py View on Github external
0.04310366054166925,  1.3970365638677635 , -1.545423393858595  ,
                1.7790215501876614 ,  0.4785341530609175 , -1.32279679741638   ,
                0.5874769077573831 , -1.0227287710873676 ,  1.779673249468527  ,
               -1.5415648119743852 ])

        valAinv= np.array([ 0.06673424072253006 , -0.005709960252678998,
               -0.10758540037163118 ,  0.1805895938775471  ,
                0.13919236400967427 ,  0.04123255613093294 ,
               -0.015395162562329407, -0.1388977308136247  ,
               -0.1462160646855434  , -0.1183453106997158  ,
               -0.06961956152268277 ,  0.1396713851886765  ,
               -0.02572904638749348 ,  0.02079613649197489 ,
               -0.06933660606043765 , -0.05436077710009021 ])
        
        A = MultiVector(layout=layout,value=valA)
        Ainv = MultiVector(layout=layout,value=valAinv)
        

        np.testing.assert_almost_equal(A.inv().value, Ainv.value)
github pygae / clifford / test_CUDA.py View on Github external
mv_d_array = np.zeros(mv_b_array.shape, dtype=np.double)

            print('Starting kernel')
            t = time.time()
            blockdim = 64
            griddim = int(math.ceil(n_mvs / blockdim))
            rotor_between_objects_kernel[griddim, blockdim](mv_a_array, mv_b_array, mv_c_array)
            end_time = time.time() - t
            print('Kernel finished')
            print(end_time)

            # Now do the non cuda kernel
            t = time.time()
            for i in range(mv_a_array.shape[0]):
                mv_a = cf.MultiVector(self.layout, mv_a_array[i, :])
                mv_b = cf.MultiVector(self.layout, mv_b_array[i, :])
                mv_d_array[i, :] = rotor_between_objects(mv_a, mv_b).value
            print(time.time() - t)

            np.testing.assert_almost_equal(mv_c_array, mv_d_array)
github pygae / clifford / test / test_clifford.py View on Github external
-0.                 , -0.                 , -1.9546896043012914 ,
                0.7069828848351363 , -0.22839793693302957,  1.0226966962560002 ,
                1.8673816483342143 , -1.7694566455296474 , -0.                 ,
               -0.                 ,  0.                 , -0.                 ,
               -0.                 ])
        valexpB = np.array([-0.8154675764311629  ,  0.                  ,
                0.                  ,  0.                  ,
                0.                  ,  0.3393508714682218  ,
                0.22959588097548828 , -0.1331099867581965  ,
               -0.01536404898029994 ,  0.012688721722814184,
                0.35678394795928464 ,  0.                  ,
                0.                  ,  0.                  ,
                0.                  , -0.14740840378445502 ])

        
        B = MultiVector(layout=layout,value=valB)
        expB =MultiVector(layout=layout,value=valexpB)
        np.testing.assert_almost_equal(exp(B).value,expB.value)
github pygae / clifford / test_CUDA.py View on Github external
mv_c_array = np.zeros(mv_b_array.shape, dtype=np.double)
            mv_d_array = np.zeros(mv_b_array.shape, dtype=np.double)

            print('Starting kernel')
            t = time.time()
            blockdim = 64
            griddim = int(math.ceil(n_mvs / blockdim))
            rotor_between_objects_kernel[griddim, blockdim](mv_a_array, mv_b_array, mv_c_array)
            end_time = time.time() - t
            print('Kernel finished')
            print(end_time)

            # Now do the non cuda kernel
            t = time.time()
            for i in range(mv_a_array.shape[0]):
                mv_a = cf.MultiVector(self.layout, mv_a_array[i, :])
                mv_b = cf.MultiVector(self.layout, mv_b_array[i, :])
                mv_d_array[i, :] = rotor_between_objects(mv_a, mv_b).value
            print(time.time() - t)

            np.testing.assert_almost_equal(mv_c_array, mv_d_array)
github pygae / clifford / test / test_clifford.py View on Github external
0.7069828848351363 , -0.22839793693302957,  1.0226966962560002 ,
                1.8673816483342143 , -1.7694566455296474 , -0.                 ,
               -0.                 ,  0.                 , -0.                 ,
               -0.                 ])
        valexpB = np.array([-0.8154675764311629  ,  0.                  ,
                0.                  ,  0.                  ,
                0.                  ,  0.3393508714682218  ,
                0.22959588097548828 , -0.1331099867581965  ,
               -0.01536404898029994 ,  0.012688721722814184,
                0.35678394795928464 ,  0.                  ,
                0.                  ,  0.                  ,
                0.                  , -0.14740840378445502 ])

        
        B = MultiVector(layout=layout,value=valB)
        expB =MultiVector(layout=layout,value=valexpB)
        np.testing.assert_almost_equal(exp(B).value,expB.value)
github pygae / clifford / clifford / _layout.py View on Github external
def parse_multivector(self, mv_string: str) -> 'cf.MultiVector':
        """ Parses a multivector string into a MultiVector object """
        # Get the names of the canonical blades
        blade_name_index_map = {name: index for index, name in enumerate(self.names)}

        # Clean up the input string a bit
        cleaned_string = re.sub('[()]', '', mv_string)

        # Create a multivector
        mv_out = cf.MultiVector(self)

        # Apply the regex
        for m in _blade_pattern.finditer(cleaned_string):
            # Clean up the search result
            cleaned_match = m.group(0)

            # Split on the '^'
            stuff = cleaned_match.split('^')

            if len(stuff) == 2:
                # Extract the value of the blade and the index of the blade
                blade_val = float("".join(stuff[0].split()))
                blade_index = blade_name_index_map[stuff[1].strip()]
                mv_out[blade_index] = blade_val
            elif len(stuff) == 1:
                # Extract the value of the scalar
github pygae / clifford / clifford / tools / g3 / __init__.py View on Github external
def rotor_vector_to_vector(v1, v2):
    """ Creates a rotor that takes one vector into another """
    if np.sum(np.abs(v1.value - v2.value)) > 0.000001:
        theta = angle_between_vectors(v1, v2)
        return generate_rotation_rotor(theta, v1, v2)
    else:
        mv = cf.MultiVector(layout)
        mv.value[0] = 1.0
        return mv
github pygae / clifford / clifford / _layout.py View on Github external
def MultiVector(self, *args, **kw):
        '''
        create a multivector in this layout

        convenience func to Multivector(layout)
        '''
        return cf.MultiVector(layout=self, *args, **kw)
github pygae / clifford / clifford / cga.py View on Github external
def __init__(self, cga, *args) -> None:
        super().__init__(cga)
        self.einf = self.cga.einf  # we use this alot

        if len(args) == 0:
            # generate random highest dimension flat
            nulls = [self.cga.null_vector() for k in range(self.layout.dims-2)]
            self.mv = reduce(op, nulls + [self.einf])

        elif len(args) == 1:
            # from existing multivector
            if isinstance(args[0], MultiVector):
                self.mv = args[0]

            # generate random flat  for given  dimension
            elif isinstance(args[0], int):
                dim = args[0]
                points = [self.cga.base_vector() for k in range(dim+1)]
                points = list(map(self.cga.up, points))
                self.mv = reduce(op, points + [self.einf])

        # from vectors on flat
        else:
            nulls = map(self.cga.null_vector, args)
            if self.einf not in nulls:
                nulls = list(nulls)+[self.einf]

            self.mv = reduce(op, nulls)