尤怨

文章 评论 浏览 28

尤怨 2025-02-07 13:34:47

sqrt< x,n> instantiates sqrt< x+1,n> and instantiates sqrt< x+2,n>等永不停止。

即使仅采用一个分支机,也通过编译器评估两个分支。编译器还不够聪明,无法看到该条件在某个时候是错误的,然后sqrt< value+1,n>不需要实例化。您必须更加解释。 (实际上更正确:编译器确实需要知道的两侧:以确定其常见类型,因为这就是条件运算符类型的类型)。

由于C ++ 17,您可以使用constexpr,如果丢弃false-branch:

#include <iostream>


template<int value, int N>
int sqrt(){
    if constexpr (value*value == N) { 
        return value;
    } else {
        return sqrt<value+1,N>();
    }
    
};

int main()
{
    std::cout << sqrt<1,4>();
}

在C ++ 17之前,您可以将模板专业化作为递归的停止条件:

#include <iostream>


template<int value, int N>
struct sqrt
{
    enum { val = ((value*value == N) ? value : (sqrt<(value+1), N>::val)) };
};

template <int value>
struct sqrt<value,value*value> {
    enum { val = value };
};


int main()
{
    std::cout << sqrt<1,4>::val;
}

但是,当<时,两者都会失败。代码> n 不是平方数。您应该将条件更改为value*value&gt; = n以确保递归始终停止(并在addionionally中检查n == value*value*value)。

此外,我建议交换参数的顺序,以便您可以将默认的1用于value。另外,enum东西看起来有些过时。我不记得要克服什么限制。无论如何,您可以简单地使用static const val = ...

sqrt<X,N> instantiates sqrt<X+1,N> and that instantiates sqrt<X+2,N> etc. it never stops.

Both branches are evaluated by the compiler, even if only one of them is taken. The compiler is not clever enough to see that the condition is false at some point and then sqrt<value+1,N> does not need to be instantiated. You have to tell it more explictly. (Actually more correct: The compiler does need to know both sides of the : to determine their common type, because thats what the conditional operators type is).

Since C++17 you can use constexpr if to get the false-branch discarded:

#include <iostream>


template<int value, int N>
int sqrt(){
    if constexpr (value*value == N) { 
        return value;
    } else {
        return sqrt<value+1,N>();
    }
    
};

int main()
{
    std::cout << sqrt<1,4>();
}

Before C++17 you could use template specialization as the stop condition for the recursion:

#include <iostream>


template<int value, int N>
struct sqrt
{
    enum { val = ((value*value == N) ? value : (sqrt<(value+1), N>::val)) };
};

template <int value>
struct sqrt<value,value*value> {
    enum { val = value };
};


int main()
{
    std::cout << sqrt<1,4>::val;
}

However, both will fail when N is not a square number. You should change the condition to value*value >= N to make sure the recursion always stops (and addtionally check if N == value*value).

Further I suggest to swap the order of the arguments so you can use a default 1 for value. Also the enum thingy looks a little outdated. I don't remember what restriction is was meant to overcome. Anyhow, you can simply use a static const val = ... instead.

此模板元图有什么问题找到平方根?

尤怨 2025-02-07 11:33:38

这里很有趣。显然,15.625是通过将其解释为[H]:MM:SS的。 375 /24 = 15.625 < / code>。因此,要返回375:00:00,您只能做15.625 * 24&amp; “:00:00”。当您将其分配给单元格时,Excel将其解释为一个值,而不是 string (但请参见下面...)。但是,这里有些奇怪。你说:

查看公式时,我可以看到该值是 14.01.1900 15:00:00

这很奇怪。显然,它应该解决 15 .01.1900等。我认为您可能已经制作了错字,但显然不是。我已经进行了一些测试:

Sub test()

For Each cell In Range("A1:A4")

'Range("A1") = 375:00:00 custom formatting automatically applied: "[h]:mm:ss"
'Range("A2") = 375:00:00 custom formatting manually adjusted: "mm/dd/yyyy h:mm:ss AM/PM"
'Range("A3") = "=VALUE(""375:00:00"")", defaults to general formatting: 15.625
'Range("A4") = "=VALUE(""10000:00:00"")" from 10000 this produces #VALUE! errors (or "Error 2015")

