cm = lal.CreateCOMPLEX8VectorSequence(4, 6) check_dynamic_vector_matrix(iv, iv.length, rv, rv.length, cm, cm.length, cm.vectorLength) del iv, rv, cm rv0 = lal.CreateREAL8Vector(0) assert(rv0.length == 0) assert(len(rv0.data) == 0) del rv0 rv1 = lal.CreateREAL8Vector(1) rv1.data[0] = 1 del rv1 lal.CheckMemoryLeaks() print("PASSED dynamic vector/matrix conversions (LAL)") # check GSL vectors and matrices iv = lal.gsl_vector_int(5) rv = lal.gsl_vector(5) cm = lal.gsl_matrix_complex_float(4, 6) check_dynamic_vector_matrix(iv, iv.size, rv, rv.size, cm, cm.size1, cm.size2) del iv, rv, cm rv1 = lal.gsl_vector(1) rv1.data[0] = 1 del rv1 print("PASSED dynamic vector/matrix conversions (GSL)") # check fixed and dynamic arrays typemaps print("checking fixed and dynamic arrays typemaps ...") a1in = numpy.array([1.2, 3.5, 7.9], dtype=numpy.double) a1out = a1in * 2.5 assert((lal.swig_lal_test_copyin_array1(a1in, 2.5) == a1out).all()) a2in = numpy.array([[3,2], [7,6], [12,10]], dtype=numpy.int32)
except: pass assert (not expected_exception) print("*** above should be an error message from CheckMemoryLeaks() ***") del mem1 del mem2 del mem3 del mem4 lal.CheckMemoryLeaks() print("PASSED memory allocation") else: print("skipped memory allocation") # check object parent tracking print("checking object parent tracking ...") a = lal.gsl_vector(3) a.data = [1.1, 2.2, 3.3] b = a.data assert (not b.flags['OWNDATA']) assert ((b == [1.1, 2.2, 3.3]).all()) del a assert ((b == [1.1, 2.2, 3.3]).all()) ts = lal.CreateREAL8TimeSeries("test", lal.LIGOTimeGPS(0), 0, 0.1, lal.DimensionlessUnit, 10) ts.data.data = list(range(0, 10)) for i in range(0, 7): v = ts.data assert ((v.data == list(range(0, 10))).all()) del ts assert ((v.data == list(range(0, 10))).all()) del v
def generate_anstar_3d_lattice(maxv1, minv1, maxv2, minv2, maxv3, minv3, \ mindist): """ This function calls into LAL routines to generate a 3-dimensional array of points using the An^* lattice. Parameters ----------- maxv1 : float Largest value in the 1st dimension to cover minv1 : float Smallest value in the 1st dimension to cover maxv2 : float Largest value in the 2nd dimension to cover minv2 : float Smallest value in the 2nd dimension to cover maxv3 : float Largest value in the 3rd dimension to cover minv3 : float Smallest value in the 3rd dimension to cover mindist : float Maximum allowed mismatch between a point in the parameter space and the generated bank of points. Returns -------- v1s : numpy.array Array of positions in the first dimension v2s : numpy.array Array of positions in the second dimension v3s : numpy.array Array of positions in the second dimension """ # Lalpulsar not a requirement for the rest of pycbc, so check if we have it # here in this function. try: import lalpulsar except: raise ImportError("A SWIG-wrapped install of lalpulsar is needed to use the anstar tiling functionality.") tiling = lalpulsar.CreateLatticeTiling(3) lalpulsar.SetLatticeTilingConstantBound(tiling, 0, minv1, maxv1) lalpulsar.SetLatticeTilingConstantBound(tiling, 1, minv2, maxv2) lalpulsar.SetLatticeTilingConstantBound(tiling, 2, minv3, maxv3) # Make a 3x3 Euclidean lattice a = lal.gsl_matrix(3,3) a.data[0,0] = 1 a.data[1,1] = 1 a.data[2,2] = 1 try: # old versions of lalpulsar used an enumeration lattice = lalpulsar.TILING_LATTICE_ANSTAR except AttributeError: # newer versions of lalpulsar use a string lattice = 'An-star' lalpulsar.SetTilingLatticeAndMetric(tiling, lattice, a, mindist) try: iterator = lalpulsar.CreateLatticeTilingIterator(tiling, 3) except TypeError: # old versions of lalpulsar required the flags argument # (set to 0 for defaults) iterator = lalpulsar.CreateLatticeTilingIterator(tiling, 3, 0) vs1 = [] vs2 = [] vs3 = [] curr_point = lal.gsl_vector(3) while (lalpulsar.NextLatticeTilingPoint(iterator, curr_point) > 0): vs1.append(curr_point.data[0]) vs2.append(curr_point.data[1]) vs3.append(curr_point.data[2]) return vs1, vs2, vs3
except: pass assert(not expected_exception) print("*** above should be an error message from CheckMemoryLeaks() ***") del mem1 del mem2 del mem3 del mem4 lal.CheckMemoryLeaks() print("PASSED memory allocation") else: print("skipped memory allocation") # check object parent tracking print("checking object parent tracking ...") a = lal.gsl_vector(3) a.data = [1.1, 2.2, 3.3] b = a.data assert(not b.flags['OWNDATA']) assert((b == [1.1, 2.2, 3.3]).all()) del a assert((b == [1.1, 2.2, 3.3]).all()) ts = lal.CreateREAL8TimeSeries("test", lal.LIGOTimeGPS(0), 0, 0.1, lal.DimensionlessUnit, 10) ts.data.data = range(0, 10) for i in range(0, 7): v = ts.data assert((v.data == range(0, 10)).all()) del ts assert((v.data == range(0, 10)).all()) del v lal.CheckMemoryLeaks()
def generate_anstar_3d_lattice(maxv1, minv1, maxv2, minv2, maxv3, minv3, \ mindist): """ This function calls into LAL routines to generate a 3-dimensional array of points using the An^* lattice. Parameters ----------- maxv1 : float Largest value in the 1st dimension to cover minv1 : float Smallest value in the 1st dimension to cover maxv2 : float Largest value in the 2nd dimension to cover minv2 : float Smallest value in the 2nd dimension to cover maxv3 : float Largest value in the 3rd dimension to cover minv3 : float Smallest value in the 3rd dimension to cover mindist : float Maximum allowed mismatch between a point in the parameter space and the generated bank of points. Returns -------- v1s : numpy.array Array of positions in the first dimension v2s : numpy.array Array of positions in the second dimension v3s : numpy.array Array of positions in the second dimension """ # Lalpulsar not a requirement for the rest of pycbc, so check if we have it # here in this function. try: import lalpulsar except: raise ImportError("A SWIG-wrapped install of lalpulsar is needed to use the anstar tiling functionality.") tiling = lalpulsar.CreateLatticeTiling(3) lalpulsar.SetLatticeConstantBound(tiling, 0, minv1, maxv1) lalpulsar.SetLatticeConstantBound(tiling, 1, minv2, maxv2) lalpulsar.SetLatticeConstantBound(tiling, 2, minv3, maxv3) # Make a 3x3 Euclidean lattice a = lal.gsl_matrix(3,3) a.data[0,0] = 1 a.data[1,1] = 1 a.data[2,2] = 1 lalpulsar.SetLatticeTypeAndMetric(tiling, lalpulsar.LATTICE_TYPE_ANSTAR, a, mindist) vs1 = [] vs2 = [] vs3 = [] count = 0 curr_point = lal.gsl_vector(3) while (lalpulsar.NextLatticePoint(tiling, curr_point) >= 0): vs1.append(curr_point.data[0]) vs2.append(curr_point.data[1]) vs3.append(curr_point.data[2]) return vs1, vs2, vs3
def generate_anstar_3d_lattice(maxv1, minv1, maxv2, minv2, maxv3, minv3, mindist): """ This function calls into LAL routines to generate a 3-dimensional array of points using the An^* lattice. Parameters ----------- maxv1 : float Largest value in the 1st dimension to cover minv1 : float Smallest value in the 1st dimension to cover maxv2 : float Largest value in the 2nd dimension to cover minv2 : float Smallest value in the 2nd dimension to cover maxv3 : float Largest value in the 3rd dimension to cover minv3 : float Smallest value in the 3rd dimension to cover mindist : float Maximum allowed mismatch between a point in the parameter space and the generated bank of points. Returns -------- v1s : numpy.array Array of positions in the first dimension v2s : numpy.array Array of positions in the second dimension v3s : numpy.array Array of positions in the second dimension """ # Lalpulsar not a requirement for the rest of pycbc, so check if we have it # here in this function. try: import lalpulsar except: raise ImportError("A SWIG-wrapped install of lalpulsar is needed to use the anstar tiling functionality.") tiling = lalpulsar.CreateLatticeTiling(3) lalpulsar.SetLatticeTilingConstantBound(tiling, 0, minv1, maxv1) lalpulsar.SetLatticeTilingConstantBound(tiling, 1, minv2, maxv2) lalpulsar.SetLatticeTilingConstantBound(tiling, 2, minv3, maxv3) # Make a 3x3 Euclidean lattice a = lal.gsl_matrix(3, 3) a.data[0, 0] = 1 a.data[1, 1] = 1 a.data[2, 2] = 1 try: # old versions of lalpulsar used an enumeration lattice = lalpulsar.TILING_LATTICE_ANSTAR except AttributeError: # newer versions of lalpulsar use a string lattice = "An-star" lalpulsar.SetTilingLatticeAndMetric(tiling, lattice, a, mindist) try: iterator = lalpulsar.CreateLatticeTilingIterator(tiling, 3) except TypeError: # old versions of lalpulsar required the flags argument # (set to 0 for defaults) iterator = lalpulsar.CreateLatticeTilingIterator(tiling, 3, 0) vs1 = [] vs2 = [] vs3 = [] count = 0 curr_point = lal.gsl_vector(3) while lalpulsar.NextLatticeTilingPoint(iterator, curr_point) > 0: vs1.append(curr_point.data[0]) vs2.append(curr_point.data[1]) vs3.append(curr_point.data[2]) return vs1, vs2, vs3