Skip to content

Comments

Broaden the template bound on the lp argument to constraints#3151

Merged
WardBrian merged 19 commits intodevelopfrom
broaden-constraint-lp-template
Mar 7, 2025
Merged

Broaden the template bound on the lp argument to constraints#3151
WardBrian merged 19 commits intodevelopfrom
broaden-constraint-lp-template

Conversation

@WardBrian
Copy link
Member

@WardBrian WardBrian commented Feb 21, 2025

Summary

This makes the lp argument of the _constrain functions its own template parameter rather that solely relying on the other arguments. This is useful for stan-dev/stanc3#1436, as for technical reasons it is hard to prevent the user from passing all doubles if these are exposed.

It also changes the order of some overloads and uses some template pack tricks to allow the non-Lp versions of these functions to be vectorized as well.

Tests

Side Effects

Release notes

Checklist

  • Copyright holder: (fill in copyright holder information)

    The copyright holder is typically you or your assignee, such as a university or company. By submitting this pull request, the copyright holder is agreeing to the license the submitted work under the following licenses:
    - Code: BSD 3-clause (https://opensource.org/licenses/BSD-3-Clause)
    - Documentation: CC-BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

  • the basic tests are passing

    • unit tests pass (to run, use: ./runTests.py test/unit)
    • header checks pass, (make test-headers)
    • dependencies checks pass, (make test-math-dependencies)
    • docs build, (make doxygen)
    • code passes the built in C++ standards checks (make cpplint)
  • the code is written in idiomatic C++ and changes are documented in the doxygen

  • the new changes are tested

@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
arma/arma.stan 0.35 0.39 0.89 -12.7% slower
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.01 0.01 0.94 -6.08% slower
gp_regr/gen_gp_data.stan 0.03 0.02 1.21 17.36% faster
gp_regr/gp_regr.stan 0.1 0.1 1.04 4.08% faster
sir/sir.stan 70.38 70.91 0.99 -0.75% slower
irt_2pl/irt_2pl.stan 4.12 4.33 0.95 -5.07% slower
eight_schools/eight_schools.stan 0.06 0.06 1.04 3.93% faster
pkpd/sim_one_comp_mm_elim_abs.stan 0.25 0.26 0.97 -2.58% slower
pkpd/one_comp_mm_elim_abs.stan 19.62 18.97 1.03 3.29% faster
garch/garch.stan 0.44 0.4 1.09 8.57% faster
low_dim_gauss_mix/low_dim_gauss_mix.stan 2.7 2.6 1.04 3.71% faster
arK/arK.stan 1.79 1.73 1.04 3.57% faster
gp_pois_regr/gp_pois_regr.stan 2.86 2.74 1.04 4.16% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 8.82 8.37 1.05 5.06% faster
performance.compilation 182.45 185.91 0.98 -1.9% slower
Mean result: 1.0216045346939837

Jenkins Console Log
Blue Ocean
Commit hash: 919e8c47e5ad903c5eadc62f9102039c73340a9f


Machine information No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focal

CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
Address sizes: 46 bits physical, 48 bits virtual
CPU(s): 80
On-line CPU(s) list: 0-79
Thread(s) per core: 2
Core(s) per socket: 20
Socket(s): 2
NUMA node(s): 2
Vendor ID: GenuineIntel
CPU family: 6
Model: 85
Model name: Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz
Stepping: 4
CPU MHz: 2400.000
CPU max MHz: 3700.0000
CPU min MHz: 1000.0000
BogoMIPS: 4800.00
Virtualization: VT-x
L1d cache: 1.3 MiB
L1i cache: 1.3 MiB
L2 cache: 40 MiB
L3 cache: 55 MiB
NUMA node0 CPU(s): 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78
NUMA node1 CPU(s): 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79
Vulnerability Gather data sampling: Mitigation; Microcode
Vulnerability Itlb multihit: KVM: Mitigation: VMX disabled
Vulnerability L1tf: Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
Vulnerability Mds: Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown: Mitigation; PTI
Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Mitigation; IBRS
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; IBRS; IBPB conditional; STIBP conditional; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Mitigation; Clear CPU buffers; SMT vulnerable
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti intel_ppin ssbd mba ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req pku ospke md_clear flush_l1d arch_capabilities

G++:
g++ (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Clang:
clang version 10.0.0-4ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
arma/arma.stan 0.31 0.31 1.03 2.89% faster
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.01 0.01 1.14 12.04% faster
gp_regr/gen_gp_data.stan 0.02 0.02 1.07 6.88% faster
gp_regr/gp_regr.stan 0.09 0.09 1.04 4.22% faster
sir/sir.stan 69.88 68.11 1.03 2.53% faster
irt_2pl/irt_2pl.stan 4.02 3.94 1.02 1.98% faster
eight_schools/eight_schools.stan 0.06 0.05 1.03 2.79% faster
pkpd/sim_one_comp_mm_elim_abs.stan 0.25 0.24 1.03 2.63% faster
pkpd/one_comp_mm_elim_abs.stan 19.44 19.0 1.02 2.24% faster
garch/garch.stan 0.44 0.4 1.08 7.63% faster
low_dim_gauss_mix/low_dim_gauss_mix.stan 2.74 2.59 1.06 5.52% faster
arK/arK.stan 1.8 1.73 1.04 4.16% faster
gp_pois_regr/gp_pois_regr.stan 2.92 2.74 1.07 6.41% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 8.8 8.44 1.04 4.06% faster
performance.compilation 181.81 185.39 0.98 -1.97% slower
Mean result: 1.0456849810292956

Jenkins Console Log
Blue Ocean
Commit hash: 919e8c47e5ad903c5eadc62f9102039c73340a9f


Machine information No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focal

CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
Address sizes: 46 bits physical, 48 bits virtual
CPU(s): 80
On-line CPU(s) list: 0-79
Thread(s) per core: 2
Core(s) per socket: 20
Socket(s): 2
NUMA node(s): 2
Vendor ID: GenuineIntel
CPU family: 6
Model: 85
Model name: Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz
Stepping: 4
CPU MHz: 2400.000
CPU max MHz: 3700.0000
CPU min MHz: 1000.0000
BogoMIPS: 4800.00
Virtualization: VT-x
L1d cache: 1.3 MiB
L1i cache: 1.3 MiB
L2 cache: 40 MiB
L3 cache: 55 MiB
NUMA node0 CPU(s): 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78
NUMA node1 CPU(s): 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79
Vulnerability Gather data sampling: Mitigation; Microcode
Vulnerability Itlb multihit: KVM: Mitigation: VMX disabled
Vulnerability L1tf: Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
Vulnerability Mds: Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown: Mitigation; PTI
Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Mitigation; IBRS
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; IBRS; IBPB conditional; STIBP conditional; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Mitigation; Clear CPU buffers; SMT vulnerable
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti intel_ppin ssbd mba ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req pku ospke md_clear flush_l1d arch_capabilities

G++:
g++ (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Clang:
clang version 10.0.0-4ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
arma/arma.stan 0.33 0.3 1.1 9.45% faster
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.01 0.01 0.95 -5.47% slower
gp_regr/gen_gp_data.stan 0.02 0.02 1.04 3.78% faster
gp_regr/gp_regr.stan 0.09 0.09 1.03 2.68% faster
sir/sir.stan 70.39 69.82 1.01 0.81% faster
irt_2pl/irt_2pl.stan 4.16 4.27 0.98 -2.5% slower
eight_schools/eight_schools.stan 0.06 0.06 1.0 -0.4% slower
pkpd/sim_one_comp_mm_elim_abs.stan 0.25 0.26 0.98 -1.91% slower
pkpd/one_comp_mm_elim_abs.stan 19.5 19.06 1.02 2.27% faster
garch/garch.stan 0.43 0.4 1.07 6.33% faster
low_dim_gauss_mix/low_dim_gauss_mix.stan 2.71 2.6 1.04 4.02% faster
arK/arK.stan 1.81 1.71 1.06 5.72% faster
gp_pois_regr/gp_pois_regr.stan 2.91 2.71 1.08 7.0% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 8.69 8.4 1.03 3.33% faster
performance.compilation 183.53 188.78 0.97 -2.86% slower
Mean result: 1.0237096279798086

Jenkins Console Log
Blue Ocean
Commit hash: 919e8c47e5ad903c5eadc62f9102039c73340a9f


Machine information No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focal

CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
Address sizes: 46 bits physical, 48 bits virtual
CPU(s): 80
On-line CPU(s) list: 0-79
Thread(s) per core: 2
Core(s) per socket: 20
Socket(s): 2
NUMA node(s): 2
Vendor ID: GenuineIntel
CPU family: 6
Model: 85
Model name: Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz
Stepping: 4
CPU MHz: 2400.000
CPU max MHz: 3700.0000
CPU min MHz: 1000.0000
BogoMIPS: 4800.00
Virtualization: VT-x
L1d cache: 1.3 MiB
L1i cache: 1.3 MiB
L2 cache: 40 MiB
L3 cache: 55 MiB
NUMA node0 CPU(s): 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78
NUMA node1 CPU(s): 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79
Vulnerability Gather data sampling: Mitigation; Microcode
Vulnerability Itlb multihit: KVM: Mitigation: VMX disabled
Vulnerability L1tf: Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
Vulnerability Mds: Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown: Mitigation; PTI
Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Mitigation; IBRS
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; IBRS; IBPB conditional; STIBP conditional; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Mitigation; Clear CPU buffers; SMT vulnerable
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti intel_ppin ssbd mba ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req pku ospke md_clear flush_l1d arch_capabilities

G++:
g++ (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Clang:
clang version 10.0.0-4ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
arma/arma.stan 0.35 0.38 0.93 -7.65% slower
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.01 0.01 0.99 -1.34% slower
gp_regr/gen_gp_data.stan 0.03 0.02 1.08 7.78% faster
gp_regr/gp_regr.stan 0.1 0.1 1.02 1.93% faster
sir/sir.stan 73.71 73.96 1.0 -0.35% slower
irt_2pl/irt_2pl.stan 4.71 4.55 1.04 3.39% faster
eight_schools/eight_schools.stan 0.07 0.06 1.25 20.04% faster
pkpd/sim_one_comp_mm_elim_abs.stan 0.27 0.26 1.03 2.98% faster
pkpd/one_comp_mm_elim_abs.stan 20.63 20.31 1.02 1.59% faster
garch/garch.stan 0.49 0.46 1.08 7.58% faster
low_dim_gauss_mix/low_dim_gauss_mix.stan 2.85 2.86 1.0 -0.23% slower
arK/arK.stan 1.86 1.89 0.98 -1.96% slower
gp_pois_regr/gp_pois_regr.stan 3.01 3.05 0.99 -1.19% slower
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 10.96 11.0 1.0 -0.34% slower
performance.compilation 194.67 205.52 0.95 -5.58% slower
Mean result: 1.0227631413541356

Jenkins Console Log
Blue Ocean
Commit hash: 919e8c47e5ad903c5eadc62f9102039c73340a9f


Machine information No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focal

CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
Address sizes: 46 bits physical, 48 bits virtual
CPU(s): 80
On-line CPU(s) list: 0-79
Thread(s) per core: 2
Core(s) per socket: 20
Socket(s): 2
NUMA node(s): 2
Vendor ID: GenuineIntel
CPU family: 6
Model: 85
Model name: Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz
Stepping: 4
CPU MHz: 3400.000
CPU max MHz: 3700.0000
CPU min MHz: 1000.0000
BogoMIPS: 4800.00
Virtualization: VT-x
L1d cache: 1.3 MiB
L1i cache: 1.3 MiB
L2 cache: 40 MiB
L3 cache: 55 MiB
NUMA node0 CPU(s): 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78
NUMA node1 CPU(s): 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79
Vulnerability Gather data sampling: Mitigation; Microcode
Vulnerability Itlb multihit: KVM: Mitigation: VMX disabled
Vulnerability L1tf: Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
Vulnerability Mds: Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown: Mitigation; PTI
Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Mitigation; IBRS
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; IBRS; IBPB conditional; STIBP conditional; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Mitigation; Clear CPU buffers; SMT vulnerable
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti intel_ppin ssbd mba ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req pku ospke md_clear flush_l1d arch_capabilities

G++:
g++ (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Clang:
clang version 10.0.0-4ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

template <typename EigVec, require_eigen_vector_t<EigVec>* = nullptr>
template <typename EigVec, typename Lp,
require_eigen_vector_t<EigVec>* = nullptr,
require_convertible_t<return_type_t<EigVec>, Lp>* = nullptr>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this will allow lp to be var and return_type_t<EigVec> to be double or var.

Do we ever want to increment the jacobian when y just has a scalar type of double?

lp += 0.5 * log1m(sum_sqs);

What are the use types you want to pass into this? Is it just the return_type_t<EigVec> = double and lp = var case? Since the data is considered constant in that case shouldn't we just call the one that does not increment the jacobian?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return_type_t<EigVec> = double and lp = var

Yes, that's the relevant one that comes up during code generation. Based on my conversation with @bob-carpenter, I think we still want to let the user do it, even if it's weird. The implementation in stanc3#1494 gives the user both a _jacobian function and a _constrain function, and I think it's reasonable to view these as similar to the difference between doing a target+= with a _lpdf versus a _lupdf.

Comment on lines 97 to 102
inline auto corr_matrix_constrain(const T& y, int K, Lp&... lp) {
static_assert(sizeof...(lp) == 0 || sizeof...(lp) == 1,
"corr_matrix_constrain should be called with either "
"two or three arguments");
return apply_vector_unary<T>::apply(
y, [&lp..., K](auto&& v) { return corr_matrix_constrain(v, K, lp...); });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a bug in our api since we only have the lp version for corr_matirix_constrain(std::vector<>). imo I'd rather just have two functions. It's more code but I think cleaner just to have two separate function

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean two separate overloads that both call apply_vector_unary? I can split them up if you want, it's just a bunch of copy-paste

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Yes it's just a bunch of copy pastes but imo I'd rather have duplicate code that is a bit easier to read here

Copy link
Collaborator

@SteveBronder SteveBronder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So imo everything is good except that I would like to have a new signature in the places where we are doing LP.... That just looks kind of clunky and having two signatures just makes a bit more sense.

* from transforming the specified finite vector of size K plus (K choose 2).
* This overload handles looping over the elements of a standard vector.
*
* @tparam Jacobian if `true`, increment log density accumulator with log
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add back docs for jacobian

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is just github showing the diff weirdly because a signature moved around -- there is no jacobian template on this overload

@WardBrian
Copy link
Member Author

@SteveBronder I pushed the change to split up the Lp... earlier today -- is your latest review based on before that?

@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
arma/arma.stan 0.33 0.32 1.03 3.16% faster
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.01 0.01 1.06 5.66% faster
gp_regr/gen_gp_data.stan 0.03 0.02 1.1 9.12% faster
gp_regr/gp_regr.stan 0.1 0.09 1.07 6.85% faster
sir/sir.stan 70.42 68.22 1.03 3.13% faster
irt_2pl/irt_2pl.stan 4.1 3.98 1.03 3.11% faster
eight_schools/eight_schools.stan 0.06 0.05 1.08 7.14% faster
pkpd/sim_one_comp_mm_elim_abs.stan 0.25 0.24 1.03 2.85% faster
pkpd/one_comp_mm_elim_abs.stan 19.63 19.05 1.03 2.97% faster
garch/garch.stan 0.43 0.4 1.07 6.87% faster
low_dim_gauss_mix/low_dim_gauss_mix.stan 2.72 2.63 1.04 3.51% faster
arK/arK.stan 1.8 1.71 1.05 4.97% faster
gp_pois_regr/gp_pois_regr.stan 2.82 2.74 1.03 3.0% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 8.72 8.39 1.04 3.83% faster
performance.compilation 182.97 183.76 1.0 -0.43% slower
Mean result: 1.046440904755975

Jenkins Console Log
Blue Ocean
Commit hash: b3ebfc9cf0b6967e9be77a03696d221959159748


Machine information No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focal

CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
Address sizes: 46 bits physical, 48 bits virtual
CPU(s): 80
On-line CPU(s) list: 0-79
Thread(s) per core: 2
Core(s) per socket: 20
Socket(s): 2
NUMA node(s): 2
Vendor ID: GenuineIntel
CPU family: 6
Model: 85
Model name: Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz
Stepping: 4
CPU MHz: 2400.000
CPU max MHz: 3700.0000
CPU min MHz: 1000.0000
BogoMIPS: 4800.00
Virtualization: VT-x
L1d cache: 1.3 MiB
L1i cache: 1.3 MiB
L2 cache: 40 MiB
L3 cache: 55 MiB
NUMA node0 CPU(s): 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78
NUMA node1 CPU(s): 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79
Vulnerability Gather data sampling: Mitigation; Microcode
Vulnerability Itlb multihit: KVM: Mitigation: VMX disabled
Vulnerability L1tf: Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
Vulnerability Mds: Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown: Mitigation; PTI
Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Mitigation; IBRS
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; IBRS; IBPB conditional; STIBP conditional; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Mitigation; Clear CPU buffers; SMT vulnerable
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti intel_ppin ssbd mba ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req pku ospke md_clear flush_l1d arch_capabilities

G++:
g++ (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Clang:
clang version 10.0.0-4ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

@SteveBronder
Copy link
Collaborator

Did you want to also do cov_matrix_constrain_lkj? (Is that used?)

@WardBrian
Copy link
Member Author

It’s not used anywhere by the compiler, so I don’t currently plan on exposing it to the user

@WardBrian
Copy link
Member Author

@SteveBronder it looks like your latest push broke the accompanying stanc3 PR: https://jenkins.flatironinstitute.org/job/Stan/job/Stanc3/job/PR-1494/14/

@WardBrian WardBrian force-pushed the broaden-constraint-lp-template branch from e918b34 to 7866a45 Compare March 6, 2025 14:52
@WardBrian WardBrian mentioned this pull request Mar 6, 2025
4 tasks
@WardBrian WardBrian requested a review from SteveBronder March 6, 2025 14:54
@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
arma/arma.stan 0.34 0.34 1.0 -0.11% slower
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.01 0.01 0.96 -3.89% slower
gp_regr/gen_gp_data.stan 0.03 0.02 1.07 6.51% faster
gp_regr/gp_regr.stan 0.1 0.09 1.06 5.38% faster
sir/sir.stan 71.14 71.32 1.0 -0.26% slower
irt_2pl/irt_2pl.stan 4.22 4.24 1.0 -0.39% slower
eight_schools/eight_schools.stan 0.06 0.06 1.02 1.95% faster
pkpd/sim_one_comp_mm_elim_abs.stan 0.26 0.26 0.99 -0.69% slower
pkpd/one_comp_mm_elim_abs.stan 19.93 19.57 1.02 1.79% faster
garch/garch.stan 0.44 0.43 1.03 2.8% faster
low_dim_gauss_mix/low_dim_gauss_mix.stan 2.84 2.74 1.04 3.63% faster
arK/arK.stan 1.84 1.82 1.01 1.13% faster
gp_pois_regr/gp_pois_regr.stan 2.88 2.86 1.01 0.53% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 9.16 8.92 1.03 2.56% faster
performance.compilation 191.13 202.56 0.94 -5.98% slower
Mean result: 1.01105728269144

Jenkins Console Log
Blue Ocean
Commit hash: 41fb879c2b057722f0b8d4e3462ddede193cb95e


Machine information No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focal

CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
Address sizes: 46 bits physical, 48 bits virtual
CPU(s): 80
On-line CPU(s) list: 0-79
Thread(s) per core: 2
Core(s) per socket: 20
Socket(s): 2
NUMA node(s): 2
Vendor ID: GenuineIntel
CPU family: 6
Model: 85
Model name: Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz
Stepping: 4
CPU MHz: 3474.467
CPU max MHz: 3700.0000
CPU min MHz: 1000.0000
BogoMIPS: 4800.00
Virtualization: VT-x
L1d cache: 1.3 MiB
L1i cache: 1.3 MiB
L2 cache: 40 MiB
L3 cache: 55 MiB
NUMA node0 CPU(s): 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78
NUMA node1 CPU(s): 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79
Vulnerability Gather data sampling: Mitigation; Microcode
Vulnerability Itlb multihit: KVM: Mitigation: VMX disabled
Vulnerability L1tf: Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
Vulnerability Mds: Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown: Mitigation; PTI
Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Mitigation; IBRS
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; IBRS; IBPB conditional; STIBP conditional; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Mitigation; Clear CPU buffers; SMT vulnerable
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti intel_ppin ssbd mba ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req pku ospke md_clear flush_l1d arch_capabilities

G++:
g++ (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Clang:
clang version 10.0.0-4ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

@WardBrian WardBrian merged commit 0f1ad25 into develop Mar 7, 2025
8 checks passed
@WardBrian WardBrian deleted the broaden-constraint-lp-template branch March 7, 2025 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants