python c api, how can I add function to class which defined in c layer - cpython

I defined a type spam.Foo follow Defining New Types.
Which like this.
PyObject *m;
m = Py_InitModule(MODULE_NAME, Spam_methods);
int rst = PyModule_AddObject(m, "Foo", (PyObject *)&FooPyType);
if (rst == -1) {
throw std::runtime_error("PyModule_AddObject(Foo) failed");
}
And the Foo PyTypeObject is like this:
PyTypeObject FooPyType = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"spam.Foo",
sizeof(Foo),
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
reinterpret_cast<reprfunc>(FooType_str),
0,
0,
0,
Py_TPFLAGS_DEFAULT,
"The spam Foo",
0,
0,
0,
0,
0,
0,
FooType_methods,
nullptr,
FooType_getSet
};
Now I want create a new function in python code:
from spam import Foo
setattr(Foo, "bar", lambda self: "Hello from bar")
But it throw an error: can't set attributes of built-in/extension type 'spam.Foo'.
How can I do this.

Related

What is difference Qt.matrix4x4 and QMatrix4x4?

I am learning the Qt 3D module. I found the Qt.matrix4x4 provide different API than QMatrix4x4 in C++ side (by using F1 check the API doc).
look likes Qt.matrix4x4 don't have such scale or rotation operations. even not in autocomplete.
BUT! these functions do exist and work!
var m = Qt.matrix4x4(1, 0, 0, -0.5, 0, 1, 0, 0, 0, 0, 1, 0.5, 0, 0, 0, 1)
m.scale(2)
console.log(m)
// qml: QMatrix4x4(2, 0, 0, -0.5, 0, 2, 0, 0, 0, 0, 2, 0.5, 0, 0, 0, 1)
// the type shows QMatrix4x4
https://doc.qt.io/qt-5/qmatrix4x4.html vs https://doc.qt.io/qt-5/qml-matrix4x4.html
I understand what these is, But why the API show different in API doc and autocomplete?
It is interesting to note that in Qt6 the documentation appears different than Qt5. In Qt6 we see clearly there are methods for constructing the matrix4x4 basic type from a vector and for multiplying them with vectors.
// translate(vector3d)
var m = Qt.matrix4x4();
m.translate(Qt.vector3d(1,2,3));
console.log(m.toString());
// QMatrix4x4(1, 0, 0, 1, 0, 1, 0, 2, 0, 0, 1, 3, 0, 0, 0, 1)
// matrix multiplication
var m = Qt.matrix4x4();
m.translate(Qt.vector3d(1,2,3));
console.log(m.toString());
// QMatrix4x4(1, 0, 0, 1, 0, 1, 0, 2, 0, 0, 1, 3, 0, 0, 0, 1)
// applying a matrix to a vector
var a = Qt.matrix4x4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
var b = Qt.vector3d(5,6,7);
var c = a.times(b);
console.log(c.toString()); // QVector3D(0.155556, 0.437037, 0.718518)
Note I tried all of the above in Qt5.15.6 but it doesn't work. So it appears that support for this type really kicks in at Qt6.
For further information see: https://doc.qt.io/qt-6/qml-matrix4x4.html

Why is my Network Map output not showing in my shiny App?

What concerns me the most is that it isn't getting an error, but it's just not showing!
I gotta mention that I even printed each line in order to check the progress as it advanced and it all came out as it regularly does on the console. I'm guessing that it must be in the output$visnetwork function, but I just don't know.
# --------------------------------------- Global --------------------------------------- #
# Set working directory -> Ctrl+Shift+H & Open the app folder
setwd("~/ProgramaciĆ³n en R/Shiny app/Client dashboard app")
# --------------------- Initialize program --------------------- #
# Print in console: global script is beginning to run
print("global.R")
#--------------------------------------- User Interface ---------------------------------------#
# Tell user ui script is beginning to run
print("ui.R")
ui <- fluidPage(
theme = shinytheme("cerulean"),
navbarPage("Analysis",
#--- Home Tab (Global View)
tabPanel("Global View",
sidebarPanel(),
visNetworkOutput("network")
), #tabPanel - Global View
tabPanel("",
) #tabPanel -
) #navbarPage
) #fluidPage
#--------------------------------------- Server ---------------------------------------#
# Tell user server script is beginning to run
print("server.R")
server <- function(input, output, session) {
# Gathering important variables in one only data set
twd <<- NULL
observe({
twd <- structure(c(0.0156521739130435, 0, 0, 0, 0, 0, 0.00633484162895928,
0, 0, 0.0137931034482759, 0.118245390972664, 0, 0.0121739130434783,
0.141455437448896, 0.00131061598951507, 0, 0.00580720092915215,
0, 0, 0, 0.0200445434298441, 0, 0, 0, 0, 0, 0, 0.036046511627907,
0, 0, 0.00180995475113122, 0, 0, 0.0334975369458128, 0.0216147488874762,
0.0449197860962567, 0.00956521739130435, 0.0834014717906787,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0121739130434783, 0.080130825838103,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0217391304347826, 0, 0, 0, 0,
0, 0, 0, 0.0623608017817372, 0, 0.00762873490146217, 0, 0, 0,
0, 0.00930232558139535, 0.0511033681765389, 0, 0, 0, 0.044543429844098,
0, 0, 0, 0.0582608695652174, 0, 0, 0, 0, 0, 0, 0, 0.0122494432071269,
0, 0, 0, 0, 0.00245298446443173, 0, 0, 0, 0, 0.0624434389140271,
0, 0, 0, 0.00190718372536554, 0, 0, 0.00654129190515127, 0, 0,
0, 0, 0, 0.0594541910331384, 0, 0, 0, 0.00320855614973262, 0.0121739130434783,
0.00163532297628782, 0, 0.0558139534883721, 0, 0, 0, 0.00584795321637427,
0, 0, 0, 0, 0, 0, 0, 0.0709302325581395, 0, 0, 0, 0, 0, 0, 0.00190718372536554,
0, 0, 0, 0, 0, 0, 0, 0.0262443438914027, 0, 0.0089086859688196,
0, 0.0133502860775588, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0368722186904005,
0, 0, 0, 0.072083879423329, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0217391304347826,
0, 0, 0, 0, 0, 0, 0.0126705653021442, 0, 0, 0.0108073744437381,
0, 0.0165217391304348, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0222504767959313,
0, 0, 0, 0, 0, 0, 0, 0.0235294117647059, 0, 0.0178173719376392,
0, 0.00699300699300699, 0, 0, 0.0098119378577269, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0.0427807486631016, 0.00521739130434783, 0.0335241210139002,
0, 0, 0, 0, 0, 0, 0, 0, 0.00254291163382072, 0, 0, 0, 0, 0, 0,
0.0488974113135187, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0488974113135187,
0, 0, 0, 0, 0, 0, 0.0182608695652174, 0.0122649223221586, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0.0128342245989305, 0, 0.00408830744071954,
0, 0, 0, 0.0134228187919463, 0.0262443438914027, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0305149396058487, 0), .Dim = c(12L,
25L), .Dimnames = list(NULL, c("demand_response", "utility_model",
"real_time", "model_discloses", "utility_model_discloses", "power_supply",
"control_system", "control_module", "intelligent_terminal", "management_system",
"energy_consumption", "disaggregated_model", "control_method",
"power_grid", "electric_energy", "intelligent_power", "electricity_consumption",
"power_consumption", "control_unit", "communication_module",
"random_access", "uplink_frequency", "intelligent_control", "mobile_terminal",
"power_utilization")))
topic_names <<- c("1", "2", "3","4","5","6","7","8","9","10","11","12")
})
# Network Map
observe({
# Preparing data with igraph library
twd_num_col <- ncol(twd)
cor_threshold <- .8
twd_cor <- cor(twd[,1:twd_num_col], method = "pearson")
twd_cor[ twd_cor < cor_threshold ] <- 0
diag(twd_cor) <- 0
graph <- graph.adjacency(twd_cor, weighted=TRUE, mode="lower")
E(graph)$edge.width <- E(graph)$weight
V(graph)$group <- apply(twd, 2, which.max) #Max topic prob for colors
V(graph)$betweenness <- betweenness(graph, v = V(graph), directed = F)
V(graph)$degree <- degree(graph, v = V(graph))
# Fit data for visNetwork
nm_data <- toVisNetworkData(graph)
nodes <- nm_data[[1]]
edges <- nm_data[[2]]
nodes <- nodes[nodes$degree != 0,] # Bye topics that don't have a connection (degree = 0)
nodes$group <- swap(nodes$group , 1:length(topic_names), topic_names) # Swap long real names
nodes$label <- rep("")
})
output$network <- renderVisNetwork({
# Graph
set.seed(17);visNetwork(nodes, edges, main = "Relation between topics") %>%
visOptions(highlightNearest = TRUE, selectedBy = "group") %>%
visInteraction(dragNodes = FALSE) %>%
visLegend(useGroups = TRUE, main = "Topic", ncol = 2) %>%
visNodes(shape = "dot",label = NULL) %>%
visEdges(smooth = FALSE) %>%
visIgraphLayout(randomSeed = 17)
})
}
shinyApp(ui, server)
And when I super assigned the data fit for visNetwork, it gave me this: Warning: Error in <observer>: cannot change value of locked binding for 'edges' but it's printing quit alright so I'm confused.