Debug.Print cell.Value
Debug.Print cell.Value2
Debug.Print cell.Text
Debug.Print "---"

Next cell

'''Immediate Window output

'     15.625
'     15.625
'    375:00:00
'    ---
'    1/14/1900 3:00:00 PM
'     15.625
'    01/15/1900 3:00:00 PM
'    ---
'     15.625
'     15.625
'    15.625
'    ---
'    Error 2015
'    Error 2015
'    #VALUE!
'    ---

'''

End Sub

因此,这里有两个非常奇怪的事情:

  1. cell.value for range(“ A2”)作为1/14/1900 3:00:00 pm(在提到的问题中重现怪异),即使.text也将正确产生01/15/1900 3:00:00 pm < /代码>。
  2. Excel停止理解10000:00:00的“逻辑”。比较以下内容:
Sub insert_convert()

Range("A6") = 10000 / 24 * 24 & ":00:00"    'expected 416.6666667, but now a String: "10000:00:00"
Range("A7") = 9999 / 24 * 24 & ":00:00"     '416.625 (and "2/19/1901  3:00:00 PM" in formula bar)

End Sub

我看不出为什么会出现这些奇怪之处。对我来说似乎是虫子。


编辑:我猜问题2可能与以下事实有关:在评估= value(“ 10000:00:00”)时,Excel试图将字符串解释为a date < /a>,然后是错误,因为:

[日期h] Olds IEEE 64位(8字节)值,代表日期为从0001的1月1日到年度12月31日 9999 ... ...

Quite an intriguing case here. Evidently, 15.625 is produced by Excel interpreting this as [h]:mm:ss. 375 / 24 = 15.625. So, to get back to 375:00:00, you could just do 15.625 * 24 & ":00:00". When you assign this to a cell, Excel will interpret it as a value, rather than a string (but see below...). However, there is something very odd here. You said:

When looking at the formula I can see that the value is 14.01.1900 15:00:00.

This is odd. Obviously, it should resolve to 15.01.1900 etc. I thought you might have made a typo, but apparently not. I've ran some tests:

Sub test()

For Each cell In Range("A1:A4")

'Range("A1") = 375:00:00 custom formatting automatically applied: "[h]:mm:ss"
'Range("A2") = 375:00:00 custom formatting manually adjusted: "mm/dd/yyyy h:mm:ss AM/PM"
'Range("A3") = "=VALUE(""375:00:00"")", defaults to general formatting: 15.625
'Range("A4") = "=VALUE(""10000:00:00"")" from 10000 this produces #VALUE! errors (or "Error 2015")

Debug.Print cell.Value
Debug.Print cell.Value2
Debug.Print cell.Text
Debug.Print "---"

Next cell

'''Immediate Window output

'     15.625
'     15.625
'    375:00:00
'    ---
'    1/14/1900 3:00:00 PM
'     15.625
'    01/15/1900 3:00:00 PM
'    ---
'     15.625
'     15.625
'    15.625
'    ---
'    Error 2015
'    Error 2015
'    #VALUE!
'    ---

'''

End Sub

So, two very odd things here:

  1. cell.Value for Range("A2") is given as 1/14/1900 3:00:00 PM (reproducing the quirk in the question mentioned about), even though .Text will correctly produce 01/15/1900 3:00:00 PM.
  2. Excel ceases to understand the "logic" at 10000:00:00. Compare this:
Sub insert_convert()

Range("A6") = 10000 / 24 * 24 & ":00:00"    'expected 416.6666667, but now a String: "10000:00:00"
Range("A7") = 9999 / 24 * 24 & ":00:00"     '416.625 (and "2/19/1901  3:00:00 PM" in formula bar)

End Sub

I fail to see why these oddities occur. Seem like bugs to me.


Edit: I guess problem 2 might have to do with the fact that during the evaluation of =VALUE("10000:00:00"), Excel tries to interpret the string as a Date, and then errs, since:

[Date h]olds IEEE 64-bit (8-byte) values that represent dates ranging from January 1 of the year 0001 through December 31 of the year 9999...

在不自动转换的情况下进行值

尤怨 2025-02-07 02:13:12

