예제 #1
0
파일: io_util.py 프로젝트: zepto/musio
def _build_mod_list(mod_path: list, suffix: str, blacklist: list) -> list:
    """ _build_mod_list(mod_path, suffix) -> Add all the paths in mod_path to
    sys.path and return a list of all modules in sys.path ending in suffix.

    """

    from sys import path as sys_path

    mod_path = [mod_path] if type(mod_path) is str else mod_path
    blacklist = [blacklist] if type(blacklist) is str else blacklist

    # Add suffix to all names in blacklist.
    blacklist.extend(["%s%s" % (name, suffix) for name in blacklist if not name.endswith(suffix)])

    # Add the path of this file to the search path.
    mod_path.append(os_abspath(os_dirname(__file__)))

    # Add the path(s) in mod_path to sys.path so we can import from
    # them.
    [sys_path.extend((path, os_dirname(path.rstrip("/")))) for path in mod_path if path not in sys_path]

    # Build the list of modules ending in suffix in the mod_path(s).
    mod_list = (
        (path, name)
        for path in sys_path
        if os_isdir(path)
        for name in os_listdir(path)
        if name.endswith(suffix) and name not in blacklist
    )

    return mod_list
예제 #2
0
def _build_mod_list(mod_path, suffix, blacklist):
    """ _build_mod_list(mod_path, suffix) -> Add all the paths in mod_path to
    sys.path and return a list of all modules in sys.path ending in suffix.

    """

    from sys import path as sys_path

    mod_path = [mod_path] if type(mod_path) is str else mod_path
    blacklist = [blacklist] if type(blacklist) is str else blacklist

    # Add suffix to all names in blacklist.
    blacklist.extend([
        '%s%s' % (name, suffix) for name in blacklist
        if not name.endswith(suffix)
    ])

    # Add the path of this file to the search path.
    mod_path.append(os_abspath(os_dirname(__file__)))

    # Add the path(s) in mod_path to sys.path so we can import from
    # them.
    [
        sys_path.extend((path, os_dirname(path.rstrip('/'))))
        for path in mod_path if path not in sys_path
    ]

    # Build the list of modules ending in suffix in the mod_path(s).
    mod_list = ((path, name) for path in sys_path if os_isdir(path)
                for name in os_listdir(path)
                if name.endswith(suffix) and name not in blacklist)

    return mod_list
예제 #3
0
파일: __init__.py 프로젝트: fendaq/core
def abspath(url):
    """
    Get a full path to a file or file URL

    See os.abspath
    """
    if url.startswith('file://'):
        url = url[len('file://'):]
    return os_abspath(url)
예제 #4
0
파일: import_util.py 프로젝트: zepto/musio
def _build_mod_list(mod_path: list) -> list:
    """ _build_mod_list(mod_path, suffix) -> Add all the paths in mod_path to
    sys.path and return a list of all modules in sys.path ending in suffix.

    """

    mod_path = [mod_path] if type(mod_path) is str else mod_path

    # Add the path of this file to the search path.
    mod_path.append(os_abspath(os_dirname(__file__)))

    # Build the list of modules in mod_path(s).
    mod_list = ('{0}.{1}.{2}'.format(os_basename(path), \
                    os_basename(root).replace(os_basename(path), ''), \
                    name.rsplit('.', 1)[0]).replace('..', '.') \
                    for path in mod_path \
                        if os_isdir(path) \
                            for root, dirs, files in os_walk(path) \
                                for name in files \
                                    if name.endswith('.py'))

    return mod_list
예제 #5
0
def _build_mod_list(mod_path):
    """ _build_mod_list(mod_path, suffix) -> Add all the paths in mod_path to
    sys.path and return a list of all modules in sys.path ending in suffix.

    """

    mod_path = [mod_path] if type(mod_path) is str else mod_path

    # Add the path of this file to the search path.
    mod_path.append(os_abspath(os_dirname(__file__)))

    # Build the list of modules in mod_path(s).
    mod_list = ('{0}.{1}.{2}'.format(os_basename(path), \
                    os_basename(root).replace(os_basename(path), ''), \
                    name.rsplit('.', 1)[0]).replace('..', '.') \
                    for path in mod_path \
                        if os_isdir(path) \
                            for root, dirs, files in os_walk(path) \
                                for name in files \
                                    if name.endswith('.py'))

    return mod_list
"""Tool for solving systems of linear equations
using Cholesky decomposition

Functions:
    solve_system(A, b) -> ndarray
    decomposition(matrix) -> ndarray
    print_log() -> None
"""

import numpy as np
import cmath

from os.path import abspath as os_abspath, join as os_join
lib_path = os_abspath(os_join(__file__, '..', '..', 'GaussianElimination'))
from sys import path as sys_path
sys_path.append(lib_path)
import gaussel as ge


def print_log():
    for key, value in _log.items():
        print(key + ':\n', value, end='\n\n')


def solve_system(A, b):
    """Solve system of linear equations A x = b and return x.

    Arguments:
    A -- symmetric matrix
    b -- vector
    """
예제 #7
0
def adjust_caps(layout: [dict], colour_map: [dict], profile_data: dict,
                collection: Collection, layout_min_point: Vector,
                layout_max_point: Vector, pargs: Namespace) -> dict:
    # Resolve output unique output name
    printi('Getting required keycap data...')
    caps: [dict] = get_data(layout, pargs.cap_dir, colour_map, collection,
                            profile_data)

    printi('Adjusting keycaps...')
    for cap in caps:
        handle_cap(cap, profile_data['unit-length'])

    capmodel_name: str = generate_capmodel_name('capmodel')
    uv_image_path: str = None
    uv_material_name: str = None
    colourMaterials: list = []
    importedCapObjects: [Object] = list(map(lambda cap: cap['cap-obj'], caps))
    imgNode: ShaderNodeTexImage = None
    if len(importedCapObjects) != 0:
        printi('Joining keycap models into a single object')
        capmodel_mesh_tmp: BMesh = new_mesh()
        for importedCapObject in importedCapObjects:
            # Transform the object and its normals
            importedCapObject.data.transform(importedCapObject.matrix_world)

            # Append the single cap to the model for the entire layout
            capmodel_mesh_tmp.from_mesh(importedCapObject.data)

            # Remove the now-unused single-cap object
            data.objects.remove(importedCapObject)
        capmodel_mesh: BMesh = data.meshes.new(capmodel_name)
        capmodel_mesh_tmp.to_mesh(capmodel_mesh)
        capmodel_mesh.use_auto_smooth = True
        capmodel_object: Object = data.objects.new(capmodel_name,
                                                   capmodel_mesh)
        collection.objects.link(capmodel_object)
        capmodel_mesh_tmp.free()

        printi('Handling material')
        uv_image_base: str = capmodel_name + '_uv_image.png'
        uv_image_path = os_abspath(abspath('//' + uv_image_base))
        if not check_permissions(uv_image_path, W_OK):
            uv_image_path = os_abspath(
                expanduser(join('~', 'Downloads', uv_image_base)))
        (imgNode, uv_material_name) = generate_uv_map_materials(
            pargs.use_existing_materials, uv_image_path, capmodel_name,
            capmodel_object)

        printi('Updating cap-model scaling')
        capmodel_object.data.transform(capmodel_object.matrix_world)
        capmodel_object.matrix_world = Matrix.Scale(profile_data['scale'], 4)
        capmodel_object.data.transform(capmodel_object.matrix_world)
        capmodel_object.matrix_world = Matrix.Identity(4)

        printi('UV-unwrapping cap-model')
        layout_scale: float = profile_data['unit-length'] * profile_data[
            'scale']
        uv_unwrap(capmodel_object, layout_scale * layout_min_point,
                  layout_scale * layout_max_point,
                  pargs.partition_uv_by_face_direction)

    return {
        'keycaps-model-name': capmodel_name,
        'keycaps-model': capmodel_object,
        'material-names': colourMaterials,
        '~caps-with-margin-offsets': caps,
        '~texture-image-node': imgNode,
        'uv-image-path': uv_image_path,
        'uv-material-name': uv_material_name
    }
from unittest import TestCase, main
from numpy import array, allclose

from os.path import abspath as os_abspath, join as os_join
lib_path = os_abspath(
    os_join(__file__, '..', '..', 'PowerIteration_EigenvalueAlgorithm'))
from sys import path as sys_path
sys_path.append(lib_path)

from powiter import power_iteration_m
from jacobi import calculate_eigenvalues, calculate_eigenvalues_m


class JacobiEigenvalueTestCase(TestCase):
    def setUp(self):
        """initial set up"""
        self.eps = 10**-10
        self.A = array([[1.42, 7.45, 0.38], [7.45, 1.61, 0.56],
                        [0.38, 0.56, 0.82]])

    def test_calculate_eigenvalues(self):
        """Verify the found eigenvalues contains max modulo eigenvalue"""
        eigenvalues = calculate_eigenvalues(self.A, self.eps)
        eigenvalue, eigenvector = power_iteration_m(self.A, self.eps)
        ndigits = 5
        self.assertIn(eigenvalue.round(ndigits), eigenvalues.round(ndigits))

    def test_calculate_eigenvalues_m(self):
        """Verify the found eigenvalues contains max modulo eigenvalue"""
        eigenvalues = calculate_eigenvalues_m(self.A, self.eps)
        eigenvalue, eigenvector = power_iteration_m(self.A, self.eps)