Planned Contrasts on glmmTMB

Apologies if this is a repeat question. Many have posted looking looking for a way to do post-hoc analyses on the conditional model (fixed factors) in glmmTMB. I want to do plannned contrasts between certain groups, not test every pairwise comparison (e.g. Tukey).
The code below worked well on nlme:lme for a lmm. However, it returns an error on the code below.
Error in modelparm.default(model, ...) :
dimensions of coefficients and covariance matrix don't match
Is there a way to do planned contrasts on a glmmTMB?
#filtdens is a dataframe and TRT,DATE,BURN,VEG are factors
filtdens <- merged %>% filter(!BLOCK %in% c("JB2","JB4","JB5") & MEAS =="DENS" &
group == "TOT" & BURN == "N" & VEG == "C")
filtdens$TD <- interaction(filtdens$TRT, filtdens$DATE)
mod2 <- glmmTMB(count~(TD)+(1|BLOCK),
data=filtdens,
zi=~1,
family=nbinom1(link = "log"))
k1 <- matrix(c(0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, -1, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, -1, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, -1, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, -1, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, -1, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, -1, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 1), byrow = T, ncol = 12)
summary(glht(mod2, linfct=k1),test=adjusted("bonferroni"))
A reproducible example would be helpful, but: this vignette in the development version offers code that ought to enable multcomp::linfct, i.e.:
glht_glmmTMB <- function (model, ..., component="cond") {
glht(model, ...,
coef. = function(x) fixef(x)[[component]],
vcov. = function(x) vcov(x)[[component]],
df = NULL)
}
modelparm.glmmTMB <- function (model,
coef. = function(x) fixef(x)[[component]],
vcov. = function(x) vcov(x)[[component]],
df = NULL, component="cond", ...) {
multcomp:::modelparm.default(model, coef. = coef., vcov. = vcov.,
df = df, ...)
}
Test (this example is with Tukey, but I don't see why it shouldn't work more generally ...)
library(glmmTMB)
data("cbpp",package="lme4")
cbpp_b1 <- glmmTMB(incidence/size~period+(1|herd),
weights=size,family=binomial,
data=cbpp)
g1 <- glht(cbpp_b1, linfct = mcp(period = "Tukey"))
summary(g1)
This works with the current CRAN version, but the current development version of glmmTMB offers more options (e.g. emmeans(); see the above-linked vignette). You'll need to install via devtools::install_github("glmmTMB/glmmTMB/glmmTMB") (you'll need compilation tools installed as well).

Endpoint returns presumably cloud config