您必须使用flag -lpthread-pthread编译(通常建议使用pthread)。如果您使用的是Clion,则需要编辑cmakelists.txt,以确保通过使用命令设置编译器标志来确保与此标志编译您的代码:

SET( CMAKE_CXX_FLAGS  "<other compiler flags> -pthread")

您可以在

You have to compile with flag -lpthread or -pthread (its usually advised to usepthread). If you're using CLion then you will need to edit CMakeLists.txt to ensure that your code is compiled with this flag by setting compiler flags with a command like:

SET( CMAKE_CXX_FLAGS  "<other compiler flags> -pthread")

You can learn more about these options on this post.

对Pthread Clion的未定义引用

尤怨 2025-02-06 18:06:53

您没有获得位置许可,因为在您的Initstate内部,您称之为一些异步事件。 Flutter Lifecycle告诉我们,尽管Initstate首先运行,但是任何异步事件都需要时间进行。这就是为什么即使您在Initstate中的功能首先称为,但由于它们是异步的,因此小部件构建方法是首先触发的,因此它覆盖了您的位置权限弹出。

为了解决这个问题,您可以将另一个未来构建器包裹在当前的未来建筑商中。第一个FutureBuilder应该具有位置权限任务,第二个FutureBuilder应具有i列任务。

You are not getting location permission because inside your initState you have called some asynchronous events. Flutter lifecycle tells us that although initState runs first, but any asynchronous event takes time to run. That's why even though your function in initState called first but as they are asynchronous, the widget build method is triggering first and thus it overrides your location permission pop up.

To solve this, you can wrap another futureBuilder to your current futureBuilder. The first futureBuilder should have the location permission task and the second futureBuilder should have the _registered task.

扑朔迷离 - 使用未来建筑商时未询问位置权限

尤怨 2025-02-06 17:02:46

如果您只想要帐户界图标,那么您可以像
&lt; greenbox&gt;&lt; acccountcircle /&gt; {Notification}&lt;/greenbox&gt;,或者如果您想要不同的通知图标,则可以做类似的事情。

export default function ControlledSwitches() {
  const UserIcon = styled(AccountCircle)({
    margin: "0px 0px 0px 0px"
  });
  const dummyNotification = [
    { text: "Notification #1", icon: <UserIcon /> },
    { text: "Notification #2", icon: <UserIcon /> },
    { text: "Notification #3", icon: <UserIcon /> }
  ];

  const cardComponents =
    dummyNotification !== undefined
      ? dummyNotification.map((notification) => (
          <div key={notification}>
            <div>
              <GreenBox>
                {notification.icon} {notification.text}
              </GreenBox>
            </div>
          </div>
        ))
      : "Loading...";
  return (
    <>
      <NavBar />
      <Row>
        <RightCol>
          <div>{cardComponents}</div>
        </RightCol>
      </Row>
    </>
  );
}

If you only want AccountCircle icon then you can hardcode the icon like
<GreenBox><AcccountCircle /> {notification}</GreenBox> or if you want different icons for different notifications then you can do something like this.

export default function ControlledSwitches() {
  const UserIcon = styled(AccountCircle)({
    margin: "0px 0px 0px 0px"
  });
  const dummyNotification = [
    { text: "Notification #1", icon: <UserIcon /> },
    { text: "Notification #2", icon: <UserIcon /> },
    { text: "Notification #3", icon: <UserIcon /> }
  ];

  const cardComponents =
    dummyNotification !== undefined
      ? dummyNotification.map((notification) => (
          <div key={notification}>
            <div>
              <GreenBox>
                {notification.icon} {notification.text}
              </GreenBox>
            </div>
          </div>
        ))
      : "Loading...";
  return (
    <>
      <NavBar />
      <Row>
        <RightCol>
          <div>{cardComponents}</div>
        </RightCol>
      </Row>
    </>
  );
}

如何在地图列表中传递MUI图标

尤怨 2025-02-06 12:08:39

当然,您要去:

init

Col_data = pd.Series([
    625814.205486,
    782267.756857,
    938721.308229])
C_PV_data = pd.Series([
    2039032.206909,
    2548790.258636,
    3058548.310363])
C_elec_data = pd.Series([
    1337523.743009,
    1671904.678761,
    2006285.614513])

