gstlal 1.13.0
Loading...
Searching...
No Matches
statevector_test_01.py
1#!/usr/bin/env python3
2# Copyright (C) 2014 Jolien Creighton
3#
4# This program is free software; you can redistribute it and/or modify it
5# under the terms of the GNU General Public License as published by the
6# Free Software Foundation; either version 2 of the License, or (at your
7# option) any later version.
8#
9# This program is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
12# Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program; if not, write to the Free Software Foundation, Inc.,
16# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18#
19# =============================================================================
20#
21# Preamble
22#
23# =============================================================================
24#
25
26
27import numpy
28import sys
29from gstlal import pipeparts
30import test_common
31import cmp_nxydumps
32
33
34#
35# =============================================================================
36#
37# Pipelines
38#
39# =============================================================================
40#
41
42
43
44
45def statevector_test_01(name, width, samples):
46 imax = 1 << width
47 bits = 3 # number of bits to set for required-on and required-off
48 required_on = 1
49 required_off = 1
50
51 while required_on & required_off:
52 # random required-on and required-off bits
53 required_on = int(sum(1 << bit for bit in numpy.random.randint(width - 1, size = bits))) & (imax - 1)
54 required_off = int(sum(1 << bit for bit in numpy.random.randint(width - 1, size = bits))) & (imax - 1)
55
56 input_samples = numpy.random.randint(imax, size=(samples, 1)).astype("u%d" % (width // 8))
57 output_reference = ((input_samples & required_on) == required_on) & ((~input_samples & required_off) == required_off)
58 output_array, = test_common.transform_arrays([input_samples], pipeparts.mkstatevector, name, required_on = required_on, required_off = required_off)
59 output_array.dtype = bool
60 if (output_array != output_reference).any():
61 raise ValueError("incorrect output: expected %s, got %s" % (output_reference, output_array))
62
63
64#
65# =============================================================================
66#
67# Main
68#
69# =============================================================================
70#
71
72
73for _ in range(100):
74 statevector_test_01("statevector_test_01a", 32, samples = 1000)
transform_arrays(input_arrays, elemfunc, name, rate=1, **elemfunc_kwargs)