I have this simple controller
#RestController
#RequestMapping("/metrics")
public class MetricsController {
#GetMapping
#ApiOperation("Get metrics by source")
public ResponseEntity<List<Metric>> getMetricBySource(#RequestParam String source) {
if (source.equalsIgnoreCase("recordings")) {
return new ResponseEntity<>(MetricsConstants.RECORDINGS_METRICS, HttpStatus.OK);
} else if (source.equalsIgnoreCase("advertisers")) {
return new ResponseEntity<>(MetricsConstants.ADVERTISERS_METRICS, HttpStatus.OK);
} else if (source.equalsIgnoreCase("publishers")) {
return new ResponseEntity<>(MetricsConstants.PUBLISHERS_METRICS, HttpStatus.OK);
} else if (source.equalsIgnoreCase("partners")) {
return new ResponseEntity<>(MetricsConstants.PARTNERS_METRICS, HttpStatus.OK);
} else if (source.equalsIgnoreCase("products")) {
return new ResponseEntity<>(MetricsConstants.PRODUCTS_METRICS, HttpStatus.OK);
} else if (source.equalsIgnoreCase("regular-users")) {
return new ResponseEntity<>(MetricsConstants.REGULAR_USERS_METRICS, HttpStatus.OK);
}
return null;
}
}
Now, when I'm trying to access the endpoint via
localhost:8099/metrics?source=advertisers
I'm getting the following response
{
"mem": 947258,
"mem.free": 367038,
"processors": 4,
"instance.uptime": 540532,
"uptime": 556754,
"systemload.average": -1,
"heap.committed": 854016,
"heap.init": 260096,
"heap.used": 486977,
"heap": 3699200,
"nonheap.committed": 95312,
"nonheap.init": 2496,
"nonheap.used": 93242,
"nonheap": 0,
"threads.peak": 61,
"threads.daemon": 37,
"threads.totalStarted": 128,
"threads": 53,
"classes": 13916,
"classes.loaded": 13916,
"classes.unloaded": 0,
"gc.ps_scavenge.count": 13,
"gc.ps_scavenge.time": 150,
"gc.ps_marksweep.count": 3,
"gc.ps_marksweep.time": 341,
"counter.servo.eurekaclient.transport.request": 0,
"counter.servo.eurekaclient.transport.connectionerrors": 0,
"counter.servo.timeouts": 0,
"counter.servo.rejectedexecutions": 0,
"counter.servo.throwables": 0,
"gauge.servo.threadpoolused": 0,
"gauge.servo.response.metrics": 6,
"normalized.servo.rest.totaltime": 0,
"normalized.servo.rest.count": 0,
"gauge.servo.rest.min": 0,
"gauge.servo.rest.max": 0,
"gauge.servo.eurekaclient.registration.lastheartbeatsec_00030": 0,
"counter.servo.discoveryclient-httpclient_reuse": 10,
"counter.servo.discoveryclient-httpclient_createnew": 26,
"counter.servo.discoveryclient-httpclient_request": 36,
"counter.servo.discoveryclient-httpclient_release": 36,
"counter.servo.discoveryclient-httpclient_delete": 24,
"normalized.servo.discoveryclient-httpclient_requestconnectiontimer.totaltime":
0.005046033333333333,
"normalized.servo.discoveryclient-httpclient_requestconnectiontimer.count":
0.06666666666666667,
"gauge.servo.discoveryclient-httpclient_requestconnectiontimer.min":
0.017749,
"gauge.servo.discoveryclient-httpclient_requestconnectiontimer.max":
0.12356299999999999,
"normalized.servo.discoveryclient-httpclient_createconnectiontimer.totaltime":
0.0012743166666666665,
"normalized.servo.discoveryclient-httpclient_createconnectiontimer.count":
0.05,
"gauge.servo.discoveryclient-httpclient_createconnectiontimer.min":
0.012288,
"gauge.servo.discoveryclient-httpclient_createconnectiontimer.max":
0.034475,
"gauge.servo.connectioncount": 2,
"normalized.servo.eurekaclient.transport.latency.totaltime": 0,
"normalized.servo.eurekaclient.transport.latency.count": 0,
"gauge.servo.eurekaclient.transport.latency.min": 0,
"gauge.servo.eurekaclient.transport.latency.max": 0,
"gauge.servo.response.star-star.favicon.ico": 42,
"gauge.servo.eurekaclient.registry.lastupdatesec_00240": 0,
"gauge.servo.eurekaclient.registration.lastheartbeatsec_00015": 1,
"gauge.servo.response.webjars.star-star": 5,
"gauge.servo.eurekaclient.resolver.endpointssize": 1,
"gauge.servo.eurekaclient.resolver.lastloadtimestamp": 233376,
"gauge.servo.eurekaclient.registration.lastheartbeatsec_00240": 0,
"gauge.servo.eurekaclient.transport.quarantinesize": 0,
"gauge.servo.eurekaclient.registry.lastupdatesec_00030": 0,
"gauge.servo.response.v2.api-docs": 126,
"gauge.servo.eurekaclient.registration.lastheartbeatsec_00480": 0,
"gauge.servo.eurekaclient.registry.lastupdatesec_00480": 0,
"gauge.servo.response.star-star": 13,
"gauge.servo.response.swagger-resources.configuration.ui": 19,
"normalized.servo.eureka-connection-cleaner-time.totaltime": 0.0009386666666666665,
"normalized.servo.eureka-connection-cleaner-time.count": 0.03333333333333333,
"gauge.servo.eureka-connection-cleaner-time.min": 0.021162,
"gauge.servo.eureka-connection-cleaner-time.max": 0.035158,
"counter.servo.eureka-connection-cleaner-failure": 0,
"gauge.servo.eurekaclient.transport.currentsessionduration": 533378,
"gauge.servo.eurekaclient.registration.lastheartbeatsec_00120": 0,
"gauge.servo.eurekaclient.registry.lastupdatesec_00015": 1,
"gauge.servo.response.swagger-resources.configuration.security": 4,
"gauge.servo.eurekaclient.registry.lastupdatesec_00120": 0,
"gauge.servo.response.info": 35,
"gauge.servo.eurekaclient.registration.lastheartbeatsec_00060": 0,
"gauge.servo.eurekaclient.registry.lastupdatesec_00060": 0,
"counter.servo.discoveryclient_reconcilehashcodemismatch": 0,
"normalized.servo.discoveryclient_fetchregistry.totaltime": 0.29706815000000003,
"normalized.servo.discoveryclient_fetchregistry.count": 0.03333333333333333,
"gauge.servo.discoveryclient_fetchregistry.min": 4.337664999999999,
"gauge.servo.discoveryclient_fetchregistry.max": 13.486424,
"counter.servo.discoveryclient_reregister": 0,
"gauge.servo.eurekaclient.registry.localregistrysize": 5,
"gauge.servo.eurekaclient.registry.lastsuccessfulregistryfetchtimeperiod":
22920,
"gauge.servo.eurekaclient.registration.lastsuccessfulheartbeattimeperiod":
22926,
"gauge.servo.response.swagger-resources": 5,
"integration.channel.errorChannel.errorRate.mean": 0,
"integration.channel.errorChannel.errorRate.max": 0,
"integration.channel.errorChannel.errorRate.min": 0,
"integration.channel.errorChannel.errorRate.stdev": 0,
"integration.channel.errorChannel.errorRate.count": 0,
"integration.channel.errorChannel.sendCount": 0,
"integration.channel.errorChannel.sendRate.mean": 0,
"integration.channel.errorChannel.sendRate.max": 0,
"integration.channel.errorChannel.sendRate.min": 0,
"integration.channel.errorChannel.sendRate.stdev": 0,
"integration.channel.errorChannel.sendRate.count": 0,
"integration.channel.springCloudBusInput.errorRate.mean": 0,
"integration.channel.springCloudBusInput.errorRate.max": 0,
"integration.channel.springCloudBusInput.errorRate.min": 0,
"integration.channel.springCloudBusInput.errorRate.stdev": 0,
"integration.channel.springCloudBusInput.errorRate.count": 0,
"integration.channel.springCloudBusInput.sendCount": 0,
"integration.channel.springCloudBusInput.sendRate.mean": 0,
"integration.channel.springCloudBusInput.sendRate.max": 0,
"integration.channel.springCloudBusInput.sendRate.min": 0,
"integration.channel.springCloudBusInput.sendRate.stdev": 0,
"integration.channel.springCloudBusInput.sendRate.count": 0,
"integration.channel.hystrixStreamOutput.errorRate.mean": 0,
"integration.channel.hystrixStreamOutput.errorRate.max": 0,
"integration.channel.hystrixStreamOutput.errorRate.min": 0,
"integration.channel.hystrixStreamOutput.errorRate.stdev": 0,
"integration.channel.hystrixStreamOutput.errorRate.count": 0,
"integration.channel.hystrixStreamOutput.sendCount": 0,
"integration.channel.hystrixStreamOutput.sendRate.mean": 0,
"integration.channel.hystrixStreamOutput.sendRate.max": 0,
"integration.channel.hystrixStreamOutput.sendRate.min": 0,
"integration.channel.hystrixStreamOutput.sendRate.stdev": 0,
"integration.channel.hystrixStreamOutput.sendRate.count": 0,
"integration.channel.nullChannel.errorRate.mean": 0,
"integration.channel.nullChannel.errorRate.max": 0,
"integration.channel.nullChannel.errorRate.min": 0,
"integration.channel.nullChannel.errorRate.stdev": 0,
"integration.channel.nullChannel.errorRate.count": 0,
"integration.channel.nullChannel.sendCount": 0,
"integration.channel.nullChannel.sendRate.mean": 0,
"integration.channel.nullChannel.sendRate.max": 0,
"integration.channel.nullChannel.sendRate.min": 0,
"integration.channel.nullChannel.sendRate.stdev": 0,
"integration.channel.nullChannel.sendRate.count": 0,
"integration.channel.springCloudBusOutput.errorRate.mean": 0,
"integration.channel.springCloudBusOutput.errorRate.max": 0,
"integration.channel.springCloudBusOutput.errorRate.min": 0,
"integration.channel.springCloudBusOutput.errorRate.stdev": 0,
"integration.channel.springCloudBusOutput.errorRate.count": 0,
"integration.channel.springCloudBusOutput.sendCount": 0,
"integration.channel.springCloudBusOutput.sendRate.mean": 0,
"integration.channel.springCloudBusOutput.sendRate.max": 0,
"integration.channel.springCloudBusOutput.sendRate.min": 0,
"integration.channel.springCloudBusOutput.sendRate.stdev": 0,
"integration.channel.springCloudBusOutput.sendRate.count": 0,
"integration.handler._org.springframework.integration.errorLogger.handler.duration.mean":
0,
"integration.handler._org.springframework.integration.errorLogger.handler.duration.max":
0,
"integration.handler._org.springframework.integration.errorLogger.handler.duration.min":
0,
"integration.handler._org.springframework.integration.errorLogger.handler.duration.stdev":
0,
"integration.handler._org.springframework.integration.errorLogger.handler.duration.count":
0,
"integration.handler._org.springframework.integration.errorLogger.handler.activeCount":
0,
"integration.handlerCount": 1,
"integration.channelCount": 5,
"integration.sourceCount": 0,
"httpsessions.max": -1,
"httpsessions.active": 0,
"datasource.primary.active": 0,
"datasource.primary.usage": 0 }
Code flow doesn't even go to the method(tried to use debugger).
The problem with only this newly created endpoint. Last error was
Full authentication is required to access this resource
until I wrote the piece of configuration:
management:
security:
enabled: false
I use
springBootVersion = '1.5.3.RELEASE'
springCloudVersion = 'Dalston.RELEASE'
The issue was with Spring Cloud MetricsInterceptorConfiguration.
As far as I understood, on each endpoint you can add suffix-path /metrics to see the metrics for this endpoint provided by Spring Cloud. So it just intercepted my mapping :)
I solved this by adding the following configuration to bootstrap.yml:
endpoints:
metrics:
enabled: false