作为df

df = pd.concat(
    [Col_data, C_PV_data, C_elec_data], axis=1,
    keys=['Col_data', 'C_PV_data', 'C_elec_data'])
>>> df
        Col_data     C_PV_data   C_elec_data
0  625814.205486  2.039032e+06  1.337524e+06
1  782267.756857  2.548790e+06  1.671905e+06
2  938721.308229  3.058548e+06  2.006286e+06

旁注:我总是不喜欢重复。以下替代方案是干燥的(不要重复自己),但也许不清楚:

keys = ['Col_data', 'C_PV_data', 'C_elec_data']
d = locals()  # just for DRY...
df = pd.concat([d[k] for k in keys], axis=1, keys=keys)

假设

您已经安装了openpyxl已安装:

df.to_excel('foo.xlsx', index=False)

box plot

edit :(并保存保存作为PNG)

ax = df.loc[[0,1,1,1,2]].plot.box()
ax.figure.savefig('costs.png')

Sure, here you go:

Init

Col_data = pd.Series([
    625814.205486,
    782267.756857,
    938721.308229])
C_PV_data = pd.Series([
    2039032.206909,
    2548790.258636,
    3058548.310363])
C_elec_data = pd.Series([
    1337523.743009,
    1671904.678761,
    2006285.614513])

As a df

df = pd.concat(
    [Col_data, C_PV_data, C_elec_data], axis=1,
    keys=['Col_data', 'C_PV_data', 'C_elec_data'])
>>> df
        Col_data     C_PV_data   C_elec_data
0  625814.205486  2.039032e+06  1.337524e+06
1  782267.756857  2.548790e+06  1.671905e+06
2  938721.308229  3.058548e+06  2.006286e+06

