From: Michael Orlitzky Date: Sun, 30 Oct 2016 20:27:12 +0000 (-0400) Subject: Add a "typecode" parameter to the identity() matrix function. X-Git-Tag: 0.1.0~112 X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dunshire.git;a=commitdiff_plain;h=97eddc6f61ca53ba39f547360ced35a2f69908cb Add a "typecode" parameter to the identity() matrix function. --- diff --git a/dunshire/matrices.py b/dunshire/matrices.py index 6ed4f85..66c2176 100644 --- a/dunshire/matrices.py +++ b/dunshire/matrices.py @@ -209,7 +209,7 @@ def eigenvalues_re(anymat): return [eig.real for eig in eigs] -def identity(domain_dim): +def identity(domain_dim, typecode='i'): """ Create an identity matrix of the given dimensions. @@ -219,6 +219,10 @@ def identity(domain_dim): domain_dim : int The dimension of the vector space on which the identity will act. + typecode : {'i', 'd', 'z'}, optional + The type code for the returned matrix, defaults to 'i' for integers. + Can also be 'd' for real double, or 'z' for complex double. + Returns ------- @@ -247,7 +251,7 @@ def identity(domain_dim): entries = [int(i == j) for i in range(domain_dim) for j in range(domain_dim)] - return matrix(entries, (domain_dim, domain_dim)) + return matrix(entries, (domain_dim, domain_dim), tc=typecode) def inner_product(vec1, vec2):