-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from bbfrederick/sharedmemupdate
First crack at new shared memory routines
- Loading branch information
Showing
7 changed files
with
158 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright 2016-2024 Blaise Frederick | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import numpy as np | ||
|
||
import rapidtide.util as tide_util | ||
|
||
|
||
def test_numpy2shared(debug=False): | ||
vectorlen = 1000 | ||
for intype in [np.float32, np.float64]: | ||
sourcevector = np.random.normal(size=vectorlen).astype(intype) | ||
if debug: | ||
print(f"{intype=}, {sourcevector.size=}, {sourcevector.dtype=}") | ||
for outtype in [np.float32, np.float64]: | ||
|
||
destvector, shm = tide_util.numpy2shared(sourcevector, outtype) | ||
if debug: | ||
print(f"\t{outtype=}, {destvector.size=}, {destvector.dtype=}") | ||
|
||
# check everything | ||
assert destvector.dtype == outtype | ||
assert destvector.size == sourcevector.size | ||
np.testing.assert_almost_equal(sourcevector, destvector, 3) | ||
|
||
# clean up | ||
tide_util.cleanup_shm(shm) | ||
|
||
|
||
def test_allocshared(debug=False): | ||
datashape = (10, 10, 10) | ||
for outtype in [np.float32, np.float64]: | ||
destarray, shm = tide_util.allocshared(datashape, outtype) | ||
if debug: | ||
print(f"{outtype=}, {destarray.size=}, {destarray.dtype=}") | ||
|
||
# check everything | ||
assert destarray.dtype == outtype | ||
assert destarray.size == np.prod(datashape) | ||
|
||
# clean up if needed | ||
tide_util.cleanup_shm(shm) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_numpy2shared(debug=True) | ||
test_allocshared(debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.