R hangs when running the sapply function

I have a data frame df in the following form:
v2 v3
2.3 c(1,5,8,2)
1.2 c(2,4,3,2)
The typeof(df$v3[1]) is list, and I want to convert it to vector. So I write a `sapply`` function and run it:
df$v3 <- sapply(
df$v3,
function(x) {x <- unlist(x)}
)
But it just keeps running and does not generate any result. I also tried lapply but it can't give me the expected result. Instead, it again generates a list.
Any my dput(droplevels(head(df))) result is :
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0))), .Names = c("V2", "V3"), row.names = c(NA,
-6L), .internal.selfref = <pointer: 0x102010578>, class = c("data.table", "data.frame"))
Could you please tell me how to solve it?
EDIT:
I run the df$V3 <- unlist(df$V3) for a long time. But the type is still list and a warning is generated:
Warning messages:
1: In `[<-.data.table`(x, j = name, value = value) :
Supplied 496450000 items to be assigned to 99290 items of column 'V3' (496350710 unused)
2: In `[<-.data.table`(x, j = name, value = value) :
Coerced 'double' RHS to 'list' to match the column's type; may have truncated precision. Either change the target column to 'double' first (by creating a new 'double' vector length 99290 (nrows of entire table) and assign that; i.e. 'replace' column), or coerce RHS to 'list' (e.g. 1L, NA_[real|integer]_, as.*, etc) to make your intent clear and for speed. Or, set the column type correctly up front when you create the table and stick to it, please.

Resources