Side note: I always dislike repeats. The following alternative to the above is DRY (Don't Repeat Yourself), but less clear perhaps:

keys = ['Col_data', 'C_PV_data', 'C_elec_data']
d = locals()  # just for DRY...
df = pd.concat([d[k] for k in keys], axis=1, keys=keys)

To xlsx

Assuming you have openpyxl installed:

df.to_excel('foo.xlsx', index=False)

Box plot

Edit: (and save as PNG)

ax = df.loc[[0,1,1,1,2]].plot.box()
ax.figure.savefig('costs.png')

将大熊猫系列汇总到数据框架和视觉表示

尤怨 2025-02-06 03:13:04

正如指出的在这里,还有另一个选择:您可以在global.css文件中导入这些样式。如果您这样做,NextJ会很高兴。

As pointed out here, there is another option: you can import those styles in the global.css file. If you do that, Nextjs will be happy.

选择器“:root”不是纯的(纯粹的选择器必须至少包含一个本地类或ID) - 带有SASS模块的NextJS

尤怨 2025-02-05 16:39:24

按照建议的答案,我最终使用了以下方式:

INSERT INTO vb_postmeta(
    SELECT
        NULL,
        post_id,
        'csco_post_video_url',
        CONCAT('https://www.youtube.com/watch?v=', meta_value)
    FROM
        vb_postmeta
    WHERE
        meta_key = 'bpxl_videourl'
)

Following suggested answers I ended up using this:

INSERT INTO vb_postmeta(
    SELECT
        NULL,
        post_id,
        'csco_post_video_url',
        CONCAT('https://www.youtube.com/watch?v=', meta_value)
    FROM
        vb_postmeta
    WHERE
        meta_key = 'bpxl_videourl'
)

SQL插入从一个字段到新字段的修改值

尤怨 2025-02-05 06:47:49

您可以用scrollbartheme包装并设置Crossaxismargin:

const ScrollbarTheme(
  data: ScrollbarThemeData(crossAxisMargin: 10),
  child: Scrollbar(
    thickness: 10,
    trackVisibility: true,
    thumbVisibility: true,
    child: TextField(),
  ),
);

另外,您可以使用RAWSCROLLBAR并设置Crossaxismargin:

const RawScrollbar(
  thickness: 10,
  trackVisibility: true,
  thumbVisibility: true,
  crossAxisMargin: 5,
  child: TextField(),
);

You may wrap it with ScrollbarTheme and set crossAxisMargin:

const ScrollbarTheme(
  data: ScrollbarThemeData(crossAxisMargin: 10),
  child: Scrollbar(
    thickness: 10,
    trackVisibility: true,
    thumbVisibility: true,
    child: TextField(),
  ),
);

Alternatively, you may use RawScrollbar and set crossAxisMargin:

const RawScrollbar(
  thickness: 10,
  trackVisibility: true,
  thumbVisibility: true,
  crossAxisMargin: 5,
  child: TextField(),
);

如何在Textfield边框和滚动栏之间添加填充?

尤怨 2025-02-05 06:29:34
data WANT;
  set HAVE;
  by ID;
  first_visit = first.ID;
  retain firstDate;
  if first.ID then firstDate = Date;
  days = Date - firstDate;
  drop firstDate;
run;
data WANT;
  set HAVE;
  by ID;
  first_visit = first.ID;
  retain firstDate;
  if first.ID then firstDate = Date;
  days = Date - firstDate;
  drop firstDate;
run;

如何计算第一个事件与SAS中的最后一个事件之间具有多个ID重复的时间?

尤怨 2025-02-04 22:49:50

我正在使用Web-Server-Bundle启动我的服务器(php bin/Console Server:run)。

当我尝试使用其他命令来启动本地服务器(php -s localhost:8000 -t public/)时,第404页工作。

I was using the web-server-bundle to launch my server (php bin/console server:run).

When I tried to use a different command to start the local server (php -S localhost:8000 -t public/), the page 404 worked.

Symfony 5-如何渲染页面错误404而不是Symfony Exception页面?

尤怨 2025-02-04 10:19:51

您可以尝试pip3python -m pip python3 -m pip 您可以检查已安装的Python版本。是3.9.12还是其他东西,如果不是.12,则应使用此 steps

You either could try pip3 or python -m pip or python3 -m pip you may check the installed python version. is it 3.9.12 or something else, and if it's not .12, you should set the new path to the Python with this steps

使用PIP窗口安装Python

尤怨 2025-02-03 22:55:56

我们需要在此处谈论消息处理保证。

如果我们追求精确的处理语义和消息传递顺序,则必须使用隔离配置消费者。Level=“ read_comments”,并且必须使用retries = integer.max_value,enable.idempotence.idempotence = true和max进行配置。 in.flight.requests.per.connection =每默认值1。

另外,设置max.in.flight.requests.per.connection = 1,即使发生回收,也将以发送的顺序写给经纪人。

We need to talk little about the messages processing guarantee here.

If we are after the exactly-once processing semantics and messaging order, then the consumers must be configured with isolation.level="read_committed" and producers have to be configured with retries=Integer.MAX_VALUE, enable.idempotence=true, and max.in.flight.requests.per.connection=1 per default.

Also, setting max.in.flight.requests.per.connection=1, will guarantee that messages will be written to the broker in the order in which they were sent, even when retries occur.

是否按照相同的邮件顺序收到的kafka ack是

尤怨 2025-02-03 10:40:54

您可以创建自己的日志功能并将其用于在屏幕上打印

func Log(args ...interface{}) {
    fmt.Fprintln(os.Stdout, args...)
}

您还可以根据通过标志传递的条件

var p = flag.Bool("p", false, "Enable Local Logging")

func MyLog(args ...interface{}) {
  if *p {
    fmt.Fprintln(os.Stdout, args...)
  }
}

示例

package main

import (
    "fmt"
    "testing"
    "os"
    "flag"
)

var p = flag.Bool("p", false, "Enable Local Logging")

func Log(args ...interface{}) {
  if *p {
    fmt.Fprintln(os.Stdout, args...)
  }
}

func IntMin(a, b int) int {
    if a < b {
        return a
    }
    return b
}

func TestIntMinBasic(t *testing.T) {
    ans := IntMin(2, -2)
    if ans != -2 {
        t.Errorf("IntMin(2, -2) = %d; want -2", ans)
    }
}

func TestIntMinTableDriven(t *testing.T) {
    var tests = []struct {
        a, b int
        want int
    }{
        {0, 1, 0},
        {1, 0, 0},
        {2, -2, -2},
        {0, -1, -1},
        {-1, 0, -1},
    }

    Log("Print to Screen")

    for _, tt := range tests {

        testname := fmt.Sprintf("%d,%d", tt.a, tt.b)
        t.Run(testname, func(t *testing.T) {
            ans := IntMin(tt.a, tt.b)
            if ans != tt.want {
                t.Errorf("got %d, want %d", ans, tt.want)
            }
        })
    }
}

func BenchmarkIntMin(b *testing.B) {
    for i := 0; i < b.N; i++ {
        IntMin(1, 2)
    }
}

并通过标志来打印日志,并且可以使用 -args

-args将命令行的其余部分(-args之后)传递到测试二进制,未解释和不变。因为此标志消耗了命令行的其余部分,所以包装列表(如果存在)必须出现在此标志之前。

CMD示例:

go test -args -p

You can create you own Log function and use it for printing on screen

func Log(args ...interface{}) {
    fmt.Fprintln(os.Stdout, args...)
}

You can also make it to print log based on condition passed through flag

var p = flag.Bool("p", false, "Enable Local Logging")

func MyLog(args ...interface{}) {
  if *p {
    fmt.Fprintln(os.Stdout, args...)
  }
}

Example

package main

import (
    "fmt"
    "testing"
    "os"
    "flag"
)

var p = flag.Bool("p", false, "Enable Local Logging")

func Log(args ...interface{}) {
  if *p {
    fmt.Fprintln(os.Stdout, args...)
  }
}

func IntMin(a, b int) int {
    if a < b {
        return a
    }
    return b
}

func TestIntMinBasic(t *testing.T) {
    ans := IntMin(2, -2)
    if ans != -2 {
        t.Errorf("IntMin(2, -2) = %d; want -2", ans)
    }
}

func TestIntMinTableDriven(t *testing.T) {
    var tests = []struct {
        a, b int
        want int
    }{
        {0, 1, 0},
        {1, 0, 0},
        {2, -2, -2},
        {0, -1, -1},
        {-1, 0, -1},
    }

    Log("Print to Screen")

    for _, tt := range tests {

        testname := fmt.Sprintf("%d,%d", tt.a, tt.b)
        t.Run(testname, func(t *testing.T) {
            ans := IntMin(tt.a, tt.b)
            if ans != tt.want {
                t.Errorf("got %d, want %d", ans, tt.want)
            }
        })
    }
}

func BenchmarkIntMin(b *testing.B) {
    for i := 0; i < b.N; i++ {
        IntMin(1, 2)
    }
}

And to pass the flag you can use -args

-args Pass the remainder of the command line (everything after -args) to the test binary, uninterpreted and unchanged. Because this flag consumes the remainder of the command line, the package list (if present) must appear before this flag.

Cmd Example:

go test -args -p

如何在不使用详细选项的情况下从GO测试到控制台打印

尤怨 2025-02-03 09:06:59

通常使用这些(err,结果)=&gt; {...}回调,您检查err first ,因为如果是真实,第二个参数很有可能不会定义。

您还应返回在检测到错误以防止其余回调执行后。

fyi, node-postgresl node-postgresl 在本地支持承诺,因此无需明确创建一个。在下面,我将您的代码转换为异步函数,以利用这一点。

const getUserById = async (id) => {
  const { rows } = await db.query({
    text: "SELECT id, first_name as firstName, email, phone FROM users WHERE id = $1",
    values: [id],
  });

  // `rows` is always an array so check the length
  if (rows.length !== 1) {
    throw new Error(`Could not find user by id [${id}]`);
  }

  return rows[0];
};

Typically with those (err, result) => { ... } callbacks, you check err first because if it is truthy, there's a good chance that the second argument will not be defined.

You should also return after detecting an error to prevent the rest of your callback from executing.

FYI, node-postgresl supports promises natively so there's no need to explicitly create one. Below I've translated your code to an async function to take advantage of this.

const getUserById = async (id) => {
  const { rows } = await db.query({
    text: "SELECT id, first_name as firstName, email, phone FROM users WHERE id = $1",
    values: [id],
  });

  // `rows` is always an array so check the length
  if (rows.length !== 1) {
    throw new Error(`Could not find user by id [${id}]`);
  }

  return rows[0];
};

为什么在调用数据库呼叫时未定义我的论点?

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文