Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ae168e5
fixed switched nomenclature for length and width
caitwolf Oct 29, 2022
fd03bda
fixed single letter variable names of 'w' and 'l'
caitwolf Oct 31, 2022
a6d8ec0
Merge branch 'master' into use-dQ-Data-slit-length-and-width-switched
caitwolf May 11, 2023
81ffb2e
Fixed inverse q-spacing in the geometric extrapolation function
Jun 27, 2023
23b05a9
Merge branch 'master' into 568-fix-geometric-extrapolation-when-point…
caitwolf Jun 27, 2023
f07dc5d
fixing typo from resolving merge conflict to ensure inverse term of l…
Jun 27, 2023
5bdfdce
Merge branch 'master' into use-dQ-Data-slit-length-and-width-switched
pkienzle Jul 25, 2023
a2b169e
Merge branch 'master' into 568-fix-geometric-extrapolation-when-point…
caitwolf Nov 21, 2023
17010b7
Merge branch 'master' into use-dQ-Data-slit-length-and-width-switched
caitwolf Jan 16, 2024
563ad5b
switched order of length and width in slit_resolution method for cons…
caitwolf Jan 16, 2024
d0dfa73
updated romberg_slit_1d to use length, width ordering of arguments, t…
caitwolf Jan 17, 2024
0e0b63d
fixed typo in the doc string for resolution.slit_resolution
caitwolf Jan 17, 2024
aa2b7b2
fixed width, length ordering in slit smearing fucntions to length, width
caitwolf Jan 17, 2024
e57e776
testing opencl ubuntu tests on github ci
caitwolf Jan 17, 2024
98053f4
switched the log_delta_q parameter in the first place so the variable…
caitwolf Jan 18, 2024
2fc80e0
Merge pull request #571 from SasView/568-fix-geometric-extrapolation-…
caitwolf Jan 19, 2024
65d5cf8
Merge branch 'master' into use-dQ-Data-slit-length-and-width-switched
Jan 21, 2026
17001fc
Update target value for test to reflect current return value
Jan 21, 2026
f3885ab
auto numpy type conversion
Jan 22, 2026
caab503
use required length/width keyword args internally; fix verification code
Jan 22, 2026
5f8552d
naming consistency: use q_width, q_length everywhere
Jan 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions sasmodels/direct_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ def main():
q, = values
dq = dqw = dql = None
#dq = [q*0.05] # 5% pinhole resolution
#dqw, dql = [q*0.05], [1.0] # 5% horizontal slit resolution
dqw, dql = [q*0.05], [1.0] # 5% horizontal slit resolution
print(Iq(model, [q], dq=dq, qw=dqw, ql=dql, **pars)[0])
#print(Gxi(model, [q], **pars)[0])
elif len(values) == 2:
Expand All @@ -554,24 +554,28 @@ def main():
sys.exit(1)

def test_simple_interface():
def near(value, target):
def assert_near(value: np.ndarray, target: list[float]):
"""Close enough in single precision"""
#print(f"value: {value}, target: {target}")
return np.allclose(value, target, rtol=1e-6, atol=0, equal_nan=True)
# Note: target values taken from running main() on parameters.
if not np.allclose(value, target, rtol=1e-6, atol=0, equal_nan=True):
assert value.tolist() == target
#raise ValueError(f"Expected {value} but got {target}")
# Target values taken from adusting main() with target resolution then running with:
# python -m sasmodels.direct_model sphere 0.1 radius=200 background=0
# python -m sasmodels.direct_model sphere 0.1,0.1 radius=200 background=0
# Resolution was 5% dq/q.
pars = dict(radius=200, background=0) # default background=1e-3, scale=1
# simple sphere in 1D (perfect, pinhole, slit)
perfect_target = 0.6190146273894904
assert near(Iq('sphere', [0.1], **pars), [perfect_target])
assert near(Iq('sphere', [0.1], dq=[0.005], **pars), [2.3009224683980215])
assert near(Iq('sphere', [0.1], qw=[0.005], ql=[1.0], **pars), [0.3663431784535172])
assert_near(Iq('sphere', [0.1], **pars), [perfect_target])
assert_near(Iq('sphere', [0.1], dq=[0.005], **pars), [2.3009224683980215])
assert_near(Iq('sphere', [0.1], qw=[0.005], ql=[1.0], **pars), [0.1650934496236075])
# simple sphere in 2D (perfect, pinhole)
assert near(Iqxy('sphere', [0.1], [0.1], **pars), [1.1771532874802199])
assert near(Iqxy('sphere', [0.1], [0.1], dqx=[0.005], dqy=[0.005], **pars),
assert_near(Iqxy('sphere', [0.1], [0.1], **pars), [1.1771532874802199])
assert_near(Iqxy('sphere', [0.1], [0.1], dqx=[0.005], dqy=[0.005], **pars),
[0.8167780778578667])
# sesans (no background or scale)
assert near(Gxi('sphere', [100], **pars), [-0.19146959126623486])
assert_near(Gxi('sphere', [100], **pars), [-0.19146959126623486])
# Check that single point sesans matches value in an array
xi = np.logspace(1, 3, 100)
y = Gxi('sphere', xi, **pars)
Expand All @@ -581,16 +585,16 @@ def near(value, target):
assert abs((ysingle-y[k])/y[k]) < 0.1, "SESANS point value not matching vector value within 10%"
# magnetic 2D
pars = dict(radius=200, sld_M0=3, sld_mtheta=30)
assert near(Iqxy('sphere', [0.1], [0.1], **pars), [1.5577852226925908])
assert_near(Iqxy('sphere', [0.1], [0.1], **pars), [1.5577852226925908])
# polydisperse 1D
pars = dict(
radius=200, radius_pd=0.1, radius_pd_n=15, radius_pd_nsigma=2.5,
radius_pd_type="uniform")
assert near(Iq('sphere', [0.1], **pars), [2.703169824954617])
assert_near(Iq('sphere', [0.1], **pars), [2.703169824954617])
# background and scale
background, scale = 1e-4, 0.1
pars = dict(radius=200, background=background, scale=scale)
assert near(Iq('sphere', [0.1], **pars), [perfect_target*scale + background])
assert_near(Iq('sphere', [0.1], **pars), [perfect_target*scale + background])


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion sasmodels/kernelcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def __setstate__(self, state):

def make_kernel(self, q_vectors):
# type: (list[np.ndarray]) -> "GpuKernel"
return GpuKernel(self, q_vectors)
return GpuKernel(self, np.asarray(q_vectors, dtype=self.dtype))

def get_function(self, name):
# type: (str) -> cl.Kernel
Expand Down
Loading